Skip to content

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

Closed
@budougumi0617

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions