Skip to content

Commit 304d987

Browse files
committed
setting default auto_decode to true
1 parent ce00d7f commit 304d987

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3737
- `RequestBody`'s `bytes` field is private; use `RequestBody::as_bytes()`.
3838
`len()` now returns `Option<u64>` (`None` for a stream without a declared
3939
length).
40+
- `FetchRequest::builder()` now defaults to `auto_decode: true`, matching the
41+
simple API and the wasm32 build. Use `.with_auto_decode(false)` for raw bytes.
42+
- With decoding on, `max_bytes` caps the decompressed size, and the early
43+
`Content-Length` rejection no longer applies (reqwest strips the header
44+
when it decodes).
4045

4146
### Fixed
4247

src/net/types.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl FetchRequest {
458458

459459
/// Builder for [`FetchRequest`], created via [`FetchRequest::builder`].
460460
///
461-
/// All settings are optional; `build()` produces a buffered, non-decoding request
461+
/// All settings are optional; `build()` produces a buffered, decoding request
462462
/// with [`Priority::Normal`] unless configured otherwise.
463463
pub struct FetchRequestBuilder {
464464
reference: RequestReference,
@@ -488,7 +488,7 @@ impl FetchRequestBuilder {
488488
initiator: Initiator::default(),
489489
kind: ResourceKind::default(),
490490
streaming: false,
491-
auto_decode: false,
491+
auto_decode: true,
492492
max_bytes: None,
493493
body: None,
494494
}
@@ -530,7 +530,10 @@ impl FetchRequestBuilder {
530530
self
531531
}
532532

533-
/// Sets whether to transparently decode compressed responses (default: false)
533+
/// Sets whether to transparently decode compressed responses (default: true).
534+
///
535+
/// With decoding on, [`with_max_bytes`](Self::with_max_bytes) caps the decompressed
536+
/// size; set `false` to cap bytes as they arrive on the wire.
534537
pub fn with_auto_decode(mut self, auto_decode: bool) -> Self {
535538
self.auto_decode = auto_decode;
536539
self
@@ -679,6 +682,13 @@ mod tests {
679682
assert_eq!(buffered.as_bytes().map(|b| b.len()), Some(3));
680683
}
681684

685+
#[test]
686+
fn builder_decodes_by_default() {
687+
let fr =
688+
FetchRequest::builder(Method::GET, Url::parse("https://example.org").unwrap()).build();
689+
assert!(fr.auto_decode);
690+
}
691+
682692
#[test]
683693
fn fetch_request_generate_get_and_headers() {
684694
let mut fr = FetchRequest::builder(

0 commit comments

Comments
 (0)