Skip to content

Commit

Permalink
Add MetadataHostName const
Browse files Browse the repository at this point in the history
  • Loading branch information
orloffv committed Jan 25, 2022
1 parent ddcc649 commit 7825619
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ type AuthData interface {
GetAttributeNames() []string
}

const MetadataHostName = "Host"

// NewContext takes an existing context and derives a new context with the
// client.Info value stored on it.
func NewContext(ctx context.Context, c Info) context.Context {
Expand Down
4 changes: 2 additions & 2 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ func contextWithClient(ctx context.Context, includeMetadata bool) context.Contex
if includeMetadata {
if md, ok := metadata.FromIncomingContext(ctx); ok {
copiedMD := md.Copy()
if len(md["Host"]) == 0 && len(md[":authority"]) > 0 {
copiedMD["Host"] = md[":authority"]
if len(md[client.MetadataHostName]) == 0 && len(md[":authority"]) > 0 {
copiedMD[client.MetadataHostName] = md[":authority"]
}
cl.Metadata = client.NewMetadata(copiedMD)
}
Expand Down
4 changes: 2 additions & 2 deletions config/confighttp/clientinfohandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func contextWithClient(req *http.Request, includeMetadata bool) context.Context

if includeMetadata {
md := req.Header.Clone()
if len(md.Get("Host")) == 0 && req.Host != "" {
md.Add("Host", req.Host)
if len(md.Get(client.MetadataHostName)) == 0 && req.Host != "" {
md.Add(client.MetadataHostName, req.Host)
}

cl.Metadata = client.NewMetadata(md)
Expand Down

0 comments on commit 7825619

Please sign in to comment.