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

custom marshaler: handle Accept headers correctly #152

Merged
merged 1 commit into from
May 16, 2016
Merged

custom marshaler: handle Accept headers correctly #152

merged 1 commit into from
May 16, 2016

Conversation

tamird
Copy link
Contributor

@tamird tamird commented May 9, 2016

Also greatly simplifies existing logic to avoid special casing of
defaults.

@tamird tamird changed the title custom marshaller: handle Accept headers correctly custom marshaler: handle Accept headers correctly May 9, 2016
@tamird
Copy link
Contributor Author

tamird commented May 9, 2016

@yugui @willtrking @tmc

@tamird
Copy link
Contributor Author

tamird commented May 9, 2016

This failed on go tip because go vet crashed, but is otherwise green.

@tmc
Copy link
Collaborator

tmc commented May 9, 2016

why the MakeMarshalerMIMERegistry naming change?

@tamird
Copy link
Contributor Author

tamird commented May 9, 2016

Because it no longer returns a pointer.

@yugui
Copy link
Member

yugui commented May 10, 2016

It is unlikely that I will merge this PR because

It would be even better if we can property handle Accept header, however, I don't think it is mandatory.

If we handle the header, it would require:

  • interpret media range and quality factor
  • split Marshaler into Marshaler and Unmarshaler.
    • Independent registry for each

@tamird
Copy link
Contributor Author

tamird commented May 10, 2016

Rebased.

I don't think this is a "proper" handling of Accept header since it ignores media range and quality factor of the header. https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1

Yeah, it's probably incomplete, but still better than the current handling which conflates "content-type" (which specifies the incoming content) with "accept" (which specifies the outgoing content).

Accept header is not the right way to identify MIME type of request body.

This is not what this PR does. It uses "content-type" to identify the MIME type of the incoming request, but uses "accept" to determine the MIME type that should be used to encode the outgoing response.

If we handle the header, it would require:

  • interpret media range and quality factor
    • split Marshaler into Marshaler and Unmarshaler.
      • Independent registry for each

Yes, we could do these things, but it doesn't seem "required" to me. I'm not sure splitting Marshaler and Unmarshaler is even worth it, but I'll leave that decision to you. Nevertheless, I don't think that refactoring should block this change.


for _, contentTypeVal := range r.Header[contentTypeHeader] {
if m, ok := mux.marshalers.mimeMap[contentTypeVal]; ok {
outbound = m
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you mean inbound = m?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, done.

@yugui
Copy link
Member

yugui commented May 11, 2016

@tamird
Thank you. I confused something in the original commits.

I'll add some comments.

}
if outbound == nil {
outbound = defaultMarshaler
outbound = mux.marshalers.mimeMap[MIMEWildcard]
Copy link
Member

@yugui yugui May 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try falling back to mux.marshalers.mimeMap[contentTypeHeader] before MIMEWildcard

So this line can be just outbound = inbound.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Also greatly simplifies existing logic to avoid special casing of
defaults.
@tamird
Copy link
Contributor Author

tamird commented May 14, 2016

@yugui ping, could you take another look?

@yugui
Copy link
Member

yugui commented May 16, 2016

LGTM. Thank you for your contribution.

@yugui yugui merged commit f5cb0d7 into grpc-ecosystem:master May 16, 2016
@tamird
Copy link
Contributor Author

tamird commented May 16, 2016

Thanks!

@tamird tamird deleted the mime-handle-accept-correctly branch May 16, 2016 02:06
adasari pushed a commit to adasari/grpc-gateway that referenced this pull request Apr 9, 2020
…correctly

custom marshaler: handle `Accept` headers correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants