Skip to content

Conversation

@jonathanedey
Copy link
Collaborator

@jonathanedey jonathanedey commented Feb 10, 2026

This pr introduces logic to change the source of truth for response metadata from relying on static headers to instead using the final response state. This allows the more accurate post-processing response metadata to be passed to the google http client layer and prevent double-decompression.

@jonathanedey jonathanedey added the release:stage Stage a release candidate label Feb 10, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @jonathanedey, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the HTTP/2 response handling mechanism to accurately capture and expose full entity details. By replacing the generic SimpleResponseConsumer with a custom implementation, the system can now reliably access critical response metadata such as content encoding, length, and type, which is essential for correct processing of HTTP/2 responses. This change improves the fidelity of response data passed to the Google HTTP client and enhances the overall robustness of the HTTP/2 transport layer.

Highlights

  • HTTP/2 Response Entity Consumption: Reimplemented HTTP/2 response entity consumption using custom ApacheHttp2AsyncEntityConsumer and ApacheHttp2Entity classes. This replaces the SimpleResponseConsumer which lacked access to full entity details.
  • Accurate Response Metadata: Ensured that response entity details (like content encoding, length, and type) are correctly captured and exposed, providing a source of truth for response metadata that Apache HTTP client headers might not update during processing.
  • Enhanced Response Handling: Updated ApacheHttp2Request to utilize the new entity consumer and ApacheHttp2Response to correctly parse and expose content and entity details from the new Message<HttpResponse, ApacheHttp2Entity> structure.
  • New Test Cases: Added new test cases to validate the handling of gzipped responses and empty responses with headers, ensuring robustness and correctness of the new entity consumption mechanism.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/main/java/com/google/firebase/internal/ApacheHttp2AsyncEntityConsumer.java
    • Added new class ApacheHttp2AsyncEntityConsumer to implement AsyncEntityConsumer for Apache HTTP/2, enabling custom consumption of response entities.
    • Implemented streamStart, updateCapacity, consume, streamEnd, failed, releaseResources, and getContent methods to manage the lifecycle and buffering of response data.
  • src/main/java/com/google/firebase/internal/ApacheHttp2Entity.java
    • Added new class ApacheHttp2Entity to encapsulate the byte array content and EntityDetails of an HTTP/2 response, providing a structured way to store response body and metadata.
  • src/main/java/com/google/firebase/internal/ApacheHttp2Request.java
    • Removed imports for SimpleHttpResponse and SimpleResponseConsumer.
    • Added imports for HttpResponse, Message, and BasicResponseConsumer.
    • Introduced a new field entityConsumer of type ApacheHttp2AsyncEntityConsumer.
    • Modified the execute method to instantiate and use ApacheHttp2AsyncEntityConsumer with BasicResponseConsumer for handling HTTP/2 responses.
    • Updated the responseFuture type from Future<SimpleHttpResponse> to Future<Message<HttpResponse, ApacheHttp2Entity>>.
    • Adjusted the return type of execute to handle the new Message structure.
    • Added a @VisibleForTesting method getEntityConsumer() to expose the consumer for testing purposes.
  • src/main/java/com/google/firebase/internal/ApacheHttp2Response.java
    • Removed imports for SimpleHttpResponse and ContentType.
    • Added imports for EntityDetails, HttpResponse, Message, and StatusLine.
    • Modified the constructor to accept Message<HttpResponse, ApacheHttp2Entity> instead of SimpleHttpResponse.
    • Introduced new fields message, response, entity, and content to store the full response message, HTTP response head, entity details, and content bytes respectively.
    • Updated getContent(), getContentEncoding(), getContentLength(), getContentType(), getStatusLine(), and getHeaderValue() methods to retrieve information from the new entity and content fields, ensuring accurate metadata extraction.
    • Changed the @VisibleForTesting method getResponse() to getMessage() and updated its return type to Message<HttpResponse, ApacheHttp2Entity>.
  • src/test/java/com/google/firebase/internal/ApacheHttp2TransportTest.java
    • Added imports for Message and BasicHttpResponse.
    • Updated mock doExecute implementations to return CompletableFuture.completedFuture(new Message<HttpResponse, ApacheHttp2Entity>(...)) instead of SimpleHttpResponse.
    • Modified assertions in existing tests to correctly access response details from the new Message and ApacheHttp2Entity structure.
    • Added testGzipResponse() to verify correct handling and decompression of gzipped HTTP responses.
    • Added testEmptyResponseWithHeaders() to ensure that responses with no body but valid headers are handled without NullPointerException.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the HTTP/2 response consumption logic to use a custom ApacheHttp2AsyncEntityConsumer and ApacheHttp2Entity. This is a significant improvement as it allows access to the response EntityDetails, providing a more reliable way to get response metadata like content length and encoding, especially when transformations like gzip decompression occur. The implementation is solid, and the addition of new tests for gzip handling and empty responses is very valuable. I've provided a few suggestions to further improve performance, ensure immutability, and enhance test code quality.

}

