Auto merge of #9427 - nikkisquared:implement_main_fetch, r=jdm

Partial implementation of Main Fetch step

I started out with Step 11 of Main Fetch so I could test creating filtered responses, which broke my tests that compare the Fetch result to a message on a server. I realized that if I got the tests to work, I'd likely end up breaking them again with the next step of Main Fetch I added, so I went ahead and did as much of Main Fetch as I could figure out.

Some steps I'm sure I could implement, I just don't know how. Such as when the spec says to "wait for response", or how to implement a Runnable object (which iirc is what I need to use) to run everything after Step 8 in parallel.

The fetch tests are still not running correctly, but I sure it's because they're getting a filtered response which doesn't have the body of response. I'm not sure how to handle that, whether it means a change needed in the tests or in the Fetch code. Like always, I look forward to feedback on my work!

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9427)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-01-30 04:55:27 +05:30
commit f0122efcec
6 changed files with 264 additions and 65 deletions

View file

@ -9,7 +9,7 @@ use hyper::status::StatusCode;
use hyper::uri::RequestUri;
use net::fetch::methods::fetch;
use net_traits::request::{Context, Referer, Request};
use net_traits::response::{Response, ResponseBody};
use net_traits::response::{Response, ResponseBody, ResponseType};
use std::rc::Rc;
use url::Url;
@ -35,7 +35,8 @@ fn test_fetch_response_is_not_network_error() {
};
let (mut server, url) = make_server(handler);
let mut request = Request::new(url, Context::Fetch, false);
let origin = url.origin();
let mut request = Request::new(url, Context::Fetch, origin, false);
request.referer = Referer::NoReferer;
let wrapped_request = Rc::new(request);
@ -56,16 +57,20 @@ fn test_fetch_response_body_matches_const_message() {
};
let (mut server, url) = make_server(handler);
let mut request = Request::new(url, Context::Fetch, false);
let origin = url.origin();
let mut request = Request::new(url, Context::Fetch, origin, false);
request.referer = Referer::NoReferer;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, false);
let _ = server.close();
match fetch_response.body {
ResponseBody::Done(body) => {
assert_eq!(body, MESSAGE);
assert!(!Response::is_network_error(&fetch_response));
assert_eq!(fetch_response.response_type, ResponseType::Basic);
match *fetch_response.body.borrow() {
ResponseBody::Done(ref body) => {
assert_eq!(&**body, MESSAGE);
},
_ => panic!()
};
@ -94,7 +99,8 @@ fn test_fetch_redirect_count(message: &'static [u8], redirect_cap: u32) -> Respo
let (mut server, url) = make_server(handler);
let mut request = Request::new(url, Context::Fetch, false);
let origin = url.origin();
let mut request = Request::new(url, Context::Fetch, origin, false);
request.referer = Referer::NoReferer;
let wrapped_request = Rc::new(request);
@ -112,10 +118,12 @@ fn test_fetch_redirect_count_ceiling() {
let fetch_response = test_fetch_redirect_count(MESSAGE, redirect_cap);
assert_eq!(Response::is_network_error(&fetch_response), false);
match fetch_response.body {
ResponseBody::Done(body) => {
assert_eq!(body, MESSAGE);
assert!(!Response::is_network_error(&fetch_response));
assert_eq!(fetch_response.response_type, ResponseType::Basic);
match *fetch_response.body.borrow() {
ResponseBody::Done(ref body) => {
assert_eq!(&**body, MESSAGE);
},
_ => panic!()
};
@ -130,9 +138,10 @@ fn test_fetch_redirect_count_failure() {
let fetch_response = test_fetch_redirect_count(MESSAGE, redirect_cap);
assert_eq!(Response::is_network_error(&fetch_response), true);
match fetch_response.body {
ResponseBody::Done(_) => panic!(),
assert!(Response::is_network_error(&fetch_response));
match *fetch_response.body.borrow() {
ResponseBody::Done(_) | ResponseBody::Receiving(_) => panic!(),
_ => { }
};
}