Module hyper::upgrade

source ·
Expand description

HTTP Upgrades

This module deals with managing HTTP Upgrades in hyper. Since several concepts in HTTP allow for first talking HTTP, and then converting to a different protocol, this module conflates them into a single API. Those include:

  • HTTP/1.1 Upgrades
  • HTTP CONNECT

You are responsible for any other pre-requisites to establish an upgrade, such as sending the appropriate headers, methods, and status codes. You can then use on to grab a Future which will resolve to the upgraded connection object, or an error if the upgrade fails.

Client

Sending an HTTP upgrade from the client involves setting either the appropriate method, if wanting to CONNECT, or headers such as Upgrade and Connection, on the http::Request. Once receiving the http::Response back, you must check for the specific information that the upgrade is agreed upon by the server (such as a 101 status code), and then get the Future from the Response.

Server

Receiving upgrade requests in a server requires you to check the relevant headers in a Request, and if an upgrade should be done, you then send the corresponding headers in a response. To then wait for hyper to finish the upgrade, you call on() with the Request, and then can spawn a task awaiting it.

Example

See this example showing how upgrades work with both Clients and Servers.

Structs

Functions

  • Gets a pending HTTP upgrade from this message.