Skip to content
Permalink
Browse files

Upgrade to hyper 0.12:

- Use hyper's MakeService implementation with futures API
- Use tokio runtime to serve HTTP backend
  • Loading branch information...
schrieveslaach committed May 19, 2019
1 parent e9c125f commit 751903ea8b5c3f991071affb7842faf097a7e95f
@@ -22,7 +22,9 @@ private-cookies = ["cookie/secure"]
[dependencies]
smallvec = "0.6"
percent-encoding = "1"
hyper = { version = "0.10.13", default-features = false }
hyper = { version = "0.12.31", default-features = false, features = ["tokio"] }
http = "0.1.17"
mime = "0.3.13"
time = "0.1"
indexmap = "1.0"
rustls = { version = "0.15", optional = true }
@@ -6,7 +6,7 @@ use std::fmt;
use crate::header::Header;
use crate::media_type::{MediaType, Source};
use crate::ext::IntoCollection;
use crate::hyper::mime::Mime;
use mime::Mime;

/// Representation of HTTP Content-Types.
///
@@ -281,11 +281,11 @@ impl From<Mime> for ContentType {
#[inline]
fn from(mime: Mime) -> ContentType {
// soooo inefficient.
let params = mime.2.into_iter()
let params = mime.params().into_iter()
.map(|(attr, value)| (attr.to_string(), value.to_string()))
.collect::<Vec<_>>();

ContentType::with_params(mime.0.to_string(), mime.1.to_string(), params)
ContentType::with_params(mime.type_().to_string(), mime.subtype().to_string(), params)
}
}

@@ -4,74 +4,66 @@
//! These types will, with certainty, be removed with time, but they reside here
//! while necessary.

#[doc(hidden)] pub use hyper::server::Request as Request;
#[doc(hidden)] pub use hyper::server::Response as Response;
#[doc(hidden)] pub use hyper::server::Server as Server;
#[doc(hidden)] pub use hyper::server::Handler as Handler;

#[doc(hidden)] pub use hyper::net;

#[doc(hidden)] pub use hyper::method::Method;
#[doc(hidden)] pub use hyper::status::StatusCode;
#[doc(hidden)] pub use hyper::{Body, Request, Response};
#[doc(hidden)] pub use hyper::body::Payload as Payload;
#[doc(hidden)] pub use hyper::error::Error;
#[doc(hidden)] pub use hyper::uri::RequestUri;
#[doc(hidden)] pub use hyper::http::h1;
#[doc(hidden)] pub use hyper::buffer;
#[doc(hidden)] pub use hyper::server::Server;
#[doc(hidden)] pub use hyper::service::{MakeService, Service};

pub use hyper::mime;
#[doc(hidden)] pub use hyper::Chunk;
#[doc(hidden)] pub use http::header::HeaderName as HeaderName;
#[doc(hidden)] pub use http::header::HeaderValue as HeaderValue;
#[doc(hidden)] pub use http::method::Method;
#[doc(hidden)] pub use http::request::Parts;
#[doc(hidden)] pub use http::status::StatusCode;
#[doc(hidden)] pub use http::uri::Uri;

/// Type alias to `hyper::Response<'a, hyper::net::Fresh>`.
#[doc(hidden)] pub type FreshResponse<'a> = self::Response<'a, self::net::Fresh>;
// TODO #[doc(hidden)] pub type FreshResponse<'a> = self::Response<'a, self::net::Fresh>;

/// Reexported Hyper header types.
pub mod header {
use crate::Header;

use hyper::header::Header as HyperHeaderTrait;

macro_rules! import_hyper_items {
($($item:ident),*) => ($(pub use hyper::header::$item;)*)
}

macro_rules! import_hyper_headers {
($($name:ident),*) => ($(
impl std::convert::From<self::$name> for Header<'static> {
fn from(header: self::$name) -> Header<'static> {
Header::new($name::header_name(), header.to_string())
}
}
pub use http::header::$name as $name;
)*)
}

import_hyper_items! {
Accept, AcceptCharset, AcceptEncoding, AcceptLanguage, AcceptRanges,
AccessControlAllowCredentials, AccessControlAllowHeaders,
AccessControlAllowMethods, AccessControlExposeHeaders,
AccessControlMaxAge, AccessControlRequestHeaders,
AccessControlRequestMethod, Allow, Authorization, Basic, Bearer,
CacheControl, Connection, ContentDisposition, ContentEncoding,
ContentLanguage, ContentLength, ContentRange, ContentType, Date, ETag,
EntityTag, Expires, From, Headers, Host, HttpDate, IfModifiedSince,
IfUnmodifiedSince, LastModified, Location, Origin, Prefer,
PreferenceApplied, Protocol, Quality, QualityItem, Referer,
StrictTransportSecurity, TransferEncoding, Upgrade, UserAgent,
AccessControlAllowOrigin, ByteRangeSpec, CacheDirective, Charset,
ConnectionOption, ContentRangeSpec, DispositionParam, DispositionType,
Encoding, Expect, IfMatch, IfNoneMatch, IfRange, Pragma, Preference,
ProtocolName, Range, RangeUnit, ReferrerPolicy, Vary, Scheme, q, qitem
}

