-
Notifications
You must be signed in to change notification settings - Fork 301
fix: Reimplement HTTP/2 response entity consumption using ApacheHttp2AsyncEntityConsumer and ApacheHttp2Entity #1181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…AsyncEntityConsumer and ApacheHttp2Entity
Summary of ChangesHello @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 Highlights
🧠 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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.
src/main/java/com/google/firebase/internal/ApacheHttp2AsyncEntityConsumer.java
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| public byte[] getContent() { | ||
| return content; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| return content; | |
| return content == null ? null : content.clone(); |
There was a problem hiding this comment.
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.
src/test/java/com/google/firebase/internal/ApacheHttp2TransportTest.java
Outdated
Show resolved
Hide resolved
|
/gemini review |
Summary of ChangesThis pull request refactors the HTTP/2 response handling mechanism to accurately capture and expose full entity details. By replacing the generic Highlights
🧠 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
Activity
|
|
/gemini review |
There was a problem hiding this 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.
| public ApacheHttp2Entity(byte[] content, EntityDetails entityDetails) { | ||
| this.content = content; | ||
| this.entityDetails = entityDetails; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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; | |
| } |
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.