aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/headers.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-09-08 18:58:05 -0500
committerGitHub <noreply@github.com>2016-09-08 18:58:05 -0500
commit5a5a76cc5db830d2e622d4e0924837383b64dfa2 (patch)
tree9f104dbe418b8c42e5767b566700d59ceea84318 /components/script/dom/headers.rs
parentaa011ea2759683ede76639a1ea889c93c21d1cb8 (diff)
parentfaf32a7cfbaf568bbfeb4f2572ea96b6a30d231e (diff)
downloadservo-5a5a76cc5db830d2e622d4e0924837383b64dfa2.tar.gz
servo-5a5a76cc5db830d2e622d4e0924837383b64dfa2.zip
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 -->
Diffstat (limited to 'components/script/dom/headers.rs')
-rw-r--r--components/script/dom/headers.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/components/script/dom/headers.rs b/components/script/dom/headers.rs
index 7b45956c039..abfa959c8e6 100644
--- a/components/script/dom/headers.rs
+++ b/components/script/dom/headers.rs
@@ -209,7 +209,13 @@ impl Headers {
headers_for_request
}
- pub fn set_guard(&self, new_guard: Guard) {
+ pub fn for_response(global: GlobalRef) -> Root<Headers> {
+ let headers_for_response = Headers::new(global);
+ headers_for_response.guard.set(Guard::Response);
+ headers_for_response
+ }
+
+ pub fn set_guard(&self, new_guard: Guard) {
self.guard.set(new_guard)
}
@@ -346,7 +352,7 @@ pub fn is_forbidden_header_name(name: &str) -> bool {
// [3] https://tools.ietf.org/html/rfc7230#section-3.2.6
// [4] https://www.rfc-editor.org/errata_search.php?rfc=7230
fn validate_name_and_value(name: ByteString, value: ByteString)
- -> Result<(String, Vec<u8>), Error> {
+ -> Fallible<(String, Vec<u8>)> {
let valid_name = try!(validate_name(name));
if !is_field_content(&value) {
return Err(Error::Type("Value is not valid".to_string()));
@@ -354,7 +360,7 @@ fn validate_name_and_value(name: ByteString, value: ByteString)
Ok((valid_name, value.into()))
}
-fn validate_name(name: ByteString) -> Result<String, Error> {
+fn validate_name(name: ByteString) -> Fallible<String> {
if !is_field_name(&name) {
return Err(Error::Type("Name is not valid".to_string()));
}
@@ -444,7 +450,7 @@ fn is_field_vchar(x: u8) -> bool {
}
// https://tools.ietf.org/html/rfc5234#appendix-B.1
-fn is_vchar(x: u8) -> bool {
+pub fn is_vchar(x: u8) -> bool {
match x {
0x21...0x7E => true,
_ => false,
@@ -452,7 +458,7 @@ fn is_vchar(x: u8) -> bool {
}
// http://tools.ietf.org/html/rfc7230#section-3.2.6
-fn is_obs_text(x: u8) -> bool {
+pub fn is_obs_text(x: u8) -> bool {
match x {
0x80...0xFF => true,
_ => false,