diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-09-19 17:47:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-19 17:47:27 -0400 |
commit | df2adebefdfa3da49f173e480fa1e56450f9bda2 (patch) | |
tree | 1f05b49bac02318455a59d5b143c186fd872bdb9 /components/script/dom/response.rs | |
parent | 2ca7a134736bb4759ff209c1bc0b6dc3cc1984c9 (diff) | |
parent | c37a345dc9f4dda6ea29c42f96f6c7201c42cbac (diff) | |
download | servo-df2adebefdfa3da49f173e480fa1e56450f9bda2.tar.gz servo-df2adebefdfa3da49f173e480fa1e56450f9bda2.zip |
Auto merge of #21737 - chansuke:format_script, r=jdm
Format script component
---
<!-- 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 part of #21373.
- [x] These changes do not require tests because they format code only.
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- 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/21737)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/response.rs')
-rw-r--r-- | components/script/dom/response.rs | 75 |
1 files changed, 52 insertions, 23 deletions
diff --git a/components/script/dom/response.rs b/components/script/dom/response.rs index ff806a5bf8f..613145a370a 100644 --- a/components/script/dom/response.rs +++ b/components/script/dom/response.rs @@ -67,22 +67,32 @@ impl Response { // https://fetch.spec.whatwg.org/#dom-response pub fn new(global: &GlobalScope) -> DomRoot<Response> { - reflect_dom_object(Box::new(Response::new_inherited()), global, ResponseBinding::Wrap) + reflect_dom_object( + Box::new(Response::new_inherited()), + global, + ResponseBinding::Wrap, + ) } - pub fn Constructor(global: &GlobalScope, body: Option<BodyInit>, init: &ResponseBinding::ResponseInit) - -> Fallible<DomRoot<Response>> { + pub fn Constructor( + global: &GlobalScope, + body: Option<BodyInit>, + init: &ResponseBinding::ResponseInit, + ) -> Fallible<DomRoot<Response>> { // Step 1 if init.status < 200 || init.status > 599 { - return Err(Error::Range( - format!("init's status member should be in the range 200 to 599, inclusive, but is {}" - , init.status))); + return Err(Error::Range(format!( + "init's status member should be in the range 200 to 599, inclusive, but is {}", + init.status + ))); } // Step 2 if !is_valid_status_text(&init.statusText) { - return Err(Error::Type("init's statusText member does not match the reason-phrase token production" - .to_string())); + return Err(Error::Type( + "init's statusText member does not match the reason-phrase token production" + .to_string(), + )); } // Step 3 @@ -108,7 +118,8 @@ impl Response { // Step 7.1 if is_null_body_status(init.status) { return Err(Error::Type( - "Body is non-null but init's status member is a null body status".to_string())); + "Body is non-null but init's status member is a null body status".to_string(), + )); }; // Step 7.3 @@ -117,9 +128,15 @@ impl Response { // Step 7.4 if let Some(content_type_contents) = content_type { - if !r.Headers().Has(ByteString::new(b"Content-Type".to_vec())).unwrap() { - r.Headers().Append(ByteString::new(b"Content-Type".to_vec()), - ByteString::new(content_type_contents.as_bytes().to_vec()))?; + if !r + .Headers() + .Has(ByteString::new(b"Content-Type".to_vec())) + .unwrap() + { + r.Headers().Append( + ByteString::new(b"Content-Type".to_vec()), + ByteString::new(content_type_contents.as_bytes().to_vec()), + )?; } }; } @@ -147,7 +164,11 @@ impl Response { } // https://fetch.spec.whatwg.org/#dom-response-redirect - pub fn Redirect(global: &GlobalScope, url: USVString, status: u16) -> Fallible<DomRoot<Response>> { + pub fn Redirect( + global: &GlobalScope, + url: USVString, + status: u16, + ) -> Fallible<DomRoot<Response>> { // Step 1 let base_url = global.api_base_url(); let parsed_url = base_url.join(&url.0); @@ -172,8 +193,10 @@ impl Response { *r.raw_status.borrow_mut() = Some((status, b"".to_vec())); // Step 6 - let url_bytestring = ByteString::from_str(url.as_str()).unwrap_or(ByteString::new(b"".to_vec())); - r.Headers().Set(ByteString::new(b"Location".to_vec()), url_bytestring)?; + let url_bytestring = + ByteString::from_str(url.as_str()).unwrap_or(ByteString::new(b"".to_vec())); + r.Headers() + .Set(ByteString::new(b"Location".to_vec()), url_bytestring)?; // Step 4 continued // Headers Guard is set to Immutable here to prevent error in Step 6 @@ -209,9 +232,7 @@ impl BodyOperations for Response { fn take_body(&self) -> Option<Vec<u8>> { let body = mem::replace(&mut *self.body.borrow_mut(), NetTraitsResponseBody::Empty); match body { - NetTraitsResponseBody::Done(bytes) => { - Some(bytes) - }, + NetTraitsResponseBody::Done(bytes) => Some(bytes), body => { mem::replace(&mut *self.body.borrow_mut(), body); None @@ -248,12 +269,17 @@ fn is_null_body_status(status: u16) -> bool { impl ResponseMethods for Response { // https://fetch.spec.whatwg.org/#dom-response-type fn Type(&self) -> DOMResponseType { - *self.response_type.borrow()//into() + *self.response_type.borrow() //into() } // https://fetch.spec.whatwg.org/#dom-response-url fn Url(&self) -> USVString { - USVString(String::from((*self.url.borrow()).as_ref().map(|u| serialize_without_fragment(u)).unwrap_or(""))) + USVString(String::from( + (*self.url.borrow()) + .as_ref() + .map(|u| serialize_without_fragment(u)) + .unwrap_or(""), + )) } // https://fetch.spec.whatwg.org/#dom-response-redirected @@ -276,7 +302,7 @@ impl ResponseMethods for Response { Some(s) => { let status_num = s.to_u16(); return status_num >= 200 && status_num <= 299; - } + }, None => false, } } @@ -291,7 +317,8 @@ impl ResponseMethods for Response { // https://fetch.spec.whatwg.org/#dom-response-headers fn Headers(&self) -> DomRoot<Headers> { - self.headers_reflector.or_init(|| Headers::for_response(&self.global())) + self.headers_reflector + .or_init(|| Headers::for_response(&self.global())) } // https://fetch.spec.whatwg.org/#dom-response-clone @@ -304,7 +331,9 @@ impl ResponseMethods for Response { // Step 2 let new_response = Response::new(&self.global()); new_response.Headers().set_guard(self.Headers().get_guard()); - new_response.Headers().fill(Some(HeadersInit::Headers(self.Headers())))?; + new_response + .Headers() + .fill(Some(HeadersInit::Headers(self.Headers())))?; // https://fetch.spec.whatwg.org/#concept-response-clone // Instead of storing a net_traits::Response internally, we |