public byte[] getContent() {
return content;

Choose a reason for hiding this comment

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

medium

The getContent() method returns the internal byte[] array directly. To preserve the immutability of this object, it's better to return a defensive copy of the array. This prevents callers from modifying the internal state of the ApacheHttp2Entity instance.

Suggested change
return content;
return content == null ? null : content.clone();

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since this is all internal I don't think we need to be this strict. It's also wrapped later in a ByteArrayInputStream before it's accessible by the google http client.

@jonathanedey
Copy link
Collaborator Author

jonathanedey commented Feb 10, 2026

/gemini review

@gemini-code-assist
Copy link

Summary of Changes

This pull request refactors the HTTP/2 response handling mechanism to accurately capture and expose full entity details. By replacing the generic SimpleResponseConsumer with a custom implementation, the system can now reliably access critical response metadata such as content encoding, length, and type, which is essential for correct processing of HTTP/2 responses. This change improves the fidelity of response data passed to the Google HTTP client and enhances the overall robustness of the HTTP/2 transport layer.

Highlights

  • HTTP/2 Response Entity Consumption: Reimplemented HTTP/2 response entity consumption using custom ApacheHttp2AsyncEntityConsumer and ApacheHttp2Entity classes, replacing the SimpleResponseConsumer which lacked access to full entity details.
  • Accurate Response Metadata: Ensured that response entity details (like content encoding, length, and type) are correctly captured and exposed, providing a reliable source of truth for response metadata.
  • Enhanced Response Handling: Updated ApacheHttp2Request to utilize the new entity consumer and ApacheHttp2Response to correctly parse and expose content and entity details from the new Message<HttpResponse, ApacheHttp2Entity> structure.
  • New Test Cases: Added new test cases to validate the handling of gzipped responses and empty responses with headers, ensuring robustness and correctness of the new entity consumption mechanism.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/main/java/com/google/firebase/internal/ApacheHttp2AsyncEntityConsumer.java
    • Added new class ApacheHttp2AsyncEntityConsumer to implement AsyncEntityConsumer for Apache HTTP/2, enabling custom consumption of response entities.
    • Implemented streamStart, updateCapacity, consume, streamEnd, failed, releaseResources, and getContent methods to manage the lifecycle and buffering of response data.
  • src/main/java/com/google/firebase/internal/ApacheHttp2Entity.java
    • Added new class ApacheHttp2Entity to encapsulate the byte array content and EntityDetails of an HTTP/2 response, providing a structured way to store response body and metadata.
  • src/main/java/com/google/firebase/internal/ApacheHttp2Request.java
    • Removed imports for SimpleHttpResponse and SimpleResponseConsumer.
    • Added imports for HttpResponse, Message, and BasicResponseConsumer.
    • Introduced a new field entityConsumer of type ApacheHttp2AsyncEntityConsumer.
    • Modified the execute method to instantiate and use ApacheHttp2AsyncEntityConsumer with BasicResponseConsumer for handling HTTP/2 responses.
    • Updated the responseFuture type from Future<SimpleHttpResponse> to Future<Message<HttpResponse, ApacheHttp2Entity>>.
    • Adjusted the return type of execute to handle the new Message structure.
    • Added a @VisibleForTesting method getEntityConsumer() to expose the consumer for testing purposes.
  • src/main/java/com/google/firebase/internal/ApacheHttp2Response.java
    • Removed imports for SimpleHttpResponse and ContentType.
    • Added imports for EntityDetails, HttpResponse, Message, and StatusLine.
    • Modified the constructor to accept Message<HttpResponse, ApacheHttp2Entity> instead of SimpleHttpResponse.
    • Introduced new fields message, response, entity, and content to store the full response message, HTTP response head, entity details, and content bytes respectively.
    • Updated getContent(), getContentEncoding(), getContentLength(), getContentType(), getStatusLine(), and getHeaderValue() methods to retrieve information from the new entity and content fields, ensuring accurate metadata extraction.
    • Changed the @VisibleForTesting method getResponse() to getMessage() and updated its return type to Message<HttpResponse, ApacheHttp2Entity>.
  • src/test/java/com/google/firebase/internal/ApacheHttp2TransportTest.java
    • Added imports for Message and BasicHttpResponse.
    • Updated mock doExecute implementations to return CompletableFuture.completedFuture(new Message<HttpResponse, ApacheHttp2Entity>(...)) instead of SimpleHttpResponse.
    • Modified assertions in existing tests to correctly access response details from the new Message and ApacheHttp2Entity structure.
    • Added testGzipResponse() to verify correct handling and decompression of gzipped HTTP responses.
    • Added testEmptyResponseWithHeaders() to ensure that responses with no body but valid headers are handled without NullPointerException.
Activity
  • gemini-code-assist[bot] provided an initial summary of the changes in the pull request.
  • gemini-code-assist[bot] suggested an optimization for the consume method in ApacheHttp2AsyncEntityConsumer.java to avoid intermediate array allocation by checking for a backing array.
  • gemini-code-assist[bot] suggested returning a defensive copy of the content array in ApacheHttp2Entity.getContent() to preserve immutability.
  • jonathanedey responded to the immutability suggestion, noting that the object is internal and its content is wrapped in a ByteArrayInputStream before external access.
  • gemini-code-assist[bot] suggested removing System.out.println statements from test files to keep test output clean.
  • jonathanedey requested a summary from gemini-code-assist[bot].

@jonathanedey
Copy link
Collaborator Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly reimplements the HTTP/2 response entity consumption to gain access to entity details, which is crucial for handling scenarios like automatic content decompression. The introduction of ApacheHttp2AsyncEntityConsumer and ApacheHttp2Entity is well-executed, and the changes in ApacheHttp2Request and ApacheHttp2Response are appropriate. The new tests for gzip and empty responses are excellent additions that improve the robustness of the transport. I have one suggestion to improve the immutability of ApacheHttp2Entity.

Comment on lines +25 to +28
public ApacheHttp2Entity(byte[] content, EntityDetails entityDetails) {
this.content = content;
this.entityDetails = entityDetails;
}

Choose a reason for hiding this comment

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

medium

To ensure ApacheHttp2Entity is immutable, the constructor should create a defensive copy of the content byte array. This prevents the internal state of the object from being modified by external code that might hold a reference to the original array.

Suggested change
public ApacheHttp2Entity(byte[] content, EntityDetails entityDetails) {
this.content = content;
this.entityDetails = entityDetails;
}
public ApacheHttp2Entity(byte[] content, EntityDetails entityDetails) {
this.content = (content != null) ? content.clone() : null;
this.entityDetails = entityDetails;
}

@jonathanedey jonathanedey marked this pull request as ready for review February 10, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:stage Stage a release candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants