Skip to content

Commit 56881ad

Browse files
author
Mike Atlas
committed
Include HTTP req.remoteAddr in gRPC ctx
1 parent 2d6296e commit 56881ad

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

runtime/context.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@ const metadataTrailerPrefix = "Grpc-Trailer-"
1414
/*
1515
AnnotateContext adds context information such as metadata from the request.
1616
17-
If there are no metadata headers in the request, then the context returned
18-
will be the same context.
17+
At a minimum, the RemoteAddr is included in the fashion of "X-Forwarded-For",
18+
except that the forwarded destination is not another HTTP service but rather
19+
a gRPC service.
1920
*/
2021
func AnnotateContext(ctx context.Context, req *http.Request) context.Context {
2122
var pairs []string
23+
24+
// Include the original RemoteAddr, something the gRPC service may need in the ctx
25+
pairs = append(pairs, "RemoteAddr", req.RemoteAddr)
26+
2227
for key, vals := range req.Header {
2328
for _, val := range vals {
24-
if strings.ToLower(key) == "authorization" {
29+
if key == "Authorization" {
2530
pairs = append(pairs, key, val)
2631
continue
2732
}

0 commit comments

Comments
 (0)