Skip to content

Commit ab1b6a5

Browse files
Add Form::set_boundary to customize multipart boundary
Customizing the boundary makes it easier to write tests that assert on the Content-Type header and body, as the content can be static. Method documentation sufficiently describes the risk of doing this. Closes #2374
1 parent b540a4e commit ab1b6a5

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/async_impl/multipart.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ impl Form {
7272
self.inner.boundary()
7373
}
7474

75+
/// Set the boundary that this form will use. By default the boundary is a
76+
/// long random string to minimize the risk of the boundary appearing in
77+
/// the body content.
78+
///
79+
/// **Setting a custom boundary incurs significant risk of generating
80+
/// corrupted bodies.** Only use this if you need it and you understand the
81+
/// risk!
82+
pub fn set_boundary(&mut self, boundary: impl Into<String>) {
83+
self.inner.boundary = boundary.into();
84+
}
85+
7586
/// Add a data field with supplied name and value.
7687
///
7788
/// # Examples

src/blocking/multipart.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ impl Form {
7979
self.inner.boundary()
8080
}
8181

82+
/// Set the boundary that this form will use. By default the boundary is a
83+
/// long random string to minimize the risk of the boundary appearing in
84+
/// the body content.
85+
///
86+
/// **Setting a custom boundary incurs significant risk of generating
87+
/// corrupted bodies.** Only use this if you need it and you understand the
88+
/// risk!
89+
pub fn set_boundary(&mut self, boundary: impl Into<String>) {
90+
self.inner.boundary = boundary.into();
91+
}
92+
8293
/// Add a data field with supplied name and value.
8394
///
8495
/// # Examples

0 commit comments

Comments
 (0)