blob: 484d7352130bc3fd4a62885435c5ab2084613e30 [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="An asynchronous, HTTP/2 server and client implementation."><meta name="keywords" content="rust, rustlang, rust-lang, h2"><title>h2 - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../h2/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../h2/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate h2</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.3.19</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">h2</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/h2/lib.rs.html#1-136">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An asynchronous, HTTP/2 server and client implementation.</p>
<p>This library implements the <a href="https://http2.github.io/">HTTP/2</a> specification. The implementation is
asynchronous, using <a href="https://docs.rs/futures/">futures</a> as the basis for the API. The implementation
is also decoupled from TCP or TLS details. The user must handle ALPN and
HTTP/1.1 upgrades themselves.</p>
<h2 id="getting-started"><a href="#getting-started">Getting started</a></h2>
<p>Add the following to your <code>Cargo.toml</code> file:</p>
<div class="example-wrap"><pre class="language-toml"><code>[dependencies]
h2 = &quot;0.3&quot;</code></pre></div><h2 id="layout-1"><a href="#layout-1">Layout</a></h2>
<p>The crate is split into <a href="client/index.html"><code>client</code></a> and <a href="server/index.html"><code>server</code></a> modules. Types that are
common to both clients and servers are located at the root of the crate.</p>
<p>See module level documentation for more details on how to use <code>h2</code>.</p>
<h2 id="handshake"><a href="#handshake">Handshake</a></h2>
<p>Both the client and the server require a connection to already be in a state
ready to start the HTTP/2 handshake. This library does not provide
facilities to do this.</p>
<p>There are three ways to reach an appropriate state to start the HTTP/2
handshake.</p>
<ul>
<li>Opening an HTTP/1.1 connection and performing an <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism">upgrade</a>.</li>
<li>Opening a connection with TLS and use ALPN to negotiate the protocol.</li>
<li>Open a connection with prior knowledge, i.e. both the client and the
server assume that the connection is immediately ready to start the
HTTP/2 handshake once opened.</li>
</ul>
<p>Once the connection is ready to start the HTTP/2 handshake, it can be
passed to <a href="server/fn.handshake.html"><code>server::handshake</code></a> or <a href="client/fn.handshake.html"><code>client::handshake</code></a>. At this point, the
library will start the handshake process, which consists of:</p>
<ul>
<li>The client sends the connection preface (a predefined sequence of 24
octets).</li>
<li>Both the client and the server sending a SETTINGS frame.</li>
</ul>
<p>See the <a href="http://httpwg.org/specs/rfc7540.html#starting">Starting HTTP/2</a> in the specification for more details.</p>
<h2 id="flow-control"><a href="#flow-control">Flow control</a></h2>
<p><a href="http://httpwg.org/specs/rfc7540.html#FlowControl">Flow control</a> is a fundamental feature of HTTP/2. The <code>h2</code> library
exposes flow control to the user.</p>
<p>An HTTP/2 client or server may not send unlimited data to the peer. When a
stream is initiated, both the client and the server are provided with an
initial window size for that stream. A window size is the number of bytes
the endpoint can send to the peer. At any point in time, the peer may
increase this window size by sending a <code>WINDOW_UPDATE</code> frame. Once a client
or server has sent data filling the window for a stream, no further data may
be sent on that stream until the peer increases the window.</p>
<p>There is also a <strong>connection level</strong> window governing data sent across all
streams.</p>
<p>Managing flow control for inbound data is done through <a href="struct.FlowControl.html"><code>FlowControl</code></a>.
Managing flow control for outbound data is done through <a href="struct.SendStream.html"><code>SendStream</code></a>. See
the struct level documentation for those two types for more details.</p>
</div></details><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="mod" href="client/index.html" title="h2::client mod">client</a></div><div class="item-right docblock-short">Client implementation of the HTTP/2 protocol.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="ext/index.html" title="h2::ext mod">ext</a></div><div class="item-right docblock-short">Extensions specific to the HTTP/2 protocol.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="server/index.html" title="h2::server mod">server</a></div><div class="item-right docblock-short">Server implementation of the HTTP/2 protocol.</div></div></div><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Error.html" title="h2::Error struct">Error</a></div><div class="item-right docblock-short">Represents HTTP/2 operation errors.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.FlowControl.html" title="h2::FlowControl struct">FlowControl</a></div><div class="item-right docblock-short">A handle to release window capacity to a remote stream.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Ping.html" title="h2::Ping struct">Ping</a></div><div class="item-right docblock-short">Sent via <a href="struct.PingPong.html"><code>PingPong</code></a> to send a PING frame to a peer.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.PingPong.html" title="h2::PingPong struct">PingPong</a></div><div class="item-right docblock-short">A handle to send and receive PING frames with the peer.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Pong.html" title="h2::Pong struct">Pong</a></div><div class="item-right docblock-short">Received via <a href="struct.PingPong.html"><code>PingPong</code></a> when a peer acknowledges a <a href="struct.Ping.html"><code>Ping</code></a>.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Reason.html" title="h2::Reason struct">Reason</a></div><div class="item-right docblock-short">HTTP/2 error codes.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.RecvStream.html" title="h2::RecvStream struct">RecvStream</a></div><div class="item-right docblock-short">Receives the body stream and trailers from the remote peer.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.SendStream.html" title="h2::SendStream struct">SendStream</a></div><div class="item-right docblock-short">Sends the body stream and trailers to the remote peer.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.StreamId.html" title="h2::StreamId struct">StreamId</a></div><div class="item-right docblock-short">A stream identifier, as described in <a href="https://tools.ietf.org/html/rfc7540#section-5.1.1">Section 5.1.1</a> of RFC 7540.</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="h2" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>