http
On this page
HTTP/1.1 (RFC 9110 / 9112) and HTTP/2 (RFC 9113, HPACK RFC 7541):
the message model, clients and servers on std::net.
Modules
bodyMessage bodies: a stream of byte chunks over a channel.clientThe client: connection pool, HTTP/1.1 keep-alive, HTTP/2 over TLS (ALPN) or by prior knowledge, redirects, timeouts.cookieCookies (RFC 6265): theCookierequest header andSet-Cookie.errorThe one error type of the package.h1HTTP/1.1 message syntax (RFC 9112): strict head parsing, body framing, chunked coding, serialization.h2HTTP/2 (RFC 9113) over TLS (ALPN "h2") or a plaintext connection with prior knowledge (h2c).headersHeader fields (RFC 9110): a case-insensitive multimap that keeps insertion order.messageRequests and responses.methodRequest methods (RFC 9110).serverThe server: an accept loop, a task per connection, HTTP/1.1 with keep-alive and pipelining, HTTP/2 over TLS (ALPN) or by prior knowledge (h2c), graceful shutdown.statusStatus codes (RFC 9110).uriURIs (RFC 3986): parsing, normalization, reference resolution, percent-encoding andapplication/x-www-form-urlencoded.
Re-exports
body::{Body, BodyWriter}Source
pub use body::{Body, BodyWriter}BodyA message body: a stream of byte chunks read once withchunk,bytesortext.BodyWriterThe feeding end ofBody::channel.
client::{Client, ClientConfig, get}Source
pub use client::{Client, ClientConfig, get}ClientAn HTTP client.ClientConfigClient settings.getGETurlwith a default client.
cookie::{SetCookie, parse_cookie_header, cookie_header}Source
pub use cookie::{SetCookie, parse_cookie_header, cookie_header}SetCookieASet-Cookieheader.
error::{HttpError, ErrorKind}Source
pub use error::{HttpError, ErrorKind}headers::HeaderMapSource
pub use headers::HeaderMapHeaderMapHeader fields in order.
message::{Request, Response, Version}Source
pub use message::{Request, Response, Version}method::MethodSource
pub use method::MethodMethodA request method.
server::serve_tlsSource
pub use server::serve_tlsserver::{Server, ServerConfig, Handler, serve}Source
pub use server::{Server, ServerConfig, Handler, serve}ServerA bound server.ServerConfigServer settings.HandlerThe request handler: one call per request, each in its own task.serveServehandleronaddr("127.0.0.1:8080") until the process ends.
status::StatusCodeSource
pub use status::StatusCodeStatusCodeA three-digit status code,100..=999.
uri::{Uri, percent_encode, percent_decode, percent_decode_bytes, form_encode, form_decode}Source
pub use uri::{Uri, percent_encode, percent_decode, percent_decode_bytes, form_encode, form_decode}UriA URI reference.percent_encodeswith every byte that is not unreserved and not inkeepas a%XXescape (UTF-8 bytes each escaped).percent_decodeThe textsencodes; throws on a malformed escape or invalid UTF-8.percent_decode_bytesThe bytessencodes; throws on a malformed escape.form_encodeapplication/x-www-form-urlencoded(WHATWG URL):a=1&b=x+y.form_decodeDecode a form body / query leniently as browsers do: empty pieces skipped,+is a space, a malformed escape stays as written, invalid UTF-8 becomes U+FFFD.
Implementations
impl Io
A second
Ioon the same connection with its own (empty) read buffer, for writing from another task. Each is closed by its owner; closing either ends the connection.Number of unread bytes.
The unread bytes (a view; valid until the next
fill).Mark
nunread bytes read.The next
nunread bytes (there must be that many).Read more from the socket;
falseat end of stream.Fill until
nbytes are unread; throwsClosedat end of stream.Stop both directions: pending reads end. TLS sends close_notify.
Stop sending (FIN); reading goes on. TLS: as
shutdown.Read and drop what the peer still sends, until its end or
deadline.Close this handle only: another
Ioon the connection (split) keeps it open. TLS: asclose.End the connection; TLS sends close_notify first.
impl Tx
Queue
v;falseonce closed.A sender of its own on the channel, unless closed.
impl Link
End the connection (close_notify, then the socket closes).
Another end on the same connection.
The next plaintext, or
End/Failed.