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

bugfix: disable IOReaderFactory for streaming requests #896

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions examples/proto/examplepb/flow_combination.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions examples/proto/examplepb/stream.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions protoc-gen-grpc-gateway/gengateway/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,7 @@ func request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ctx cont
grpclog.Infof("Failed to start streaming: %v", err)
return nil, metadata, err
}
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
dec := marshaler.NewDecoder(newReader())
dec := marshaler.NewDecoder(req.Body)
for {
var protoReq {{.Method.RequestType.GoType .Method.Service.File.GoPkg.Path}}
err = dec.Decode(&protoReq)
Expand Down Expand Up @@ -303,8 +299,8 @@ var (
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
} else {
protoReq.{{.FieldMaskField}} = fieldMask
}
} {{end}}
}
} {{end}}
{{end}}
{{end}}
{{if .PathParams}}
Expand Down Expand Up @@ -378,11 +374,7 @@ var (
grpclog.Infof("Failed to start streaming: %v", err)
return nil, metadata, err
}
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, berr
}
dec := marshaler.NewDecoder(newReader())
dec := marshaler.NewDecoder(req.Body)
handleSend := func() error {
var protoReq {{.Method.RequestType.GoType .Method.Service.File.GoPkg.Path}}
err := dec.Decode(&protoReq)
Expand Down
9 changes: 3 additions & 6 deletions protoc-gen-grpc-gateway/gengateway/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,6 @@ func TestApplyTemplateRequestWithClientStreaming(t *testing.T) {
if want := spec.sigWant; !strings.Contains(got, want) {
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
}
if want := `marshaler.NewDecoder(newReader()`; !strings.Contains(got, want) {
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
}
if want := `func RegisterExampleServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {`; !strings.Contains(got, want) {
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
}
Expand Down Expand Up @@ -482,7 +479,7 @@ func TestAllowPatchFeature(t *testing.T) {
}
}

func TestIdentifierCapitalization(t *testing.T){
func TestIdentifierCapitalization(t *testing.T) {
msgdesc1 := &protodescriptor.DescriptorProto{
Name: proto.String("Exam_pleRequest"),
}
Expand All @@ -492,12 +489,12 @@ func TestIdentifierCapitalization(t *testing.T){
meth1 := &protodescriptor.MethodDescriptorProto{
Name: proto.String("ExampleGe2t"),
InputType: proto.String("Exam_pleRequest"),
OutputType: proto.String("example_response"),
OutputType: proto.String("example_response"),
}
meth2 := &protodescriptor.MethodDescriptorProto{
Name: proto.String("Exampl_eGet"),
InputType: proto.String("Exam_pleRequest"),
OutputType: proto.String("example_response"),
OutputType: proto.String("example_response"),
}
svc := &protodescriptor.ServiceDescriptorProto{
Name: proto.String("Example"),
Expand Down