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

application/x-www-form-urlencoded support. #960

Closed
Miladrzh opened this issue Jun 25, 2019 · 6 comments
Closed

application/x-www-form-urlencoded support. #960

Miladrzh opened this issue Jun 25, 2019 · 6 comments

Comments

@Miladrzh
Copy link

Hello to all grpc-gateway community.

I have a api call which its request is post and data come in application/x-www-form-urlencoded format

for example:

foo=bar&something=somethingelse

But grpc-gateway cant serialize it into my request.
i use proto3 and my request is like

message Req{
    string token = 1;
    string body = 3;
}

rpc SamanPayPostCallback(Req) returns (google.api.HttpBody) {
        option (google.api.http) = {
            post: "/x/{token}"
            body: "body"
        };
}

I try to serialize it like strings or like bytes but none of them work correct even in bytes.

i get this error when i call my api with this body

foo=bar&something=somethingelse

"invalid character 'f' looking for beginning of value"

Can anybody help me what should i do?

@johanbrandhorst
Copy link
Collaborator

@Miladrzh thanks for your bug report. We do test this in our integration tests, so it should be working: https://github.com/grpc-ecosystem/grpc-gateway/blob/master/examples/integration/integration_test.go#L1502. The main difference is that our integration tests use a "GET" request for this:
https://github.com/grpc-ecosystem/grpc-gateway/blob/master/examples/proto/examplepb/a_bit_of_everything.proto#L441. Maybe try that?

@johanbrandhorst
Copy link
Collaborator

Looking at the code, I think the problem is that you've defined it as POST actually. Why aren't you using JSON if you're using a post request?

@johanbrandhorst
Copy link
Collaborator

Take a look at the source:

for m, handlers := range s.handlers {
. It will allow falling back to POST if it doesn't already match anything. I think if you want to use POST and application/x-www-form-urlencoded you have to define a custom marshaller.

@Miladrzh
Copy link
Author

Unfortunatelly, i can't change the request cause it comes from outside resources which that protocol is like that.

I know it needs a custom marshaller but does grpc-gateway have plan to implement this marshaller?

As many framework like django recognize post in application/x-www-form-urlencoded format.

@johanbrandhorst
Copy link
Collaborator

You can implement your own Marshaler and hand it to runtime.WithMarshalerOption: https://godoc.org/github.com/grpc-ecosystem/grpc-gateway/runtime#WithMarshalerOption.

@johanbrandhorst
Copy link
Collaborator

If you implement a form marshaler and would like to contribute it back to us, you're welcome to do so. I will close this issue as I think there's a clear path forward. Please let me know if you need more help.

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

No branches or pull requests

2 participants