// import_hyper_items! {
// Accept, AcceptCharset, AcceptEncoding, AcceptLanguage, AcceptRanges,
// AccessControlAllowCredentials, AccessControlAllowHeaders,
// AccessControlAllowMethods, AccessControlExposeHeaders,
// AccessControlMaxAge, AccessControlRequestHeaders,
// AccessControlRequestMethod, Allow, Authorization, Basic, Bearer,
// CacheControl, Connection, ContentDisposition, ContentEncoding,
// ContentLanguage, ContentLength, ContentRange, ContentType, Date, ETag,
// EntityTag, Expires, From, Headers, Host, HttpDate, IfModifiedSince,
// IfUnmodifiedSince, LastModified, Location, Origin, Prefer,
// PreferenceApplied, Protocol, Quality, QualityItem, Referer,
// StrictTransportSecurity, TransferEncoding, Upgrade, UserAgent,
// AccessControlAllowOrigin, ByteRangeSpec, CacheDirective, Charset,
// ConnectionOption, ContentRangeSpec, DispositionParam, DispositionType,
// Encoding, Expect, IfMatch, IfNoneMatch, IfRange, Pragma, Preference,
// ProtocolName, Range, RangeUnit, ReferrerPolicy, Vary, Scheme, q, qitem
// }
//
import_hyper_headers! {
Accept, AccessControlAllowCredentials, AccessControlAllowHeaders,
AccessControlAllowMethods, AccessControlAllowOrigin,
AccessControlExposeHeaders, AccessControlMaxAge,
AccessControlRequestHeaders, AccessControlRequestMethod, AcceptCharset,
AcceptEncoding, AcceptLanguage, AcceptRanges, Allow, CacheControl,
Connection, ContentDisposition, ContentEncoding, ContentLanguage,
ContentLength, ContentRange, Date, ETag, Expect, Expires, Host, IfMatch,
IfModifiedSince, IfNoneMatch, IfRange, IfUnmodifiedSince, LastModified,
Location, Origin, Pragma, Prefer, PreferenceApplied, Range, Referer,
ReferrerPolicy, StrictTransportSecurity, TransferEncoding, Upgrade,
UserAgent, Vary
ACCEPT, ACCESS_CONTROL_ALLOW_CREDENTIALS, ACCESS_CONTROL_ALLOW_HEADERS,
ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN,
ACCESS_CONTROL_EXPOSE_HEADERS, ACCESS_CONTROL_MAX_AGE,
ACCESS_CONTROL_REQUEST_HEADERS, ACCESS_CONTROL_REQUEST_METHOD, ACCEPT_CHARSET,
ACCEPT_ENCODING, ACCEPT_LANGUAGE, ACCEPT_RANGES, ALLOW, CACHE_CONTROL,
CONNECTION, CONTENT_DISPOSITION, CONTENT_ENCODING, CONTENT_LANGUAGE,
CONTENT_LENGTH, CONTENT_RANGE, DATE, ETAG, EXPECT, EXPIRES, HOST, IF_MATCH,
IF_MODIFIED_SINCE, IF_NONE_MATCH, IF_RANGE, IF_UNMODIFIED_SINCE, LAST_MODIFIED,
LOCATION, ORIGIN, PRAGMA, RANGE, REFERER,
REFERRER_POLICY, STRICT_TRANSPORT_SECURITY, TRANSFER_ENCODING, UPGRADE,
USER_AGENT, VARY
}
}
@@ -1,3 +1,5 @@
extern crate http;

use std::fmt;
use std::str::FromStr;

@@ -24,18 +26,18 @@ pub enum Method {
impl Method {
/// WARNING: This is unstable! Do not use this method outside of Rocket!
#[doc(hidden)]
pub fn from_hyp(method: &hyper::Method) -> Option<Method> {
pub fn from_hyp(method: &http::method::Method) -> Option<Method> {
match *method {
hyper::Method::Get => Some(Get),
hyper::Method::Put => Some(Put),
hyper::Method::Post => Some(Post),
hyper::Method::Delete => Some(Delete),
hyper::Method::Options => Some(Options),
hyper::Method::Head => Some(Head),
hyper::Method::Trace => Some(Trace),
hyper::Method::Connect => Some(Connect),
hyper::Method::Patch => Some(Patch),
hyper::Method::Extension(_) => None,
http::method::Method::GET => Some(Get),
http::method::Method::PUT => Some(Put),
http::method::Method::POST => Some(Post),
http::method::Method::DELETE => Some(Delete),
http::method::Method::OPTIONS => Some(Options),
http::method::Method::HEAD => Some(Head),
http::method::Method::TRACE => Some(Trace),
http::method::Method::CONNECT => Some(Connect),
http::method::Method::PATCH => Some(Patch),
_ => None,
}
}

@@ -94,6 +94,20 @@ impl<'a> Uri<'a> {
crate::parse::uri::from_str(string)
}

// pub fn from_hyp(uri: &'a hyper::Uri) -> Uri<'a> {
// match uri.is_absolute() {
// true => Uri::Absolute(Absolute::new(
// uri.scheme().unwrap(),
// match uri.host() {
// Some(host) => Some(Authority::new(None, Host::Raw(host), uri.port())),
// None => None
// },
// None
// )),
// false => Uri::Asterisk
// }
// }

/// Returns the internal instance of `Origin` if `self` is a `Uri::Origin`.
/// Otherwise, returns `None`.
///
@@ -24,8 +24,10 @@ tls = ["rocket_http/tls"]
private-cookies = ["rocket_http/private-cookies"]

[dependencies]
futures = "0.1"
rocket_codegen = { version = "0.5.0-dev", path = "../codegen" }
rocket_http = { version = "0.5.0-dev", path = "../http" }
tokio = "0.1.16"
yansi = "0.5"
log = "0.4"
toml = "0.4.7"
@@ -59,6 +59,7 @@ use yansi::Color::*;
///
/// A function decorated with `catch` must take exactly zero or one arguments.
/// If the catcher takes an argument, it must be of type [`&Request`](Request).
#[derive(Clone)]
pub struct Catcher {
/// The HTTP status code to match against.
pub code: u16,

0 comments on commit 751903e

Please sign in to comment.
You can’t perform that action at this time.