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

Use an interface for ContentTypeFromMessage #1150

Merged

Conversation

wtlangford
Copy link
Contributor

This allows custom Marshaler implementations to vary the HTTP response's Content-Type based on the returned proto.

Because of the comments around adding the interface param to the existing ContentType() function, I left the interface unexported, so that it doesn't become part of the public API of the package.

Alternatively, it could be exported and used to eventually deprecate the old Marshaler interface in favor of a more flexible ContentTypeFromMessage.

// A ContentTypeMarshaler is a Marshaler that can vary its Content-Type based on the response value
type ContentTypeMarshaler interface {
   Marshaler
   ContentTypeFromMessage(v interface{}) string
}

Is there a preference between the two approaches?

@johanbrandhorst
Copy link
Collaborator

Hi William, thanks for the PR! Do you mind explaining why you want this feature added? I appreciate that this is a pretty minimally disruptive change, so I don't have any reservations, but if you have a particular use case in mind it would help me understand why the existing solution isn't good enough.

@wtlangford
Copy link
Contributor Author

We've added a custom marshaler in our application that wraps the existing HTTPBodyMarshaler and provides some additional functionality (mapping the request body into an google.api.HttpBody). Unfortunately, when we use that marshaler, we no longer have the Content-Type header properly set on responses that use google.api.HttpBody.

I'm happy to look at separately contributing back the request-mapping functionality, but this felt like a useful way to allow other custom marshalers to use ContentTypeFromMessage.

@johanbrandhorst
Copy link
Collaborator

Hi, please rebase on master, I've moved some folders around, but otherwise SGTM.

This allows custom Marshaler implementations to vary their Content-Type
based on the response
@wtlangford wtlangford force-pushed the httpbody-content-type branch from b5ea930 to 4a57bc0 Compare March 4, 2020 19:31
@johanbrandhorst johanbrandhorst merged commit 3156ca6 into grpc-ecosystem:master Mar 4, 2020
@wtlangford wtlangford deleted the httpbody-content-type branch March 4, 2020 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants