Skip to content

feat(multipart): add Form::set_boundary for custom boundaries#1094

Merged
0x676e67 merged 5 commits into0x676e67:mainfrom
sqdshguy:feat/custom-multipart-boundary
Mar 13, 2026
Merged

feat(multipart): add Form::set_boundary for custom boundaries#1094
0x676e67 merged 5 commits into0x676e67:mainfrom
sqdshguy:feat/custom-multipart-boundary

Conversation

@sqdshguy
Copy link
Copy Markdown
Contributor

Adds Form::set_boundary(&mut self, boundary: impl Into<String>) so users can specify their own multipart boundary string (e.g. ------WebKitFormBoundary... for browser emulation). This is useful for matching browser fingerprints during emulation, since the default gen_boundary() output doesn't resemble any real browser.

API and doc comment follow reqwest's approach in seanmonstar/reqwest#2814. Includes unit and integration tests.

Closes #1030

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 enhances the multipart form functionality by providing a mechanism for users to specify custom boundary strings. This capability is vital for use cases such as browser emulation, where precise control over the multipart boundary is necessary to mimic specific client behaviors. The implementation includes clear documentation regarding the potential risks of using custom boundaries and is thoroughly tested to ensure its reliability.

Highlights

  • Feature Addition: Introduced a new public method, Form::set_boundary, allowing users to explicitly define the multipart boundary string.
  • Use Case: This feature is primarily intended for advanced scenarios like browser emulation, where matching specific browser-generated boundary fingerprints is crucial.
  • Risk Mitigation: The documentation for set_boundary includes a prominent warning about the significant risk of generating corrupted bodies when using custom boundaries, advising users to proceed with caution.
  • Testing: Comprehensive testing has been added, including both a unit test in src/client/multipart.rs and an integration test in tests/multipart.rs, to ensure the correct application and behavior of custom boundaries.
Changelog
  • src/client/multipart.rs
    • Added pub fn set_boundary(&mut self, boundary: impl Into<String>) to the Form struct.
    • Included a detailed doc comment for set_boundary explaining its purpose and warning about potential risks.
    • Added a unit test custom_boundary_is_applied to verify the functionality of setting a custom boundary.
  • tests/multipart.rs
    • Added an integration test text_part_with_custom_boundary to validate that custom boundaries are correctly used in a full request-response cycle.
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
Copy Markdown
Contributor

@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 adds the ability to set a custom boundary for multipart forms, which is a useful feature for browser emulation. The implementation is straightforward and follows the pattern of similar APIs in other libraries. The addition of both unit and integration tests is great. I've found one issue in the new integration test related to how a multi-line string is defined, which would likely cause the test to fail. I've left a suggestion to fix it. This seems to be a pattern copied from other tests, so it might be worth fixing it in other places as well.

@0x676e67
Copy link
Copy Markdown
Owner

0x676e67 commented Mar 12, 2026

I prefer the "with_boundary" initialization method over "set_boundary".

    pub fn with_boundary(boundary: impl Into<String>) -> Form {
        let mut inner = FormParts::new();
        inner.boundary = boundary;
        Form { inner }
    }

@sqdshguy
Copy link
Copy Markdown
Contributor Author

I prefer the "with_boundary" initialization method over "set_boundary".

    pub fn with_boundary(boundary: impl Into<String>) -> Form {
        let mut inner = FormParts::new();
        inner.boundary = boundary;
        Form { inner }
    }

Done. Let me know if there's something else to change. First time contributing here, so not sure about the conventions

@0x676e67 0x676e67 merged commit 30adda1 into 0x676e67:main Mar 13, 2026
22 checks passed
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.

Add a way to specify own multipart boundaries / browser-emulated multipart boundaries

2 participants