packages

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

  • body Message bodies: a stream of byte chunks over a channel.
  • client The client: connection pool, HTTP/1.1 keep-alive, HTTP/2 over TLS (ALPN) or by prior knowledge, redirects, timeouts.
  • cookie Cookies (RFC 6265): the Cookie request header and Set-Cookie.
  • error The one error type of the package.
  • h1 HTTP/1.1 message syntax (RFC 9112): strict head parsing, body framing, chunked coding, serialization.
  • h2 HTTP/2 (RFC 9113) over TLS (ALPN "h2") or a plaintext connection with prior knowledge (h2c).
  • headers Header fields (RFC 9110): a case-insensitive multimap that keeps insertion order.
  • message Requests and responses.
  • method Request methods (RFC 9110).
  • server The 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.
  • status Status codes (RFC 9110).
  • uri URIs (RFC 3986): parsing, normalization, reference resolution, percent-encoding and application/x-www-form-urlencoded.

Re-exports

body::{Body, BodyWriter}Source

pub use body::{Body, BodyWriter}
  • Body A message body: a stream of byte chunks read once with chunk, bytes or text.
  • BodyWriter The feeding end of Body::channel.

client::{Client, ClientConfig, get}Source

pub use client::{Client, ClientConfig, get}

error::{HttpError, ErrorKind}Source

pub use error::{HttpError, ErrorKind}
  • HttpError An HTTP failure: its kind, a message and, for HTTP/2 errors, the RFC 9113 error code (0 otherwise).
  • ErrorKind What went wrong.

headers::HeaderMapSource

pub use headers::HeaderMap

message::{Request, Response, Version}Source

pub use message::{Request, Response, Version}

method::MethodSource

pub use method::Method

server::serve_tlsSource

pub use server::serve_tls

server::{Server, ServerConfig, Handler, serve}Source

pub use server::{Server, ServerConfig, Handler, serve}
  • Server A bound server.
  • ServerConfig Server settings.
  • Handler The request handler: one call per request, each in its own task.
  • serve Serve handler on addr ("127.0.0.1:8080") until the process ends.

status::StatusCodeSource

pub use status::StatusCode

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}
  • Uri A URI reference.
  • percent_encode s with every byte that is not unreserved and not in keep as a %XX escape (UTF-8 bytes each escaped).
  • percent_decode The text s encodes; throws on a malformed escape or invalid UTF-8.
  • percent_decode_bytes The bytes s encodes; throws on a malformed escape.
  • form_encode application/x-www-form-urlencoded (WHATWG URL): a=1&b=x+y.
  • form_decode Decode 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

  • pub fn new(s: TcpStream) -> Io§

    Source
  • pub fn split(self) throws (HttpError) -> Io§

    Source

    A second Io on 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.

  • pub fn buffered(self) -> usize§

    Source

    Number of unread bytes.

  • pub fn peek(self) -> Slice<u8>§

    Source

    The unread bytes (a view; valid until the next fill).

  • pub fn consume(self, n: usize)§

    Source

    Mark n unread bytes read.

  • pub fn take(self, n: usize) -> List<u8>§

    Source

    The next n unread bytes (there must be that many).

  • pub async fn fill(self, deadline: Instant | none) throws (HttpError) -> bool§

    Source

    Read more from the socket; false at end of stream.

  • pub async fn need(self, n: usize, deadline: Instant | none) throws (HttpError)§

    Source

    Fill until n bytes are unread; throws Closed at end of stream.

  • pub async fn write(self, data: Slice<u8>, deadline: Instant | none) throws (HttpError)§

    Source
  • pub fn shutdown(self)§

    Source

    Stop both directions: pending reads end. TLS sends close_notify.

  • pub fn shutdown_write(self)§

    Source

    Stop sending (FIN); reading goes on. TLS: as shutdown.

  • pub async fn drain(self, deadline: Instant | none)§

    Source

    Read and drop what the peer still sends, until its end or deadline.

  • pub fn release(self)§

    Source

    Close this handle only: another Io on the connection (split) keeps it open. TLS: as close.

  • pub fn close(self)§

    Source

    End the connection; TLS sends close_notify first.

impl Tx

  • pub fn new(s: Sender<T>) -> Tx<T>§

    Source
  • pub fn send(self, v: T) -> bool§

    Source

    Queue v; false once closed.

  • pub fn sender(self) -> Sender<T> | none§

    Source

    A sender of its own on the channel, unless closed.

  • pub fn close(self)§

    Source