#[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
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.