Skip to main content

ClientLeniency

Struct ClientLeniency 

Source
#[non_exhaustive]
pub struct ClientLeniency { pub obs_fold_in_responses: bool, }
Expand description

Opt-in tolerances for responses a strict client would refuse. All are off by default; requests are never parsed leniently.

  • obs_fold_in_responses: replace each obsolete line fold in a response head (a field line continued on the next line, which begins with a space or tab) by overwriting the fold’s CR and LF with spaces, as RFC 9112 section 5.2 tells a user agent to do. The rewrite happens in place in the connection’s buffer, so offsets do not move, views stay borrowed, and nothing is allocated. Whitespace before the first field is still refused.

Bare LF, bare CR, Content-Length with Transfer-Encoding, and whitespace before a colon are never tolerated: they are how messages get framed differently by different hops.

§Examples

use http_net::{ClientConn, ClientEvent, ClientLeniency, Request};

let mut conn = ClientConn::new();
conn.set_leniency(ClientLeniency::new().with_obs_fold_in_responses(true));
conn.send_request(&Request::get("/").header("host", "a"), &mut Vec::new())?;
let _ = conn.feed(b"HTTP/1.1 200 OK\r\nX-Long: part one,\r\n part two\r\nContent-Length: 0\r\n\r\n");
let ClientEvent::Response(resp) = conn.poll()? else { panic!() };
assert_eq!(resp.header("x-long"), Some(&b"part one,   part two"[..]));

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§obs_fold_in_responses: bool

Replace obs-folds in response fields with spaces instead of refusing them with HttpError::ObsFold.

Implementations§

Source§

impl ClientLeniency

Source

pub const fn new() -> Self

Every tolerance off (the strict default).

§Examples
assert!(!http_net::ClientLeniency::new().obs_fold_in_responses);
Source

pub const fn with_obs_fold_in_responses(self, on: bool) -> Self

Sets obs_fold_in_responses.

§Examples
let l = http_net::ClientLeniency::new().with_obs_fold_in_responses(true);
assert!(l.obs_fold_in_responses);

Trait Implementations§

Source§

impl Clone for ClientLeniency

Source§

fn clone(&self) -> Self

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 ClientLeniency

Source§

impl Debug for ClientLeniency

Source§

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

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

impl Default for ClientLeniency

Source§

fn default() -> Self

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

impl Eq for ClientLeniency

Source§

impl Hash for ClientLeniency

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ClientLeniency

Source§

fn eq(&self, other: &Self) -> 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 ClientLeniency

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.