servo: Merge #12851 - Fix step 31 of the Request constructor (from jeenalee:request); r=nox

<!-- Please describe your changes on the following line: -->
This PR fixes the step 31 of the Request constructor to fill Request's Headers object and rethrow any exceptions. Additionally, it removes unnecessary line breaks, comments, and redundant function.

---
<!-- 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
- [X] These changes fix #12845 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because this PR does not change the behavior of the Request constructor.

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

In addition to fixing step 31 of the Request constructor, this
commit also:
- remove `get_current_url` function, and use `net_request::request`'s
built-in `current_url` method
- clean up unnecessary line breaks and comments

Source-Repo: https://github.com/servo/servo
Source-Revision: 882872897e9473ec176d771589f64769fbd4c352
This commit is contained in:
Jeena Lee 2016-08-13 15:26:15 -05:00
Родитель 8483739854
Коммит 3e55dba029
1 изменённых файлов: 3 добавлений и 15 удалений

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

@ -32,7 +32,7 @@ use net_traits::request::Request as NetTraitsRequest;
use net_traits::request::RequestMode as NetTraitsRequestMode;
use net_traits::request::Type as NetTraitsRequestType;
use net_traits::request::{Origin, Window};
use std::cell::{Cell, Ref};
use std::cell::Cell;
use url::Url;
#[dom_struct]
@ -144,7 +144,7 @@ impl Request {
// Step 12
let mut request: NetTraitsRequest;
request = net_request_from_global(global,
get_current_url(&temporary_request).unwrap().clone(),
temporary_request.current_url(),
false);
request.method = temporary_request.method;
request.headers = temporary_request.headers.clone();
@ -214,8 +214,6 @@ impl Request {
return Err(Error::Type(
"RequestInit's referrer has invalid origin".to_string()));
}
// TODO: Requires Step 7.
// Step 14.7
*request.referer.borrow_mut() = NetTraitsRequestReferer::RefererUrl(parsed_referrer);
}
@ -339,7 +337,7 @@ impl Request {
}
// Step 31
r.Headers().fill(Some(HeadersOrByteStringSequenceSequence::Headers(headers_copy)));
try!(r.Headers().fill(Some(HeadersOrByteStringSequenceSequence::Headers(headers_copy))));
// Step 32
let input_body = if let RequestInfo::Request(ref input_request) = input {
@ -433,16 +431,6 @@ fn net_request_from_global(global: GlobalRef,
Some(pipeline_id))
}
// https://fetch.spec.whatwg.org/#concept-request-current-url
fn get_current_url(req: &NetTraitsRequest) -> Option<Ref<Url>> {
let url_list = req.url_list.borrow();
if url_list.len() > 0 {
Some(Ref::map(url_list, |urls| urls.last().unwrap()))
} else {
None
}
}
fn normalized_method_to_typed_method(m: &str) -> hyper::method::Method {
match m {
"DELETE" => hyper::method::Method::Delete,