mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Autocomputed content-type header now reaches net request
This commit is contained in:
parent
bb5cd02da3
commit
b9c4b64978
2 changed files with 18 additions and 35 deletions
|
@ -25,6 +25,7 @@ use crate::dom::headers::{Guard, Headers};
|
||||||
use crate::dom::promise::Promise;
|
use crate::dom::promise::Promise;
|
||||||
use crate::dom::xmlhttprequest::Extractable;
|
use crate::dom::xmlhttprequest::Extractable;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use http::header::{HeaderName, HeaderValue};
|
||||||
use http::method::InvalidMethod;
|
use http::method::InvalidMethod;
|
||||||
use http::Method as HttpMethod;
|
use http::Method as HttpMethod;
|
||||||
use net_traits::request::CacheMode as NetTraitsRequestCache;
|
use net_traits::request::CacheMode as NetTraitsRequestCache;
|
||||||
|
@ -309,7 +310,8 @@ impl Request {
|
||||||
// Step 30 TODO: "If signal is not null..."
|
// Step 30 TODO: "If signal is not null..."
|
||||||
|
|
||||||
// Step 31
|
// Step 31
|
||||||
// "or_init" looks unclear here
|
// "or_init" looks unclear here, but it always enters the block since r
|
||||||
|
// hasn't had any other way to initialize its headers
|
||||||
r.headers.or_init(|| Headers::for_request(&r.global()));
|
r.headers.or_init(|| Headers::for_request(&r.global()));
|
||||||
|
|
||||||
// Step 32 - but spec says this should only be when non-empty init?
|
// Step 32 - but spec says this should only be when non-empty init?
|
||||||
|
@ -420,15 +422,27 @@ impl Request {
|
||||||
|
|
||||||
// Step 36.4
|
// Step 36.4
|
||||||
if let Some(contents) = content_type {
|
if let Some(contents) = content_type {
|
||||||
|
let ct_header_name = b"Content-Type";
|
||||||
if !r
|
if !r
|
||||||
.Headers()
|
.Headers()
|
||||||
.Has(ByteString::new(b"Content-Type".to_vec()))
|
.Has(ByteString::new(ct_header_name.to_vec()))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
|
let ct_header_val = contents.as_bytes();
|
||||||
r.Headers().Append(
|
r.Headers().Append(
|
||||||
ByteString::new(b"Content-Type".to_vec()),
|
ByteString::new(ct_header_name.to_vec()),
|
||||||
ByteString::new(contents.as_bytes().to_vec()),
|
ByteString::new(ct_header_val.to_vec()),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
// In Servo r.Headers's header list isn't a pointer to
|
||||||
|
// the same actual list as r.request's, and so we need to
|
||||||
|
// append to both lists to keep them in sync.
|
||||||
|
if let Ok(v) = HeaderValue::from_bytes(ct_header_val) {
|
||||||
|
r.request
|
||||||
|
.borrow_mut()
|
||||||
|
.headers
|
||||||
|
.insert(HeaderName::from_bytes(ct_header_name).unwrap(), v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,47 +1,16 @@
|
||||||
[request-headers.any.html]
|
[request-headers.any.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
[Fetch with PUT with body]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Fetch with POST with text body]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Fetch with POST with FormData body]
|
[Fetch with POST with FormData body]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Fetch with POST with URLSearchParams body]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Fetch with POST with Blob body with mime type]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Fetch with Chicken]
|
[Fetch with Chicken]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Fetch with Chicken with body]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[request-headers.any.worker.html]
|
[request-headers.any.worker.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
[Fetch with PUT with body]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Fetch with POST with text body]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Fetch with POST with FormData body]
|
[Fetch with POST with FormData body]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Fetch with POST with URLSearchParams body]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Fetch with POST with Blob body with mime type]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Fetch with Chicken]
|
[Fetch with Chicken]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Fetch with Chicken with body]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue