Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions bitreq/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,14 @@ impl Request {
body: None,
timeout: None,
pipelining: false,
max_headers_size: None,
max_status_line_len: None,
max_body_size: None,
// Default matches chrome as of 2022-11:
// https://groups.google.com/a/chromium.org/g/chromium-os-discuss/c/in-f59OKYAE/m/uVanwcXkAgAJ
// https://source.chromium.org/chromium/chromium/src/+/refs/heads/main:net/http/http_stream_parser.h;l=164-168;drc=66941d1f0cfe9155b400aef887fe39a403c1f518
max_headers_size: Some(256 * 1024),
// Probably could be 128 bytes, but set conservatively for good measure.
max_status_line_len: Some(64 * 1024),
// Picked somewhat randomly
max_body_size: Some(1024 * 1024 * 1024),
max_redirects: 100,
#[cfg(feature = "proxy")]
proxy: None,
Expand Down Expand Up @@ -221,8 +226,7 @@ impl Request {
///
/// `None` disables the cap, and may cause the program to use any
/// amount of memory if the server responds with a lot of headers
/// (or an infinite amount). The default is None, so setting this
/// manually is recommended when talking to untrusted servers.
/// (or an infinite amount). The default is 256KiB.
pub fn with_max_headers_size<S: Into<Option<usize>>>(mut self, max_headers_size: S) -> Request {
self.max_headers_size = max_headers_size.into();
self
Expand All @@ -239,8 +243,7 @@ impl Request {
///
/// `None` disables the cap, and may cause the program to use any
/// amount of memory if the server responds with a long (or
/// infinite) status line. The default is None, so setting this
/// manually is recommended when talking to untrusted servers.
/// infinite) status line. The default is 64 KiB.
pub fn with_max_status_line_length<S: Into<Option<usize>>>(
mut self,
max_status_line_len: S,
Expand All @@ -259,7 +262,10 @@ impl Request {
///
/// `None` disables the cap, and may cause the program to use any
/// amount of memory if the server responds with a large (or
/// infinite) body. The default is None, so setting this
/// infinite) body.
///
/// The default is 1 GiB, which is likely to cause an
/// out-of-memory condition in many cases so setting this
/// manually is recommended when talking to untrusted servers.
pub fn with_max_body_size<S: Into<Option<usize>>>(mut self, max_body_size: S) -> Request {
self.max_body_size = max_body_size.into();
Expand Down