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

Incorrect error message when execute protoc-gen-grpc-gateway to HTTP GET method with BODY #531

Closed
budougumi0617 opened this issue Jan 24, 2018 · 3 comments

Comments

@budougumi0617
Copy link
Contributor

budougumi0617 commented Jan 24, 2018

I try to compile by protoc-gen-grpc-gateway the below definition to generate reverse-proxy file.

service TaskManager {
  rpc GetTask (GetTaskRequest) returns (Task) {
    option (google.api.http) = {
       get: "/v1/tasklist-gateway/task/{id}" // "id" is defined in GetTaskRequest
       body: "*"
    };
  }
}

message GetTaskRequest {
  int32 id = 1;
}

protoc returns error with below text.

needs request body even though http method is GET: GetTask

protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. proto/task_list.proto
--grpc-gateway_out: needs request body even though http method is GET: GetTask

However, solution for the error is remove body statement.

  rpc GetTask (GetTaskRequest) returns (Task) {
    option (google.api.http) = {
       get: "/v1/tasklist-gateway/task/{id}" // "id" is defined in GetTaskRequest
    };
  }

I think HTTP GET request should not include BODY. It it correct error text?

Detail

Related implementation codes are below.

httpMethod = "GET"
pathTemplate = opts.GetGet()
if opts.Body != "" {
return nil, fmt.Errorf("needs request body even though http method is GET: %s", md.GetName())
}

		case opts.GetGet() != "":
			httpMethod = "GET"
			pathTemplate = opts.GetGet()
			if opts.Body != "" {
				return nil, fmt.Errorf("needs request body even though http method is GET: %s", md.GetName())
			}

It seems "if statement" validates that request body has no string, but error text is recommending set the request body. Also, I think DELETE method has same issue.

case opts.GetDelete() != "":
httpMethod = "DELETE"
pathTemplate = opts.GetDelete()
if opts.Body != "" && !r.allowDeleteBody {
return nil, fmt.Errorf("needs request body even though http method is DELETE: %s", md.GetName())
}

		case opts.GetDelete() != "":
			httpMethod = "DELETE"
			pathTemplate = opts.GetDelete()
			if opts.Body != "" && !r.allowDeleteBody {
				return nil, fmt.Errorf("needs request body even though http method is DELETE: %s", md.GetName())
			}

And, I created below pull request for this issue.
#532

I would appreciate it if you could check this issue, and PR.

@achew22
Copy link
Collaborator

achew22 commented Jan 24, 2018

Thank you for your thorough issue report and pull request. The behavior you specified is indeed incorrect. Sorry about that. I've merged your PR and you shouldn't have that sort of problem again.

Thanks so much for contributing!

@achew22 achew22 closed this as completed Jan 24, 2018
@lixin9311
Copy link

I think we should reconsider this issue.

FYI, https://stackoverflow.com/questions/978061/http-get-with-request-body

Any HTTP request message is allowed to contain a message body.

Although it's not a common way, at least provide an option for it, like DELETE.

@johanbrandhorst
Copy link
Collaborator

Maybe I can help you fix this issue without adding GET body parsing. What problem are you having? Feel free to drop by #grpc-gateway on the Gophers slack https://invite.slack.golangbridge.org/.

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

4 participants