Module tsukuyomi::input::upgrade [−][src]
Components for the basic mechanisim for HTTP/1.1 server upgrade.
Examples
fn validate(input: &Input) -> Result<(), Error> { // do some stuff ... } fn on_upgrade(io: Upgraded, cx: UpgradeContext) -> impl Future<Item = (), Error = ()> + Send + 'static { // ... } fn handshake(input: &mut Input) -> Result<Output, Error> { validate(input)?; // Register a callback function called when upgrading // the server protocol. let _ = input.body_mut().on_upgrade(on_upgrade); // Build the handshake response. // If the status code is set to `101 Switching Protocols`, // a task will be generated by calling a callback function // registered at the above section at the end of handling // the request. Response::builder() .status(StatusCode::SWITCHING_PROTOCOLS) .header(header::UPGRADE, "foo") .body(ResponseBody::empty()) .map_err(Error::internal_server_error) }
Structs
UpgradeContext |
Contextual information used at upgrading to another protocol. |
Upgraded |
An upgraded HTTP connection. |
Traits
OnUpgrade |
A trait representing a function called at performing the protocol upgrade. |