Skip to content

Move HTTP upgrades API off the Body type #2086

Closed
@seanmonstar

Description

@seanmonstar

Introduced in #1563, the HTTP Upgrade/CONNECT API currently is accessed via hyper::Body::on_upgrade. This has some downsides that I'd like to address with a modified API:

  • It makes the Body type fatter.
  • It requires people keep the Body around, meaning they can't use stream combinators to read the body first, and then wait for the upgrade to finish. This also makes it more annoying for users who may wish adjust their http::Request<Body> into some http::Request<Doodad>.

Proposed API

Similar to the proposal in #1586, the change would be to pass the http::Request or http::Response to a free function.

  • hyper::upgrade::on(req_or_resp) -> OnUpgrade
    • We can also allow passing just a mutable reference, thus not consuming the request or response.
  • Optional other functions could be added, but not necessary: has_upgrade, etc.

Implementation Plan

The types would be inserted into the http::Extensions of the request/response (though with a private wrapper type to hide the exact details).

  • Add the new hyper::upgrade::on function.
  • The Body::on_upgrade method would become #[deprecated].
  • So as to not be a behavioral breaking change, the OnUpgrade would need to be placed in both the Body and the Extensions, wrapped in some Arc<Lock> that only allows taking it once.

I'd like to in a future release be able to not put it in an Arc<Lock> and place it in the Body, but I'm not sure how that could really be done in 0.13.x. (I knew I'd find something I forgot to change after finally releasing XD).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-http1Area: HTTP/1 specific.B-breaking-changeBlocked: this is an "API breaking change".C-featureCategory: feature. This is adding a new feature.E-mediumEffort: medium. Some knowledge of how hyper internal works would be useful.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions