-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding x-forwarded-host support #39
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ import ( | |
"golang.org/x/net/context" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/metadata" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
var ( | ||
|
@@ -70,7 +72,18 @@ func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error | |
} | ||
|
||
clientCtx, clientCancel := context.WithCancel(outgoingCtx) | ||
// TODO(mwitkow): Add a `forwarded` header to metadata, https://en.wikipedia.org/wiki/X-Forwarded-For. | ||
md, ok := metadata.FromIncomingContext(clientCtx) | ||
if !ok { | ||
return status.Error(codes.Internal, ":authority header has not been set") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this now an error? seems like a breaking change. |
||
} | ||
authority, ok := md[":authority"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any way of connecting these keys back to the upstream definition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems incorrect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks strange to me as well - I'm not clear on how If you want to record the caller, then |
||
if !ok { | ||
return status.Error(codes.Internal, ":authority header has not been set") | ||
} | ||
md = md.Copy() // metadata is immutable, copy. | ||
md["x-forwarded-host"] = authority | ||
|
||
clientCtx = metadata.NewOutgoingContext(clientCtx, md) | ||
clientStream, err := grpc.NewClientStream(clientCtx, clientStreamDescForProxying, backendConn, fullMethodName) | ||
if err != nil { | ||
return err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract to function, link to relevant docs (i.e. wikipedia)