-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add an option to override content type for a client #132
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for your contribution! I looked at the changes and they look good - I left few detailed comments to address or reply.
However, I am missing tests here. I see that there are no tests for that pkg yet - would you be okay with writing few unit tests for the change that you proposed? We usually write table-driven unit tests.
As a minimum test coverage, I would be curious to see:
- Behavior of the content-type header combined with various values of the
forceDowngrade
parameter, - Ensuring that the default value
application/grpc
is applied whencontentType
is empty, - Making sure that the library does not crash when nonsense values of
contentType
are provided
Thanks for the review! I am thinking, what is the best way to implement requested tests? Initially, I tried to add new tests to go-grpc-http1/_integration-tests/echo_service_test.go Lines 185 to 194 in c0b77f0
the problem is tests are failed, because of https://github.com/dhaus67/go-grpc-http1/blob/78361be32b62187099a40e07fb4a9d6eda16221a/server/server.go#L185-L189 Basically, right now current So, I can see the following ways to implement some tests:
But it looks like that both ways don't allow to test gRPC. It still will be just HTTP header assert, without guarantees that gRPC still works. |
Thanks for the attempt at writing the tests! I have several thoughts on that. The existing integration tests would definitely need to be adapted. We must make sure that by adding and using that feature we are not breaking the old behavior. Maybe instead of checking Additionally to the integration tests one could add unit tests that would cover the I think, that there is more value in the integration tests and the unit tests could be skipped. The problem you stumbled upon while attempting to write the test shows that the change in its current state is untested and cannot be added. The tests must by first updated and add test coverage for that change must be added. |
Sorry, I want to ask follow-up question to better understand, what I can do. I tried
) I got HTTP 415. Apparently, inside gRPC server (part of gRPC impl., not this library) there is another check for Basically, we can use only So, if we want to support
With such code, all new tests are green. Should I do this change? |
It is difficult for me to see the entire thing only based on a comment. It would be better to implement the change that you have in mind, so that we can see it in the code. If I understand your idea correctly, you propose that this library would accept multiple content types, but it would pass only the |
…http1 into add-custom-content-type
sorry, yes, you are right. I've pushed a code to show an idea. |
Hi @Hixon10 , I am sorry for no progress on reviewing this PR, we are having a hackathon week and some delays in other activities shall be expected. |
Hi! No problem at all! I will be happy to continue work on this PR any time, when you are available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for waiting for the review. I think this is safe to be merged - I run some additional integration tests locally and added a negative test scenario (when the content type is set to something bogus). Let's wait for the CI to evaluate this.
Suggested changes: I rephrased one comment for brevity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test results look good, marking it green
@vikin91 thanks a lot for helping with this PR and merging it at the end! |
Thank you for the contribution @Hixon10 . I merged myself, as external contributions must be merged through team members, but if you have some additional things that you want to add or change, then feel free to open another PR. |
At present, current implementation of a client sends
Content-Type: application/grpc
to a server. Because of it, some gRPC Web Servers does not work (for example, Official C# web gRPC server). Also, gRPC Web spec says that it is expected to get eitherapplication/grpc-web
, orapplication/grpc-web-text
content type.This PR adds a way to override content type, which will be sent to a server. This fix allows me to use your client with my web gRPC server, so I would be happy to merge it to upstream.