servo: Merge #4128 - Fixes #3962 (from jtuchsen:issue-3962); r=jdm

Bad HTTP responses now have a 0 status code instead of 200 OK.

Source-Repo: https://github.com/servo/servo
Source-Revision: b56bab4e407b38fa1e58d8be247ecd5f156c89bc
This commit is contained in:
Jesse Tuchsen 2014-11-27 13:42:41 -07:00
Родитель 13d56c2822
Коммит 5234e4a7a9
4 изменённых файлов: 14 добавлений и 8 удалений

Просмотреть файл

@ -19,7 +19,7 @@ pub fn factory(mut load_data: LoadData, start_chan: Sender<LoadResponse>) {
content_type: Some(("text".to_string(), "html".to_string())),
charset: Some("utf-8".to_string()),
headers: None,
status: StatusOk,
status: Some(StatusOk),
});
chan.send(Done(Ok(())));
return

Просмотреть файл

@ -17,7 +17,10 @@ pub fn factory(load_data: LoadData, start_chan: Sender<LoadResponse>) {
}
fn send_error(url: Url, err: String, start_chan: Sender<LoadResponse>) {
match start_sending_opt(start_chan, Metadata::default(url)) {
let mut metadata = Metadata::default(url);
metadata.status = None;
match start_sending_opt(start_chan, metadata) {
Ok(p) => p.send(Done(Err(err))),
_ => {}
};
@ -133,7 +136,7 @@ fn load(load_data: LoadData, start_chan: Sender<LoadResponse>) {
let mut metadata = Metadata::default(url);
metadata.set_content_type(&response.headers.content_type);
metadata.headers = Some(response.headers.clone());
metadata.status = response.status.clone();
metadata.status = Some(response.status.clone());
let progress_chan = match start_sending_opt(start_chan, metadata) {
Ok(p) => p,

Просмотреть файл

@ -72,7 +72,7 @@ pub struct Metadata {
pub headers: Option<ResponseHeaderCollection>,
/// HTTP Status
pub status: Status
pub status: Option<Status>
}
impl Metadata {
@ -83,7 +83,7 @@ impl Metadata {
content_type: None,
charset: None,
headers: None,
status: StatusOk // http://fetch.spec.whatwg.org/#concept-response-status-message
status: Some(StatusOk) // http://fetch.spec.whatwg.org/#concept-response-status-message
}
}

Просмотреть файл

@ -88,7 +88,7 @@ pub struct GenerationId(uint);
pub enum XHRProgress {
/// Notify that headers have been received
HeadersReceivedMsg(GenerationId, Option<ResponseHeaderCollection>, Status),
HeadersReceivedMsg(GenerationId, Option<ResponseHeaderCollection>, Option<Status>),
/// Partial progress (after receiving headers), containing portion of the response
LoadingMsg(GenerationId, ByteString),
/// Loading is done
@ -874,8 +874,11 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
// Part of step 13, send() (processing response)
// XXXManishearth handle errors, if any (substep 1)
// Substep 2
*self.status_text.borrow_mut() = ByteString::new(status.reason().into_bytes());
self.status.set(status.code());
let status_text = status.as_ref().map_or(vec![], |s| s.reason().into_bytes());
let status_code = status.as_ref().map_or(0, |s| s.code());
*self.status_text.borrow_mut() = ByteString::new(status_text);
self.status.set(status_code);
match headers {
Some(ref h) => {
*self.response_headers.borrow_mut() = h.clone();