Skip to content
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

runtime - export prefix constants #236

Merged
merged 3 commits into from
Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions runtime/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ import (
"google.golang.org/grpc/metadata"
)

const metadataHeaderPrefix = "Grpc-Metadata-"
const metadataTrailerPrefix = "Grpc-Trailer-"
// MetadataHeaderPrefix is prepended to HTTP headers in order to convert them to
// gRPC metadata for incoming requests processed by grpc-gateway
const MetadataHeaderPrefix = "Grpc-Metadata-"
// MetadataTrailerPrefix is prepended to gRPC metadata as it is converted to
// HTTP headers in a response handled by grpc-gateway
const MetadataTrailerPrefix = "Grpc-Trailer-"
const metadataGrpcTimeout = "Grpc-Timeout"

const xForwardedFor = "X-Forwarded-For"
Expand Down Expand Up @@ -52,8 +56,8 @@ func AnnotateContext(ctx context.Context, req *http.Request) (context.Context, e
pairs = append(pairs, "authorization", val)
continue
}
if strings.HasPrefix(key, metadataHeaderPrefix) {
pairs = append(pairs, key[len(metadataHeaderPrefix):], val)
if strings.HasPrefix(key, MetadataHeaderPrefix) {
pairs = append(pairs, key[len(MetadataHeaderPrefix):], val)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func ForwardResponseStream(ctx context.Context, marshaler Marshaler, w http.Resp

func handleForwardResponseServerMetadata(w http.ResponseWriter, md ServerMetadata) {
for k, vs := range md.HeaderMD {
hKey := fmt.Sprintf("%s%s", metadataHeaderPrefix, k)
hKey := fmt.Sprintf("%s%s", MetadataHeaderPrefix, k)
for i := range vs {
w.Header().Add(hKey, vs[i])
}
Expand All @@ -76,14 +76,14 @@ func handleForwardResponseServerMetadata(w http.ResponseWriter, md ServerMetadat

func handleForwardResponseTrailerHeader(w http.ResponseWriter, md ServerMetadata) {
for k := range md.TrailerMD {
tKey := textproto.CanonicalMIMEHeaderKey(fmt.Sprintf("%s%s", metadataTrailerPrefix, k))
tKey := textproto.CanonicalMIMEHeaderKey(fmt.Sprintf("%s%s", MetadataTrailerPrefix, k))
w.Header().Add("Trailer", tKey)
}
}

func handleForwardResponseTrailer(w http.ResponseWriter, md ServerMetadata) {
for k, vs := range md.TrailerMD {
tKey := fmt.Sprintf("%s%s", metadataTrailerPrefix, k)
tKey := fmt.Sprintf("%s%s", MetadataTrailerPrefix, k)
for i := range vs {
w.Header().Add(tKey, vs[i])
}
Expand Down