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

New proposal: support for the google.api.HttpBody #904

Merged
merged 14 commits into from
Mar 11, 2019

Conversation

wimspaargaren
Copy link
Contributor

No description provided.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

go.sum Outdated Show resolved Hide resolved
Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

This is great, thank you so much for this! A couple of comments and I'm also wondering if you could put together something for the documentation as well? Along the lines of the patch examples: https://grpc-ecosystem.github.io/grpc-gateway/docs/patch.html.

@@ -16,7 +16,7 @@ type Marshaler interface {
// NewEncoder returns an Encoder which writes bytes sequence into "w".
NewEncoder(w io.Writer) Encoder
// ContentType returns the Content-Type which this marshaler is responsible for.
ContentType() string
ContentType(v interface{}) string
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we can change this without breaking backwards compatibility. Could we add a new interface with this new method and then type assert at marshalling time? That way we could support both new and old marshallers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it back and assert it at marshalling time. What do you think of this implementation?

runtime/marshal_httpbodyproto.go Outdated Show resolved Hide resolved
@wimspaargaren
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@wimspaargaren
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

go.mod Outdated Show resolved Hide resolved
// the actual message used as the response. If not, then this will
// simply fallback to the JSONPb marshaler.
type HTTPBodyMarshaler struct {
DefaultMarshaler Marshaler
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you embed this directly you can avoid defining the methods which just call the underlying implementations:

type HTTPBodyMarshaler struct {
	Marshaler
}

func SetHTTPBodyMarshaler(serveMux *ServeMux) {
	serveMux.marshalers.mimeMap[MIMEWildcard] = &HTTPBodyMarshaler{
		Marshaler: &JSONPb{OrigName: true},
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted.

"bytes"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/genproto/googleapis/api/httpbody"
"testing"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, same thing about the imports please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@johanbrandhorst
Copy link
Collaborator

A couple of comments and I'm also wondering if you could put together something for the documentation as well? Along the lines of the patch examples: https://grpc-ecosystem.github.io/grpc-gateway/docs/patch.html.

What do you think about this?

@codecov-io
Copy link

codecov-io commented Mar 11, 2019

Codecov Report

Merging #904 into master will decrease coverage by 0.07%.
The diff coverage is 41.37%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #904      +/-   ##
==========================================
- Coverage   53.61%   53.54%   -0.08%     
==========================================
  Files          39       40       +1     
  Lines        3937     3961      +24     
==========================================
+ Hits         2111     2121      +10     
- Misses       1629     1642      +13     
- Partials      197      198       +1
Impacted Files Coverage Δ
runtime/handler.go 40.62% <0%> (-0.98%) ⬇️
runtime/proto_errors.go 0% <0%> (ø) ⬆️
runtime/errors.go 44.73% <50%> (-1.1%) ⬇️
runtime/marshal_httpbodyproto.go 69.23% <69.23%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6523154...44b123a. Read the comment docs.

runtime/marshal_httpbodyproto.go Outdated Show resolved Hide resolved
runtime/marshal_httpbodyproto.go Outdated Show resolved Hide resolved
@johanbrandhorst
Copy link
Collaborator

A couple of comments and I'm also wondering if you could put together something for the documentation as well? Along the lines of the patch examples: https://grpc-ecosystem.github.io/grpc-gateway/docs/patch.html.

What do you think about this?

Bump :D

@wimspaargaren
Copy link
Contributor Author

Not sure if it is added at the right place, but I added a small README for the httpbody :)

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

Great work, just a few comments on the new docs page.

docs/_docs/httpbody.md Show resolved Hide resolved
docs/_docs/httpbody.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up!

@wimspaargaren
Copy link
Contributor Author

No problem!

@johanbrandhorst
Copy link
Collaborator

johanbrandhorst commented Mar 29, 2019

I think that'd have to be part of your proto file annotation:

get: "/picture.jpg"

adasari pushed a commit to adasari/grpc-gateway that referenced this pull request Apr 9, 2020
* Implementation of HTTPBody marshaler

* Rework HTTPBodyMarshaler fallback marshaler

* Added tests.

* Fix gomod

* Fixed tests and added two new ones.

* Added marshal backwards compatibility

* Last line modsum was removed.

* Embedded Marshaler & fixed import order

* Removed inherited methods.

* Comment improvements

* Added small readme.

* Doc enhancements

* Identation fix

* What's wrong with identation
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.

4 participants