Skip to content

Commit

Permalink
auto merge of #4065 : seanmonstar/servo/hyper, r=Manishearth
Browse files Browse the repository at this point in the history
Replaces `rust-http` with [hyper](https://github.com/hyperium/hyper).

I don't have any bench numbers: I'm not sure what I would run (before and after) to make a nice presentation. If someone could help me there, I can update this description.

WPT-wise, ~18 more tests succeeding.

So say we all?

Closes #3956
  • Loading branch information
bors-servo committed Nov 30, 2014
2 parents 9cea3ce + 317d8a1 commit 1193231
Show file tree
Hide file tree
Showing 32 changed files with 628 additions and 453 deletions.
46 changes: 40 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/msg/Cargo.toml
Expand Up @@ -17,8 +17,8 @@ git = "https://github.com/servo/rust-azure"
[dependencies.geom]
git = "https://github.com/servo/rust-geom"

[dependencies.http]
git = "https://github.com/servo/rust-http"
[dependencies.hyper]
git = "https://github.com/servo/hyper"
branch = "servo"

[dependencies.layers]
Expand Down
8 changes: 4 additions & 4 deletions components/msg/constellation_msg.rs
Expand Up @@ -8,8 +8,8 @@
use geom::rect::Rect;
use geom::size::TypedSize2D;
use geom::scale_factor::ScaleFactor;
use http::headers::request::HeaderCollection as RequestHeaderCollection;
use http::method::{Method, Get};
use hyper::header::Headers;
use hyper::method::{Method, Get};
use layers::geometry::DevicePixel;
use servo_util::geometry::{PagePx, ViewportPx};
use std::comm::{channel, Sender, Receiver};
Expand Down Expand Up @@ -214,7 +214,7 @@ pub enum Msg {
pub struct LoadData {
pub url: Url,
pub method: Method,
pub headers: RequestHeaderCollection,
pub headers: Headers,
pub data: Option<Vec<u8>>,
}

Expand All @@ -223,7 +223,7 @@ impl LoadData {
LoadData {
url: url,
method: Get,
headers: RequestHeaderCollection::new(),
headers: Headers::new(),
data: None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/msg/lib.rs
Expand Up @@ -7,7 +7,7 @@

extern crate azure;
extern crate geom;
extern crate http;
extern crate hyper;
extern crate layers;
extern crate serialize;
extern crate "util" as servo_util;
Expand Down
4 changes: 2 additions & 2 deletions components/net/Cargo.toml
Expand Up @@ -13,8 +13,8 @@ path = "../util"
[dependencies.geom]
git = "https://github.com/servo/rust-geom"

[dependencies.http]
git = "https://github.com/servo/rust-http"
[dependencies.hyper]
git = "https://github.com/servo/hyper"
branch = "servo"

[dependencies.png]
Expand Down
4 changes: 2 additions & 2 deletions components/net/about_loader.rs
Expand Up @@ -7,7 +7,7 @@ use file_loader;

use std::io::fs::PathExtensions;
use url::Url;
use http::status::Ok as StatusOk;
use hyper::http::RawStatus;
use servo_util::resource_files::resources_dir_path;


Expand All @@ -23,7 +23,7 @@ pub fn factory(mut load_data: LoadData, start_chan: Sender<TargetedLoadResponse>
content_type: Some(("text".to_string(), "html".to_string())),
charset: Some("utf-8".to_string()),
headers: None,
status: Some(StatusOk),
status: Some(RawStatus(200, "OK".into_string()))
});
chan.send(Done(Ok(())));
return
Expand Down
7 changes: 3 additions & 4 deletions components/net/data_loader.rs
Expand Up @@ -6,8 +6,7 @@ use resource_task::{Done, Payload, Metadata, LoadData, TargetedLoadResponse, sta

use serialize::base64::FromBase64;

use http::headers::test_utils::from_stream_with_str;
use http::headers::content_type::MediaType;
use hyper::mime::Mime;
use url::{percent_decode, NonRelativeSchemeData};


Expand Down Expand Up @@ -59,8 +58,8 @@ fn load(load_data: LoadData, start_chan: Sender<TargetedLoadResponse>) {

// Parse the content type using rust-http.
// FIXME: this can go into an infinite loop! (rust-http #25)
let content_type: Option<MediaType> = from_stream_with_str(ct_str);
metadata.set_content_type(&content_type);
let content_type: Option<Mime> = from_str(ct_str);
metadata.set_content_type(content_type.as_ref());

let progress_chan = start_sending(senders, metadata);
let bytes = percent_decode(parts[1].as_bytes());
Expand Down
2 changes: 1 addition & 1 deletion components/net/fetch/cors_cache.rs
Expand Up @@ -9,7 +9,7 @@
//! This library will eventually become the core of the Fetch crate
//! with CORSRequest being expanded into FetchRequest (etc)

use http::method::Method;
use hyper::method::Method;
use std::ascii::AsciiExt;
use std::comm::{Sender, Receiver, channel};
use time;
Expand Down
12 changes: 7 additions & 5 deletions components/net/fetch/request.rs
Expand Up @@ -3,8 +3,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use url::Url;
use http::method::{Get, Method};
use http::headers::request::HeaderCollection;
use hyper::method::{Get, Method};
use hyper::mime::{Mime, Text, Html, Charset, Utf8};
use hyper::header::Headers;
use hyper::header::common::ContentType;
use fetch::cors_cache::CORSCache;
use fetch::response::Response;

Expand Down Expand Up @@ -58,7 +60,7 @@ pub enum ResponseTainting {
pub struct Request {
pub method: Method,
pub url: Url,
pub headers: HeaderCollection,
pub headers: Headers,
pub unsafe_request: bool,
pub body: Option<Vec<u8>>,
pub preserve_content_codings: bool,
Expand Down Expand Up @@ -87,7 +89,7 @@ impl Request {
Request {
method: Get,
url: url,
headers: HeaderCollection::new(),
headers: Headers::new(),
unsafe_request: false,
body: None,
preserve_content_codings: false,
Expand Down Expand Up @@ -116,7 +118,7 @@ impl Request {
"about" => match self.url.non_relative_scheme_data() {
Some(s) if s.as_slice() == "blank" => {
let mut response = Response::new();
let _ = response.headers.insert_raw("Content-Type".to_string(), b"text/html;charset=utf-8");
response.headers.set(ContentType(Mime(Text, Html, vec![(Charset, Utf8)])));
response
},
_ => Response::network_error()
Expand Down
48 changes: 23 additions & 25 deletions components/net/fetch/response.rs
Expand Up @@ -3,11 +3,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use url::Url;
use http::status::{Status, UnregisteredStatus};
use http::status::Ok as StatusOk;
use http::headers::HeaderEnum;
use http::headers::response::HeaderCollection;
use std::ascii::OwnedAsciiExt;
use hyper::status::StatusCode;
use hyper::status::Ok as StatusOk;
use hyper::header::Headers;
use std::ascii::AsciiExt;
use std::comm::Receiver;

/// [Response type](http://fetch.spec.whatwg.org/#concept-response-type)
Expand Down Expand Up @@ -57,8 +56,9 @@ pub struct Response {
pub response_type: ResponseType,
pub termination_reason: Option<TerminationReason>,
pub url: Option<Url>,
pub status: Status,
pub headers: HeaderCollection,
/// `None` can be considered a StatusCode of `0`.
pub status: Option<StatusCode>,
pub headers: Headers,
pub body: ResponseBody,
/// [Internal response](http://fetch.spec.whatwg.org/#concept-internal-response), only used if the Response is a filtered response
pub internal_response: Option<Box<Response>>,
Expand All @@ -70,8 +70,8 @@ impl Response {
response_type: Default,
termination_reason: None,
url: None,
status: StatusOk,
headers: HeaderCollection::new(),
status: Some(StatusOk),
headers: Headers::new(),
body: Empty,
internal_response: None
}
Expand All @@ -82,8 +82,8 @@ impl Response {
response_type: Error,
termination_reason: None,
url: None,
status: UnregisteredStatus(0, "".to_string()),
headers: HeaderCollection::new(),
status: None,
headers: Headers::new(),
body: Empty,
internal_response: None
}
Expand All @@ -110,32 +110,30 @@ impl Response {
match filter_type {
Default | Error => unreachable!(),
Basic => {
let mut headers = HeaderCollection::new();
for h in old_headers.iter() {
match h.header_name().into_ascii_lower().as_slice() {
"set-cookie" | "set-cookie2" => {},
_ => headers.insert(h)
let headers = old_headers.iter().filter(|header| {
match header.name().to_ascii_lower().as_slice() {
"set-cookie" | "set-cookie2" => false,
_ => true
}
}
}).collect();
response.headers = headers;
response.response_type = filter_type;
},
CORS => {
let mut headers = HeaderCollection::new();
for h in old_headers.iter() {
match h.header_name().into_ascii_lower().as_slice() {
let headers = old_headers.iter().filter(|header| {
match header.name().to_ascii_lower().as_slice() {
"cache-control" | "content-language" |
"content-type" | "expires" | "last-modified" | "Pragma" => {},
"content-type" | "expires" | "last-modified" | "Pragma" => false,
// XXXManishearth handle Access-Control-Expose-Headers
_ => headers.insert(h)
_ => true
}
}
}).collect();
response.headers = headers;
response.response_type = filter_type;
},
Opaque => {
response.headers = HeaderCollection::new();
response.status = UnregisteredStatus(0, "".to_string());
response.headers = Headers::new();
response.status = None;
response.body = Empty;
}
}
Expand Down

0 comments on commit 1193231

Please sign in to comment.