Content-length: 0 confuses grpc-web client
See original GitHub issueA gRPC server could send back a gRPC response without any body, for example, a gRPC error response. However, some server could choose not to use “trailers-only” to send back the “grpc-status”. Instead, it still uses “headers”, “empty body”, “trailers” HTTP/2 frames, and the grpc-status and grpc-message are set in the trailers.
There could be scenario when “content-length: 0” is added to the response header as the body is empty. For example, if the gRPC server is fronted by an envoy, the envoy could add “C-L: 0”. See https://github.com/envoyproxy/envoy/issues/5554. An example response looks like this:
envoy_1 | [2021-06-19 02:40:08.061][15][debug][http] [source/common/http/conn_manager_impl.cc:1472] [C6][S17521888214259471014] encoding headers via codec (end_stream=false):
envoy_1 | ':status', '200'
envoy_1 | 'grpc-accept-encoding', 'identity'
envoy_1 | 'grpc-encoding', 'identity'
envoy_1 | 'content-type', 'application/grpc+proto'
envoy_1 | 'date', 'Sat, 19 Jun 2021 02:40:08 GMT'
envoy_1 | 'server', 'envoy'
envoy_1 | 'x-cloud-trace-context', 'a86f4f6eeee8e5baccd463176c163b05/11003727237429165764'
envoy_1 | 'content-length', '0'
envoy_1 | 'x-envoy-upstream-service-time', '170'
envoy_1 |
envoy_1 | [2021-06-19 02:40:08.062][15][debug][client] [source/common/http/codec_client.cc:130] [C7] response complete
envoy_1 | [2021-06-19 02:40:08.062][15][debug][pool] [source/common/conn_pool/conn_pool_base.cc:200] [C7] destroying stream: 0 remaining
envoy_1 | [2021-06-19 02:40:08.062][15][debug][http] [source/common/http/conn_manager_impl.cc:1488] [C6][S17521888214259471014] encoding trailers via codec:
envoy_1 | 'grpc-status', '200'
envoy_1 | 'grpc-message', 'invalid%20input'
For this case, as grpc-web filter doesn’t strip content-length nor update content length after it encodes the trailers and puts it into the response body. The output from the filter could confuses the grpc-web client and makes it reject the response.
See a reproduction case in https://github.com/ridedott/grpc-web-cloud-run-issue And confirm removing content-length header makes the grpc-web client happy: https://github.com/ridedott/grpc-web-cloud-run-issue
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7
#1050 (comment) solved it for us.
Hey all. What’s the current status on this and are there any workarounds in the time being?