Auto merge of #13058 - malisas:malisa-responseAPI, r=Manishearth,jdm

Response API

<!-- Please describe your changes on the following line: -->
This PR adds the [dom::Response](https://fetch.spec.whatwg.org/#response-class) implementation and addresses #11896.

The relevant passing tests` expectations have been updated.

In order to allow non-UTF-8-encoded status messages, `net_traits::response::Response`'s `raw_status` field has been changed from type [`Option<RawStatus>`](https://doc.servo.org/hyper/http/struct.RawStatus.html) to type `Option<(u16, Vec<u8>)>`. As a result, a few other files which rely on the `raw_status` field were affected and updated.

TODOs:
- The `body` and `trailer` methods. Relies on implementation of `ReadableStream` and `Promise`s.
- Similarly, replace the dummy constructor `_body: Option<USVString>` argument with `body: ResponseBodyInit`.
- Currently, whenever `r's response's header list` or `r's Headers object` are mentioned, I always modify the `headers_reflector` field (of type dom::Headers, or `r's Headers object`) and not the corresponding hyper::Headers list in the net_traits::Response field. A completely accurate interpretation of the spec might consider making both of these lists the same thing via a reference. [Discussion](https://github.com/whatwg/fetch/issues/358) was [had](https://github.com/servo/servo/pull/12884).

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13058)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-09-08 18:58:05 -05:00 committed by GitHub
commit 5a5a76cc5d
30 changed files with 402 additions and 124 deletions

View file

@ -4,7 +4,6 @@
use file_loader;
use hyper::header::ContentType;
use hyper::http::RawStatus;
use hyper::mime::{Mime, SubLevel, TopLevel};
use hyper_serde::Serde;
use mime_classifier::MimeClassifier;
@ -38,7 +37,7 @@ pub fn factory(mut load_data: LoadData,
Some(Serde(ContentType(Mime(TopLevel::Text, SubLevel::Html, vec![])))),
charset: Some("utf-8".to_owned()),
headers: None,
status: Some(Serde(RawStatus(200, "OK".into()))),
status: Some((200, b"OK".to_vec())),
https_state: HttpsState::None,
referrer: None,
};

View file

@ -5,7 +5,6 @@
use filemanager_thread::{FileManager, UIProvider};
use hyper::header::{DispositionType, ContentDisposition, DispositionParam};
use hyper::header::{Headers, ContentType, ContentLength, Charset};
use hyper::http::RawStatus;
use hyper_serde::Serde;
use ipc_channel::ipc;
use mime::{Mime, Attr};
@ -72,7 +71,7 @@ fn load_blob<UI: 'static + UIProvider>
charset: charset.map(|c| c.as_str().to_string()),
headers: Some(Serde(headers)),
// https://w3c.github.io/FileAPI/#TwoHundredOK
status: Some(Serde(RawStatus(200, "OK".into()))),
status: Some((200, b"OK".to_vec())),
https_state: HttpsState::None,
referrer: None,
};

View file

@ -973,8 +973,9 @@ fn http_network_fetch(request: Rc<Request>,
Ok((res, msg)) => {
response.url = Some(url.clone());
response.status = Some(res.response.status);
response.raw_status = Some(res.response.status_raw().clone());
response.headers = res.response.headers.clone();
response.raw_status = Some((res.response.status_raw().0,
res.response.status_raw().1.as_bytes().to_vec()));
response.headers = res.response.headers.clone();
let res_body = response.body.clone();
@ -1001,7 +1002,7 @@ fn http_network_fetch(request: Rc<Request>,
send_response_to_devtools(
&sender, request_id.unwrap(),
meta_headers.map(Serde::into_inner),
meta_status.map(Serde::into_inner),
meta_status,
pipeline_id);
}
}

View file

@ -629,7 +629,7 @@ pub fn send_request_to_devtools(msg: ChromeToDevtoolsControlMsg,
pub fn send_response_to_devtools(devtools_chan: &Sender<DevtoolsControlMsg>,
request_id: String,
headers: Option<Headers>,
status: Option<RawStatus>,
status: Option<(u16, Vec<u8>)>,
pipeline_id: PipelineId) {
let response = DevtoolsHttpResponse { headers: headers, status: status, body: None, pipeline_id: pipeline_id };
let net_event_response = NetworkEvent::HttpResponse(response);
@ -1081,7 +1081,8 @@ pub fn load<A, B>(load_data: &LoadData,
None => None
});
metadata.headers = Some(Serde(adjusted_headers));
metadata.status = Some(Serde(response.status_raw().clone()));
metadata.status = Some((response.status_raw().0,
response.status_raw().1.as_bytes().to_vec()));
metadata.https_state = if doc_url.scheme() == "https" {
HttpsState::Modern
} else {
@ -1097,7 +1098,7 @@ pub fn load<A, B>(load_data: &LoadData,
send_response_to_devtools(
&chan, request_id.unwrap(),
metadata.headers.clone().map(Serde::into_inner),
metadata.status.clone().map(Serde::into_inner),
metadata.status.clone(),
pipeline_id);
}
}