Skip to content

Commit

Permalink
Support cases where the request is done with transfer-encoding chunked
Browse files Browse the repository at this point in the history
PR grpc-ecosystem#527 was put in place to fix an issue where an empty request body
would cause an empty message to be sent down to the GRPC service
(instead of failing). The fix at the time was to check that the
ContentLength was >0, but this doesn't take into consideration
transfer-encoding chunked POSTs. Since this patch all chunked POSTs
no longer unmarshal the message (as the content-length was 0).

My proposed fix is instead to always call Decode and simply ignore EOF
errors (as we still want to pass the un-filled struct down). I have
tested that things such as partial json blobs (something like '{') don'
t return EOF (they have their own json error).
  • Loading branch information
jacksontj committed Apr 12, 2018
1 parent 3189c0c commit 1a0cf45
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions protoc-gen-grpc-gateway/gengateway/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,8 @@ var (
var protoReq {{.Method.RequestType.GoType .Method.Service.File.GoPkg.Path}}
var metadata runtime.ServerMetadata
{{if .Body}}
if req.ContentLength > 0 {
if err := marshaler.NewDecoder(req.Body).Decode(&{{.Body.RHS "protoReq"}}); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := marshaler.NewDecoder(req.Body).Decode(&{{.Body.RHS "protoReq"}}); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
{{end}}
{{if .PathParams}}
Expand Down

0 comments on commit 1a0cf45

Please sign in to comment.