Expand description
This module provides methods to create a http/3 Server.
It allows to accept incoming requests, and send responses.
Examples
Simple example
async fn doc<C>(conn: C)
where
C: h3::quic::Connection<bytes::Bytes>,
<C as h3::quic::Connection<bytes::Bytes>>::BidiStream: Send + 'static
{
let mut server_builder = h3::server::builder();
// Build the Connection
let mut h3_conn = server_builder.build(conn).await.unwrap();
loop {
// Accept incoming requests
match h3_conn.accept().await {
Ok(Some((req, mut stream))) => {
// spawn a new task to handle the request
tokio::spawn(async move {
// build a http response
let response = http::Response::builder().status(http::StatusCode::OK).body(()).unwrap();
// send the response to the wire
stream.send_response(response).await.unwrap();
// send some date
stream.send_data(bytes::Bytes::from("test")).await.unwrap();
// finnish the stream
stream.finish().await.unwrap();
});
}
Ok(None) => {
// break if no Request is accepted
break;
}
Err(err) => {
match err.get_error_level() {
// break on connection errors
h3::error::ErrorLevel::ConnectionError => break,
// continue on stream errors
h3::error::ErrorLevel::StreamError => continue,
}
}
}
}
}
File server
A ready-to-use example of a file server is available here
Structs
- Builder of HTTP/3 server connections.
- Server connection driver
- Manage request and response transfer for an incoming request
Functions
- Create a builder of HTTP/3 server connections