Skip to content

feat(http): Add support for working with Form buffers - #2532

Open
celarye wants to merge 2 commits into
twilight-rs:mainfrom
wpbs-rs:feat/form-buffer
Open

feat(http): Add support for working with Form buffers#2532
celarye wants to merge 2 commits into
twilight-rs:mainfrom
wpbs-rs:feat/form-buffer

Conversation

@celarye

@celarye celarye commented May 28, 2026

Copy link
Copy Markdown
Member

Add support for building Form based Requests using raw form buffers. This is useful when the buffer is transferred through a medium which does not know about the Form struct (e.g. WASM components).

@github-actions github-actions Bot added c-http Affects the http crate t-feature Addition of a new feature labels May 28, 2026
@celarye

celarye commented May 28, 2026

Copy link
Copy Markdown
Member Author

My previous Form::from_buffer implementation had an off by one error, I have not tested this new one yet. I'll try to do that ASAP and will update this PR with the results.

@celarye
celarye force-pushed the feat/form-buffer branch from 5a4fb88 to ba1aa2d Compare May 29, 2026 11:40
@celarye
celarye force-pushed the feat/form-buffer branch from ba1aa2d to 03c4004 Compare June 5, 2026 16:35
@celarye

celarye commented Jun 7, 2026

Copy link
Copy Markdown
Member Author

Seems like the latest Lavalink PR let a Clippy warning slip through...

@Erk-

Erk- commented Jun 8, 2026

Copy link
Copy Markdown
Member

Seems like the latest Lavalink PR let a Clippy warning slip through...

No it was unrelated to any code changes in that PR, I guess it is just a new case caught by default.

@celarye

celarye commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

Can't request a review but imo this is ready to merge

#[allow(clippy::missing_const_for_fn)]
pub fn form(mut self, form: Form) -> Self {
/// Set the the multipart form from an existing boundary and buffer.
pub fn multipart(mut self, boundary: [u8; 15], buffer: Vec<u8>) -> Self {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can simplify this. This is essentially a wrapper around the new Form::from_parts method and inlines the new RequestBuilder::form. Because Form is publicly exported from twilight_http::request I think it would be simpler to make Form::from_parts public and have users call the new RequestBuilder::form method. This way we're only increasing the API surface of this type by one method instead of two.

To summarize:

  • Remove multipart
  • Make Form::from_parts public

What do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The reason I've added this method was for it to match the json/body methods where you have one method which expects a Serializable struct and one which expects raw bytes.

So in case of forms I made it so now have one which expects a Form and one which expects raw bytes.

Asking users to call two methods (Form::from_parts and then RequestBuilder::form) sounds like a worse user experience but I get where you are coming from.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would like to hear opinions on this matter from a couple more people.

@celarye celarye self-assigned this Jul 28, 2026
@celarye
celarye force-pushed the feat/form-buffer branch from 03c4004 to 7e23bb4 Compare July 28, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c-http Affects the http crate t-feature Addition of a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants