Skip to main content

ClientEvent

Enum ClientEvent 

Source
#[non_exhaustive]
pub enum ClientEvent<'a> { Response(ResponseHead<'a>), Informational(ResponseHead<'a>), Continue, Body(&'a [u8]), Trailers(Headers<'a>), ResponseEnd, NeedInput, Idle, Upgraded, Closed, }
Expand description

What a ClientConn has for the caller after poll.

§Examples

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

let mut conn = ClientConn::new();
let mut out = Vec::new();
conn.send_request(&Request::get("/").header("host", "example.com"), &mut out).unwrap();
let _ = conn.feed(b"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n3\r\nabc\r\n0\r\n\r\n");
let mut body = Vec::new();
loop {
    match conn.poll().unwrap() {
        ClientEvent::Response(resp) => assert_eq!(resp.status(), 200),
        ClientEvent::Body(chunk) => body.extend_from_slice(chunk),
        ClientEvent::ResponseEnd => break,
        other => panic!("{other:?}"),
    }
}
assert_eq!(body, b"abc");

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Response(ResponseHead<'a>)

The final response head arrived. Its body follows as Body events, then ResponseEnd. Interim (1xx) responses before it are skipped unless set_report_informational asked for them; either way they count against Limits::max_interim and, together, Limits::max_header_bytes.

§

Informational(ResponseHead<'a>)

An interim response other than 101 (for example 103 Early Hints, or 102 Processing), only with set_report_informational(true). The final response follows.

§

Continue

The server answered 100 Continue to a request built with Request::expect_continue: send the body now.

§

Body(&'a [u8])

A run of body bytes, after chunked decoding.

§

Trailers(Headers<'a>)

The response’s trailer fields, just before ResponseEnd: only with set_report_trailers(true) and a non-empty trailer section.

§

ResponseEnd

The response is complete.

§

NeedInput

More input is needed (or, for a body that runs until close, feed_eof once the server closes).

§

Idle

No request is outstanding; send the next one.

§

Upgraded

The server switched protocols (101 to an upgrade request, or 2xx to CONNECT); the response head was reported just before. Bytes of the new protocol that already arrived are in remaining_input.

§

Closed

The connection cannot carry another request: close the socket.

Trait Implementations§

Source§

impl<'a> Debug for ClientEvent<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ClientEvent<'a>

§

impl<'a> RefUnwindSafe for ClientEvent<'a>

§

impl<'a> Send for ClientEvent<'a>

§

impl<'a> Sync for ClientEvent<'a>

§

impl<'a> Unpin for ClientEvent<'a>

§

impl<'a> UnsafeUnpin for ClientEvent<'a>

§

impl<'a> UnwindSafe for ClientEvent<'a>

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> 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, 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.