#4238 Added the WithWriteContentLength ServerMuxOption #4239
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR Fixes #4238. The GRPC Gateway is currently relying on the default behavior of w.Write, which will only set Content-Length on small messages by default. For users who are running GRPC Gateway behind a CDN (i.e. CloudFront), this means they cannot take advantage of automatic compression handling for client requests.
Always setting the Content-Length header, isn't a great option, as middleware/forwardResponseOptions may be mutating the response and could lead to an invalid Content-Length being printed. While a forwardResponseOption could be used to write Content-Length, this would result in a double marshaling of the protobuf message and could potentially be incorrect in special cases.
This fix should be backwards compatible and avoids the downsides discussed above.