-
-
Notifications
You must be signed in to change notification settings - Fork 88
Fix doubleKnock request.clone() errors #335
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
Fix doubleKnock request.clone() errors #335
Conversation
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.
Summary of Changes
Hello @allouis, 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 addresses a bug where request.clone() could cause errors in the doubleKnock function, particularly during iterations and redirects. The core change involves centralizing the reading of the request body to a single operation and then passing this pre-read body buffer throughout the signing and redirection processes, improving robustness and efficiency.
Highlights
- Refactored Request Body Handling: I've refactored the
doubleKnockfunction and related HTTP signing functions (signRequestDraft,signRequestRfc9421) to preventrequest.clone()errors. The request body is now read once at the top level ofdoubleKnockand passed as anArrayBufferthrough subsequent operations, including signing and redirect handling, avoiding multiple costly and error-prone cloning operations. - API Surface Extension: I've extended the
SignRequestOptionsandDoubleKnockOptionsinterfaces with an optionalbodyparameter (ArrayBuffer | null). This allows callers to pre-provide the request body, further optimizing scenarios where the body is already available. - Improved Redirect Logic: The redirect handling within
doubleKnockhas been updated to consistently reuse the pre-read request body buffer, eliminating redundant body cloning during redirects and ensuring proper request signing for redirected requests.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 or fill out our survey to provide feedback.
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
-
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. ↩
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 effectively addresses the request.clone() errors in doubleKnock by refactoring the logic to read the request body only once at the top level. The changes are consistent and well-implemented, passing the pre-read body down to the signing functions and recursive calls. The addition of a regression test is also a great way to ensure the fix is effective and prevents future regressions.
I've added a few suggestions to improve the readability of the new body-handling logic by refactoring the nested ternary expressions into clearer if/else blocks. This should enhance the code's maintainability.
This refactors the doubleKnock function and related signing functions to get the request body once at the top level instead of cloning it multiple times during iterations and redirects. Changes: - Add optional `body` parameter to SignRequestOptions and DoubleKnockOptions - Update signRequestDraft and signRequestRfc9421 to accept pre-read body - Modify doubleKnock to read body once and pass through all operations - Update redirect handling to reuse the same body buffer
9ea2c21 to
fc7178a
Compare
|
The latest push to this pull request has been published to JSR and npm as a pre-release: |
|
The docs for this pull request have been published: |
|
Shipped with v1.7.7. |
ref fedify-dev/fedify#335 ref fedify-dev/fedify#324 This bump to fedify includes two fixes the the doubleKnock implementation. One which is an attempt to remedy the 'unusable' errors when cloning the request objects, and the other which handles relative paths in the Location header when recieving a redirect. Both of these errors cause significant noise in our production environment and cleaning them up should allow us to spot real errors a lot easier in future.
ref fedify-dev/fedify#335 ref fedify-dev/fedify#324 This bump to fedify includes two fixes the the doubleKnock implementation. One which is an attempt to remedy the 'unusable' errors when cloning the request objects, and the other which handles relative paths in the Location header when recieving a redirect. Both of these errors cause significant noise in our production environment and cleaning them up should allow us to spot real errors a lot easier in future.
This refactors the doubleKnock function and related signing functions to get the request body once at the top level instead of cloning it multiple times during iterations and redirects.
Changes:
bodyparameter to SignRequestOptions and DoubleKnockOptionsThis has already been approved and merged into
mainbut we want to backport the bug fix to 1.7.x