Skip to content

Commit

Permalink
Pass Permanent Request Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
christianvozar committed Aug 18, 2016
1 parent ccd4e6b commit 815536c
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions runtime/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"google.golang.org/grpc/metadata"
)

const metadataHeaderPrefix = "Grpc-Metadata-"
const metadataHeaderPrefix = "GrpcGateway-"
const metadataTrailerPrefix = "Grpc-Trailer-"
const metadataGrpcTimeout = "Grpc-Timeout"

Expand Down Expand Up @@ -48,8 +48,8 @@ func AnnotateContext(ctx context.Context, req *http.Request) (context.Context, e

for key, vals := range req.Header {
for _, val := range vals {
if key == "Authorization" {
pairs = append(pairs, "authorization", val)
if isPermanentHTTPHeader(key) {
pairs = append(pairs, strings.ToLower(fmt.Sprintf("%s%s", metadataHeaderPrefix, key)), val)
continue
}
if strings.HasPrefix(key, metadataHeaderPrefix) {
Expand Down Expand Up @@ -137,3 +137,41 @@ func timeoutUnitToDuration(u uint8) (d time.Duration, ok bool) {
}
return
}

// isPermanentHTTPHeader checks whether hdr belongs to the list of
// permenant request headers maintained by IANA.
// http://www.iana.org/assignments/message-headers/message-headers.xml
func isPermanentHTTPHeader(hdr string) bool {
if hdr != "" && hdr[0] == ':' {
return true
}
switch hdr {
case
"Accept",
"Accept-Charset",
"Accept-Language",
"Accept-Ranges",
"Authorization",
"Cache-Control",
"Content-Type",
"Cookie",
"Date",
"Expect",
"From",
"Host",
"If-Match",
"If-Modified-Since",
"If-None-Match",
"If-Schedule-Tag-Match",
"If-Unmodified-Since",
"Max-Forwards",
"Origin",
"Pragma",
"Referer",
"User-Agent",
"Via",
"Warning":
return true
}
return false
}

0 comments on commit 815536c

Please sign in to comment.