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

fix body with "*" bug #804

Closed
wants to merge 1 commit into from

Conversation

ChenLingPeng
Copy link

@ChenLingPeng ChenLingPeng commented Nov 12, 2018

this code says that when body is set to "*" in a rpc service, all the query param will map to the request body, but the truth is not. when body is "*", b.Body != nil && len(b.Body.FieldPath) will be true and we should continue the method

Signed-off-by: forrestchen forrestchen@tencent.com

@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

@johanbrandhorst
Copy link
Collaborator

I'm confused, are you saying that parameters provided as query parameters should be parsed when body: "*" is set? I'm not sure it's a correct interpretation of the rule. My interpretation is that any parameters not part of the path should be in the request body. Do you have a practical example of this instead of a hypothetical interpretation?

@ChenLingPeng
Copy link
Author

In my case, I have a request
GET /v1/clusters?offset=0&limit=10
and request Body:

{"requestId":"xxx-xxx-xxx"}

@johanbrandhorst
Copy link
Collaborator

Leaving aside the point about having a body in a GET, what does your http.proto annotations look like for this RPC?

@ChenLingPeng
Copy link
Author

ChenLingPeng commented Nov 12, 2018

message TsfListClusterRequest {
    string requestId = 1;
    int32 offset = 2;
    int32 limit = 3;
}

message TsfListClusterResponse {
    int32 code = 1;
    string message = 2;
    string requestId = 3;
    TsfListClusterData data = 4;
}

rpc ListClusters(TsfListClusterRequest) returns (TsfListClusterResponse) {
    option (google.api.http)  = {
        get: "/tsf/v1.0/clusters"
        body: "*"
    };
}

@googlebot
Copy link

CLAs look good, thanks!

@johanbrandhorst
Copy link
Collaborator

So judging by your annotations I think the wording in http.proto implies that the parameters should go in the body. You can't expect it to read it from query parameters and the body when you use "*". Have you tried just using body: "request_id"?

Also; you should really use snake_case for proto file field names. https://developers.google.com/protocol-buffers/docs/style

@ChenLingPeng
Copy link
Author

when body is set to "request_id", the generate code is marshaler.NewDecoder(req.Body).Decode(&protoReq.RequestId) and will return an unmarshal error.

Signed-off-by: forrestchen <forrestchen@tencent.com>
@johanbrandhorst
Copy link
Collaborator

What does that error look like?

@ChenLingPeng
Copy link
Author

{"error":"json: cannot unmarshal object into Go value of type string","code":3}

@johanbrandhorst
Copy link
Collaborator

I'm wondering if that's a bug... it should be possible to have the specific parameter parsed from the body. Can you see why this is broken like this? You can't use * and expect query parameters to work.

@johanbrandhorst
Copy link
Collaborator

johanbrandhorst commented Nov 13, 2018

I think the premise of this PR is a flawed interpretation of http.proto, as I discussed in #234 (comment). Closing since the current behaviour is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants