golang / protobuf

Go support for Google's protocol buffers
BSD 3-Clause "New" or "Revised" License
9.8k stars 1.58k forks source link

google.protobuf.Empty as response serializes to not empty response depending on request headers #1636

Closed abraxasjoshuricke closed 4 months ago

abraxasjoshuricke commented 4 months ago

What version of protobuf and what language are you using? Version: go 1.22, github.com/golang/protobuf v1.5.3, google.golang.org/protobuf v1.31.0, google.golang.org/grpc v1.59.0, github.com/grpc-ecosystem/grpc-gateway v1.16.0

What did you do? We are using protobuf with grpc-gateway for our go application. When returning google.protobuf.Empty we are getting an not empty response. This happens depending on what request headers are being sent. These two headers in combination result in the faulty behaviour: 'Accept: text/html' 'Content-Type: application/x-www-form-urlencoded'

What did you expect to see? An empty response, regardless of what headers are being sent.

What did you see instead? Flags=3&denseCoderFields=null&initDone=1&isMessageSet=false&needsInitCheck=false&numRequiredFields=0&sema=0&sizeCache=0&state=0&unknownPtrKind=false

I debugged pretty deep into the source code and found out that the fields getting serialized to the response are from the message field 'coderMessageInfo' -> https://github.com/protocolbuffers/protobuf-go/blob/v1.31.0/internal/impl/codec_message.go#L22 Sadly I was not able to figure out where and why these fields are getting serialized.

Thanks for your help!

Kind Regards Joshu

puellanivis commented 4 months ago

This project is not responsible for the bodies which gRPC transmits. I recommend you look there for the reason this is being serialized as such: https://github.com/grpc/grpc

However, to add in, I think this is expected behavior: https://github.com/grpc/grpc-go/blob/0b33bfe7863c548658efdb4eac6e742ef2c8f3de/test/http_header_end2end_test.go#L46-L53 you’re telling it text/html not application/grpc then this will have compounding issues with how the gRPC server interprets the expected response to your request.

abraxasjoshuricke commented 4 months ago

Thank you for your input. Yeah I figured something like that. I will still ask the people over there what they think of it.

Thanks and have a nice day! Kind Regards