mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Reorganize header manipulation that occurs before sending an HTTP request so we can provide the full set of headers while creating a request.
This commit is contained in:
parent
0e1703d747
commit
a315f8db9e
1 changed files with 30 additions and 26 deletions
|
@ -639,6 +639,7 @@ pub fn obtain_response<A>(request_factory: &HttpRequestFactory<R=A>,
|
||||||
request_id: &str)
|
request_id: &str)
|
||||||
-> Result<A::R, LoadError> where A: HttpRequest + 'static {
|
-> Result<A::R, LoadError> where A: HttpRequest + 'static {
|
||||||
|
|
||||||
|
let null_data = None;
|
||||||
let response;
|
let response;
|
||||||
let connection_url = replace_hosts(&url);
|
let connection_url = replace_hosts(&url);
|
||||||
|
|
||||||
|
@ -647,20 +648,7 @@ pub fn obtain_response<A>(request_factory: &HttpRequestFactory<R=A>,
|
||||||
// a ConnectionAborted error. this loop tries again with a new
|
// a ConnectionAborted error. this loop tries again with a new
|
||||||
// connection.
|
// connection.
|
||||||
loop {
|
loop {
|
||||||
let mut req = try!(request_factory.create_with_headers(connection_url.clone(), method.clone(),
|
let mut headers = request_headers.clone();
|
||||||
request_headers.clone()));
|
|
||||||
|
|
||||||
if cancel_listener.is_cancelled() {
|
|
||||||
return Err(LoadError::Cancelled(connection_url.clone(), "load cancelled".to_owned()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if log_enabled!(log::LogLevel::Info) {
|
|
||||||
info!("{}", method);
|
|
||||||
for header in req.headers_mut().iter() {
|
|
||||||
info!(" - {}", header);
|
|
||||||
}
|
|
||||||
info!("{:?}", data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Avoid automatically sending request body if a redirect has occurred.
|
// Avoid automatically sending request body if a redirect has occurred.
|
||||||
//
|
//
|
||||||
|
@ -669,26 +657,42 @@ pub fn obtain_response<A>(request_factory: &HttpRequestFactory<R=A>,
|
||||||
//
|
//
|
||||||
// https://tools.ietf.org/html/rfc7231#section-6.4
|
// https://tools.ietf.org/html/rfc7231#section-6.4
|
||||||
let is_redirected_request = iters != 1;
|
let is_redirected_request = iters != 1;
|
||||||
let cloned_data;
|
let request_body;
|
||||||
let maybe_response = match data {
|
match data {
|
||||||
&Some(ref d) if !is_redirected_request => {
|
&Some(ref d) if !is_redirected_request => {
|
||||||
req.headers_mut().set(ContentLength(d.len() as u64));
|
headers.set(ContentLength(d.len() as u64));
|
||||||
cloned_data = data.clone();
|
request_body = data;
|
||||||
req.send(data)
|
}
|
||||||
},
|
|
||||||
_ => {
|
_ => {
|
||||||
if *load_data_method != Method::Get && *load_data_method != Method::Head {
|
if *load_data_method != Method::Get && *load_data_method != Method::Head {
|
||||||
req.headers_mut().set(ContentLength(0))
|
headers.set(ContentLength(0))
|
||||||
}
|
}
|
||||||
cloned_data = None;
|
request_body = &null_data;
|
||||||
req.send(&None)
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
if log_enabled!(log::LogLevel::Info) {
|
||||||
|
info!("{}", method);
|
||||||
|
for header in headers.iter() {
|
||||||
|
info!(" - {}", header);
|
||||||
|
}
|
||||||
|
info!("{:?}", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
let req = try!(request_factory.create_with_headers(connection_url.clone(), method.clone(),
|
||||||
|
headers.clone()));
|
||||||
|
|
||||||
|
if cancel_listener.is_cancelled() {
|
||||||
|
return Err(LoadError::Cancelled(connection_url.clone(), "load cancelled".to_owned()));
|
||||||
|
}
|
||||||
|
|
||||||
|
let maybe_response = req.send(request_body);
|
||||||
|
|
||||||
if let Some(pipeline_id) = *pipeline_id {
|
if let Some(pipeline_id) = *pipeline_id {
|
||||||
send_request_to_devtools(
|
send_request_to_devtools(
|
||||||
devtools_chan.clone(), request_id.clone().into(),
|
devtools_chan.clone(), request_id.clone().into(),
|
||||||
url.clone(), method.clone(), request_headers.clone(),
|
url.clone(), method.clone(), headers,
|
||||||
cloned_data, pipeline_id, time::now()
|
request_body.clone(), pipeline_id, time::now()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue