Skip to main content

DecompressionSupport

Enum DecompressionSupport 

Source
pub enum DecompressionSupport {
    None,
    Internal,
}
Expand description

Whether the transport hands back a response body it has already decoded, or the bytes exactly as the server put them on the wire.

The question a caller asks of this is “must I reverse a Content-Encoding myself, and may I ask for one?” — both halves at once, because they are one fact about the transport. hclient’s Client is that caller: it reads this field and nothing else to decide whether to advertise Accept-Encoding and whether to decode.

§Why this is NOT read off forbidden_request_headers

hclient-fetch lists http::header::ACCEPT_ENCODING among its forbidden request headers, and it also decompresses internally, so on that one backend the two answers coincide — which is exactly what makes deriving one from the other tempting and wrong. “This header cannot be sent” and “the body reaching you is already decoded” are different claims: a transport that forbids the header while decompressing nothing is perfectly coherent (a proxy-shaped backend that pins its own Accept-Encoding, say), and a client that inferred “already decoded” from “header forbidden” would hand that caller compressed bytes labelled as plaintext. That is the “capability that lies” defect this workspace has caught four times, which is why this is its own field.

The reverse inference is just as wrong and is the one Client implements: a None transport that forbids Accept-Encoding gets no header from us and still gets its response decoded, because a Content-Encoding the server applied unbidden is still ours to reverse.

§Why two variants and not three

CancelSupport’s rule, applied a third time: a variant exists only if a caller decision turns on it. The third variant that suggests itself is “the transport can decompress, if asked” — configurable rather than automatic. No transport in this workspace or outside it works that way today, and there is no client-level setting for it to answer: Client does not offer “decompress, but at the transport layer”. A variant no caller can branch on is a distinction the capability set carries forever for nothing.

The condition under which it arrives, on RedirectSupport::Transparent’s precedent: together with the setting that asks for it and its arm in check_supported, once a backend exists that is being misread without it. Not before.

§Silence and the substantive claim coincide here

Self::None is what Capabilities::default() returns, so “the backend never filled this in” and “the backend hands the bytes over untouched” are the same value — and, as with CancelSupport::None and ReuseSupport::None, that costs nothing, because the two mean the same thing to a caller: decode it yourself. The RedirectSupport problem, where None was a strictly stronger claim than silence and a Transparent backend was misread for lack of a third value, does not arise.

Not #[non_exhaustive], for consistency with every other enum in this file.

Variants§

§

None

The response body arrives exactly as it came off the wire: a Content-Encoding the server applied is still applied, and reversing it belongs to whoever reads the body.

The conservative base — Capabilities::default() returns this — and the honest answer for every transport that moves bytes rather than interpreting them: hclient-native (hyper hands the body through as it arrives) and hclient-wasi (wasi:http 0.3 defines no content-coding behaviour of its own) are both this.

§

Internal

The transport decodes Content-Encoding itself, before a single byte reaches us, and chooses what to ask for — so Accept-Encoding is not ours to set either, and decoding again would corrupt every compressed response.

Named after RedirectSupport::Internal, and for the same shape of reason: the backend does it, we neither control nor see it. The example is again the browser — hclient-fetch reports this, derived from the same in-crate fact its Body::size_hint already rests on (a Content-Length under a Content-Encoding describes bytes this transport never yields, because the browser has already reversed the coding).

Note what this does NOT promise: that the response headers were tidied up afterwards. fetch leaves Content-Encoding and Content-Length on the response describing the wire, not the body you get — which is precisely why the size hint has to distrust them.

Trait Implementations§

Source§

impl Clone for DecompressionSupport

Source§

fn clone(&self) -> DecompressionSupport

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DecompressionSupport

Source§

impl Debug for DecompressionSupport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DecompressionSupport

Source§

fn default() -> DecompressionSupport

Returns the “default value” for a type. Read more
Source§

impl Eq for DecompressionSupport

Source§

impl PartialEq for DecompressionSupport

Source§

fn eq(&self, other: &DecompressionSupport) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DecompressionSupport

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.