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

Proposal: Update metadata and headers in context.Context. #237

Open
adamryman opened this issue Sep 12, 2017 · 0 comments
Open

Proposal: Update metadata and headers in context.Context. #237

adamryman opened this issue Sep 12, 2017 · 0 comments

Comments

@adamryman
Copy link
Member

adamryman commented Sep 12, 2017

We current put all HTTP/1.1 headers and all gRPC metadata values into the ctx context.Context with context.WithValue(. We just use string keys for the string values.

Putting them into the context as strings is bad form as it could conflict with others just using string values (though no one should be using it)

I propose we add a type to each transport for their respective request values (headers and metadata).

Example HTTP

# svc/transport_http.go
type HTTPHeaders struct{}

func headersToContext(ctx context.Context, r *http.Request) context.Context {
    return context.WithValue(ctx, HTTPHeaders, r.Header)
}
# handlers.go

func (s echoService) Echo(ctx context.Context, in *pb.EchoRequest) (*pb.EchoResponse, error) {
   headers = ctx.Value(svc.HTTPHeaders)
   logger.Log("Content-Type", headers.Get("Content-Type"))
   return nil, nil
}

Same basic idea with GRPC.

We could also use this to put other values, or the entire original request into the context.

type HTTPRequest struct{}

Another value would be the HTTP method that was used, could be useful for knowing if a custom verb was used: #230

type HTTPVerb struct{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant