Skip to content

Commit dfa0ce9

Browse files
committed
[bitreq] Set a default max-response limit of 1 GiB
Because its very easy to (mis-)use the API and forget to set a response size limit, we really should have a default one. Sadly, its also quite hard to pick a reasonable default here. Rather than being conservative, we pick 1 GiB and hope that this is enough to avoid an OOM, even though its still quite huge, and almost certainly is larger than what people will use `bitreq` for.
1 parent 704fe64 commit dfa0ce9

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

bitreq/src/request.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ impl Request {
123123
max_headers_size: Some(256 * 1024),
124124
// Probably could be 128 bytes, but set conservatively for good measure.
125125
max_status_line_len: Some(64 * 1024),
126-
max_body_size: None,
126+
// Picked somewhat randomly
127+
max_body_size: Some(1024 * 1024 * 1024),
127128
max_redirects: 100,
128129
#[cfg(feature = "proxy")]
129130
proxy: None,
@@ -261,7 +262,10 @@ impl Request {
261262
///
262263
/// `None` disables the cap, and may cause the program to use any
263264
/// amount of memory if the server responds with a large (or
264-
/// infinite) body. The default is None, so setting this
265+
/// infinite) body.
266+
///
267+
/// The default is 1 GiB, which is likely to cause an
268+
/// out-of-memory condition in many cases so setting this
265269
/// manually is recommended when talking to untrusted servers.
266270
pub fn with_max_body_size<S: Into<Option<usize>>>(mut self, max_body_size: S) -> Request {
267271
self.max_body_size = max_body_size.into();

0 commit comments

Comments
 (0)