mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Adds content-length to empty-bodied non-GET/HEAD requests
This commit is contained in:
parent
976dbc5155
commit
f257b5fcef
2 changed files with 24 additions and 0 deletions
|
@ -533,6 +533,10 @@ pub fn load<A>(load_data: LoadData,
|
||||||
try!(req.send(&load_data.data))
|
try!(req.send(&load_data.data))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
if load_data.method != Method::Get && load_data.method != Method::Head {
|
||||||
|
req.headers_mut().set(ContentLength(0))
|
||||||
|
}
|
||||||
|
|
||||||
send_request_to_devtools(
|
send_request_to_devtools(
|
||||||
devtools_chan.clone(), request_id.clone(), url.clone(),
|
devtools_chan.clone(), request_id.clone(), url.clone(),
|
||||||
method.clone(), load_data.headers.clone(),
|
method.clone(), load_data.headers.clone(),
|
||||||
|
|
|
@ -208,6 +208,26 @@ impl HttpRequest for AssertMustHaveBodyRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_load_when_request_is_not_get_or_head_and_there_is_no_body_content_length_should_be_set_to_0() {
|
||||||
|
let url = Url::parse("http://mozilla.com").unwrap();
|
||||||
|
let resource_mgr = new_resource_task("Test-agent".to_string(), None);
|
||||||
|
|
||||||
|
let mut load_data = LoadData::new(url.clone(), None);
|
||||||
|
load_data.data = None;
|
||||||
|
load_data.method = Method::Post;
|
||||||
|
|
||||||
|
let mut content_length = Headers::new();
|
||||||
|
content_length.set_raw("Content-Length".to_owned(), vec![<[_]>::to_vec("0".as_bytes())]);
|
||||||
|
|
||||||
|
let _ = load::<AssertRequestMustHaveHeaders>(
|
||||||
|
load_data.clone(), resource_mgr, None,
|
||||||
|
&AssertMustHaveHeadersRequestFactory {
|
||||||
|
expected_headers: content_length,
|
||||||
|
body: <[_]>::to_vec(&[])
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_when_redirecting_from_a_post_should_rewrite_next_request_as_get() {
|
fn test_load_when_redirecting_from_a_post_should_rewrite_next_request_as_get() {
|
||||||
struct Factory;
|
struct Factory;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue