Skip to content

core: Clarify missing content-type on HTTP error responses#12720

Open
becomeStar wants to merge 1 commit intogrpc:masterfrom
becomeStar:fix/missing-content-type-error-detail
Open

core: Clarify missing content-type on HTTP error responses#12720
becomeStar wants to merge 1 commit intogrpc:masterfrom
becomeStar:fix/missing-content-type-error-detail

Conversation

@becomeStar
Copy link
Contributor

Summary

In this case, grpc-java preserves the HTTP status-based context, but may later append invalid content-type: null.

That seems misleading when the response is missing content-type, because the header appears to be absent rather than invalid, and the null value exposes a Java implementation detail.

This PR keeps the existing HTTP-to-gRPC status mapping unchanged and only adjusts the diagnostic for the missing content-type case.

Changes

  • keep the existing HTTP-to-gRPC status mapping unchanged
  • keep the existing behavior for invalid non-null content-types unchanged
  • replace invalid content-type: null with missing content-type in response headers

Ref #12418

Improve the client-side diagnostic for HTTP error responses that are
missing `content-type`.

grpc-java currently may report a missing header as
`invalid content-type: null`. Keep the existing HTTP-to-gRPC status
mapping unchanged and replace that detail with a more accurate message.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves gRPC-Java client diagnostics when an HTTP error response is missing the content-type header, replacing the misleading invalid content-type: null message while keeping the existing HTTP→gRPC status mapping unchanged (per #12418).

Changes:

  • Adjust Http2ClientStreamTransportState.validateInitialMetadata() to emit missing content-type in response headers when the header is absent (null).
  • Preserve existing behavior/messages for invalid non-null content-type values.
  • Add a regression test covering missing content-type with an HTTP 431 response.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
core/src/main/java/io/grpc/internal/Http2ClientStreamTransportState.java Emits a clearer diagnostic when content-type is missing while keeping HTTP status mapping intact.
core/src/test/java/io/grpc/internal/Http2ClientStreamTransportStateTest.java Adds test coverage for the missing content-type + HTTP 431 case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kannanjgithub kannanjgithub added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Mar 23, 2026
@kannanjgithub
Copy link
Contributor

/gcbrun

@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants