Skip to content

Commit d175bee

Browse files
schrieveslaachjebrosen
authored andcommitted
Upgrade to hyper 0.12:
- Use hyper's MakeService implementation with futures API - Use tokio runtime to serve HTTP backend
1 parent ed6661a commit d175bee

File tree

17 files changed

+431
-412
lines changed

17 files changed

+431
-412
lines changed

core/http/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ private-cookies = ["cookie/secure"]
2222
[dependencies]
2323
smallvec = "0.6"
2424
percent-encoding = "1"
25-
hyper = { version = "0.10.13", default-features = false }
25+
hyper = { version = "0.12.31", default-features = false, features = ["tokio"] }
26+
http = "0.1.17"
27+
mime = "0.3.13"
2628
time = "0.1"
2729
indexmap = "1.0"
2830
rustls = { version = "0.15", optional = true }

core/http/src/content_type.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::fmt;
66
use crate::header::Header;
77
use crate::media_type::{MediaType, Source};
88
use crate::ext::IntoCollection;
9-
use crate::hyper::mime::Mime;
9+
use mime::Mime;
1010

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

288-
ContentType::with_params(mime.0.to_string(), mime.1.to_string(), params)
288+
ContentType::with_params(mime.type_().to_string(), mime.subtype().to_string(), params)
289289
}
290290
}
291291

core/http/src/hyper.rs

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,66 @@
44
//! These types will, with certainty, be removed with time, but they reside here
55
//! while necessary.
66
7-
#[doc(hidden)] pub use hyper::server::Request as Request;
8-
#[doc(hidden)] pub use hyper::server::Response as Response;
9-
#[doc(hidden)] pub use hyper::server::Server as Server;
10-
#[doc(hidden)] pub use hyper::server::Handler as Handler;
11-
12-
#[doc(hidden)] pub use hyper::net;
13-
14-
#[doc(hidden)] pub use hyper::method::Method;
15-
#[doc(hidden)] pub use hyper::status::StatusCode;
7+
#[doc(hidden)] pub use hyper::{Body, Request, Response};
8+
#[doc(hidden)] pub use hyper::body::Payload as Payload;
169
#[doc(hidden)] pub use hyper::error::Error;
17-
#[doc(hidden)] pub use hyper::uri::RequestUri;
18-
#[doc(hidden)] pub use hyper::http::h1;
19-
#[doc(hidden)] pub use hyper::buffer;
10+
#[doc(hidden)] pub use hyper::server::Server;
11+
#[doc(hidden)] pub use hyper::service::{MakeService, Service};
2012

21-
pub use hyper::mime;
13+
#[doc(hidden)] pub use hyper::Chunk;
14+
#[doc(hidden)] pub use http::header::HeaderName as HeaderName;
15+
#[doc(hidden)] pub use http::header::HeaderValue as HeaderValue;
16+
#[doc(hidden)] pub use http::method::Method;
17+
#[doc(hidden)] pub use http::request::Parts;
18+
#[doc(hidden)] pub use http::status::StatusCode;
19+
#[doc(hidden)] pub use http::uri::Uri;
2220

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

2624
/// Reexported Hyper header types.
2725
pub mod header {
2826
use crate::Header;
2927

30-
use hyper::header::Header as HyperHeaderTrait;
31-
3228
macro_rules! import_hyper_items {
3329
($($item:ident),*) => ($(pub use hyper::header::$item;)*)
3430
}
3531

3632
macro_rules! import_hyper_headers {
3733
($($name:ident),*) => ($(
38-
impl std::convert::From<self::$name> for Header<'static> {
39-
fn from(header: self::$name) -> Header<'static> {
40-
Header::new($name::header_name(), header.to_string())
41-
}
42-
}
34+
pub use http::header::$name as $name;
4335
)*)
4436
}
4537

