Skip to main content

ServerEvent

Enum ServerEvent 

Source
#[non_exhaustive]
pub enum ServerEvent<'a> { Request(RequestHead<'a>), Body(&'a [u8]), RequestEnd, NeedInput, AwaitingResponse, Upgraded, Closed, }
Expand description

What a ServerConn has for the caller after poll.

§Examples

use http_net::{Response, ServerConn, ServerEvent};

let mut conn = ServerConn::new();
let mut out = Vec::new();
let _ = conn.feed(b"POST /echo HTTP/1.1\r\nHost: a\r\nContent-Length: 2\r\n\r\nhi");
let mut body = Vec::new();
loop {
    match conn.poll().unwrap() {
        ServerEvent::Request(req) => assert_eq!(req.path(), "/echo"),
        ServerEvent::Body(chunk) => body.extend_from_slice(chunk),
        ServerEvent::RequestEnd => {
            conn.respond(&Response::new(200).body(body.clone()), &mut out).unwrap();
        }
        ServerEvent::NeedInput => break,
        other => panic!("{other:?}"),
    }
}
assert!(out.ends_with(b"\r\n\r\nhi"));

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

Request(RequestHead<'a>)

A request head arrived. Its body (if any) follows as Body events, then RequestEnd. A response may be sent from this point on; sending it while body bytes are still unread closes the connection afterwards (a request without a body stays keep-alive). If the head expects_continue, answer with send_continue or a final response before waiting for the body.

§

Body(&'a [u8])

A run of body bytes, after chunked decoding.

§

RequestEnd

The request is complete. Send the response if it has not been sent.

§

NeedInput

More input is needed: read from the socket, then feed (or read_buf and commit), or feed_eof if the peer closed.

§

AwaitingResponse

The request is complete and its response has not been finished yet. Pipelined requests wait in the buffer until it is.

§

Upgraded

A 101 Switching Protocols (or a 2xx to CONNECT) was sent: the connection now belongs to the new protocol. Bytes that already arrived for it are in remaining_input.

§

Closed

The connection is finished: flush any output, then close the socket.

Trait Implementations§

Source§

impl<'a> Debug for ServerEvent<'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 ServerEvent<'a>

§

impl<'a> RefUnwindSafe for ServerEvent<'a>

§

impl<'a> Send for ServerEvent<'a>

§

impl<'a> Sync for ServerEvent<'a>

§

impl<'a> Unpin for ServerEvent<'a>

§

impl<'a> UnsafeUnpin for ServerEvent<'a>

§

impl<'a> UnwindSafe for ServerEvent<'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.