46-
import_hyper_items! {
47-
Accept, AcceptCharset, AcceptEncoding, AcceptLanguage, AcceptRanges,
48-
AccessControlAllowCredentials, AccessControlAllowHeaders,
49-
AccessControlAllowMethods, AccessControlExposeHeaders,
50-
AccessControlMaxAge, AccessControlRequestHeaders,
51-
AccessControlRequestMethod, Allow, Authorization, Basic, Bearer,
52-
CacheControl, Connection, ContentDisposition, ContentEncoding,
53-
ContentLanguage, ContentLength, ContentRange, ContentType, Date, ETag,
54-
EntityTag, Expires, From, Headers, Host, HttpDate, IfModifiedSince,
55-
IfUnmodifiedSince, LastModified, Location, Origin, Prefer,
56-
PreferenceApplied, Protocol, Quality, QualityItem, Referer,
57-
StrictTransportSecurity, TransferEncoding, Upgrade, UserAgent,
58-
AccessControlAllowOrigin, ByteRangeSpec, CacheDirective, Charset,
59-
ConnectionOption, ContentRangeSpec, DispositionParam, DispositionType,
60-
Encoding, Expect, IfMatch, IfNoneMatch, IfRange, Pragma, Preference,
61-
ProtocolName, Range, RangeUnit, ReferrerPolicy, Vary, Scheme, q, qitem
62-
}
63-
38+
// import_hyper_items! {
39+
// Accept, AcceptCharset, AcceptEncoding, AcceptLanguage, AcceptRanges,
40+
// AccessControlAllowCredentials, AccessControlAllowHeaders,
41+
// AccessControlAllowMethods, AccessControlExposeHeaders,
42+
// AccessControlMaxAge, AccessControlRequestHeaders,
43+
// AccessControlRequestMethod, Allow, Authorization, Basic, Bearer,
44+
// CacheControl, Connection, ContentDisposition, ContentEncoding,
45+
// ContentLanguage, ContentLength, ContentRange, ContentType, Date, ETag,
46+
// EntityTag, Expires, From, Headers, Host, HttpDate, IfModifiedSince,
47+
// IfUnmodifiedSince, LastModified, Location, Origin, Prefer,
48+
// PreferenceApplied, Protocol, Quality, QualityItem, Referer,
49+
// StrictTransportSecurity, TransferEncoding, Upgrade, UserAgent,
50+
// AccessControlAllowOrigin, ByteRangeSpec, CacheDirective, Charset,
51+
// ConnectionOption, ContentRangeSpec, DispositionParam, DispositionType,
52+
// Encoding, Expect, IfMatch, IfNoneMatch, IfRange, Pragma, Preference,
53+
// ProtocolName, Range, RangeUnit, ReferrerPolicy, Vary, Scheme, q, qitem
54+
// }
55+
//
6456
import_hyper_headers! {
65-
Accept, AccessControlAllowCredentials, AccessControlAllowHeaders,
66-
AccessControlAllowMethods, AccessControlAllowOrigin,
67-
AccessControlExposeHeaders, AccessControlMaxAge,
68-
AccessControlRequestHeaders, AccessControlRequestMethod, AcceptCharset,
69-
AcceptEncoding, AcceptLanguage, AcceptRanges, Allow, CacheControl,
70-
Connection, ContentDisposition, ContentEncoding, ContentLanguage,
71-
ContentLength, ContentRange, Date, ETag, Expect, Expires, Host, IfMatch,
72-
IfModifiedSince, IfNoneMatch, IfRange, IfUnmodifiedSince, LastModified,
73-
Location, Origin, Pragma, Prefer, PreferenceApplied, Range, Referer,
74-
ReferrerPolicy, StrictTransportSecurity, TransferEncoding, Upgrade,
75-
UserAgent, Vary
57+
ACCEPT, ACCESS_CONTROL_ALLOW_CREDENTIALS, ACCESS_CONTROL_ALLOW_HEADERS,
58+
ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN,
59+
ACCESS_CONTROL_EXPOSE_HEADERS, ACCESS_CONTROL_MAX_AGE,
60+
ACCESS_CONTROL_REQUEST_HEADERS, ACCESS_CONTROL_REQUEST_METHOD, ACCEPT_CHARSET,
61+
ACCEPT_ENCODING, ACCEPT_LANGUAGE, ACCEPT_RANGES, ALLOW, CACHE_CONTROL,
62+
CONNECTION, CONTENT_DISPOSITION, CONTENT_ENCODING, CONTENT_LANGUAGE,
63+
CONTENT_LENGTH, CONTENT_RANGE, DATE, ETAG, EXPECT, EXPIRES, HOST, IF_MATCH,
64+
IF_MODIFIED_SINCE, IF_NONE_MATCH, IF_RANGE, IF_UNMODIFIED_SINCE, LAST_MODIFIED,
65+
LOCATION, ORIGIN, PRAGMA, RANGE, REFERER,
66+
REFERRER_POLICY, STRICT_TRANSPORT_SECURITY, TRANSFER_ENCODING, UPGRADE,
67+
USER_AGENT, VARY
7668
}
7769
}

core/http/src/method.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
extern crate http;
2+
13
use std::fmt;
24
use std::str::FromStr;
35

@@ -24,18 +26,18 @@ pub enum Method {
2426
impl Method {
2527
/// WARNING: This is unstable! Do not use this method outside of Rocket!
2628
#[doc(hidden)]
27-
pub fn from_hyp(method: &hyper::Method) -> Option<Method> {
29+
pub fn from_hyp(method: &http::method::Method) -> Option<Method> {
2830
match *method {
29-
hyper::Method::Get => Some(Get),
30-
hyper::Method::Put => Some(Put),
31-
hyper::Method::Post => Some(Post),
32-
hyper::Method::Delete => Some(Delete),
33-
hyper::Method::Options => Some(Options),
34-
hyper::Method::Head => Some(Head),
35-
hyper::Method::Trace => Some(Trace),
36-
hyper::Method::Connect => Some(Connect),
37-
hyper::Method::Patch => Some(Patch),
38-
hyper::Method::Extension(_) => None,
31+
http::method::Method::GET => Some(Get),
32+
http::method::Method::PUT => Some(Put),
33+
http::method::Method::POST => Some(Post),
34+
http::method::Method::DELETE => Some(Delete),
35+
http::method::Method::OPTIONS => Some(Options),
36+
http::method::Method::HEAD => Some(Head),
37+
http::method::Method::TRACE => Some(Trace),
38+
http::method::Method::CONNECT => Some(Connect),
39+
http::method::Method::PATCH => Some(Patch),
40+
_ => None,
3941
}
4042
}
4143

core/http/src/uri/uri.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ impl<'a> Uri<'a> {
9494
crate::parse::uri::from_str(string)
9595
}
9696

97+
// pub fn from_hyp(uri: &'a hyper::Uri) -> Uri<'a> {
98+
// match uri.is_absolute() {
99+
// true => Uri::Absolute(Absolute::new(
100+
// uri.scheme().unwrap(),
101+
// match uri.host() {
102+
// Some(host) => Some(Authority::new(None, Host::Raw(host), uri.port())),
103+
// None => None
104+
// },
105+
// None
106+
// )),
107+
// false => Uri::Asterisk
108+
// }
109+
// }
110+
97111
/// Returns the internal instance of `Origin` if `self` is a `Uri::Origin`.
98112
/// Otherwise, returns `None`.
99113
///

core/lib/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ tls = ["rocket_http/tls"]
2424
private-cookies = ["rocket_http/private-cookies"]
2525

2626
[dependencies]
27+
futures = "0.1"
2728
rocket_codegen = { version = "0.5.0-dev", path = "../codegen" }
2829
rocket_http = { version = "0.5.0-dev", path = "../http" }
30+
tokio = "0.1.16"
2931
yansi = "0.5"
3032
log = "0.4"
3133
toml = "0.4.7"

core/lib/src/catcher.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use yansi::Color::*;
5959
///
6060
/// A function decorated with `catch` must take exactly zero or one arguments.
6161
/// If the catcher takes an argument, it must be of type [`&Request`](Request).
62+
#[derive(Clone)]
6263
pub struct Catcher {
6364
/// The HTTP status code to match against.
6465
pub code: u16,

0 commit comments

Comments
 (0)