mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Make XMLHttpRequest user-set headers be preserved across redirects.
This commit is contained in:
parent
542e8d52d5
commit
fb217ab24b
4 changed files with 49 additions and 41 deletions
|
@ -108,22 +108,29 @@ reason: \"certificate verify failed\" }]";
|
|||
}
|
||||
};
|
||||
|
||||
// Preserve the `host` header set automatically by Request.
|
||||
let host = req.headers().get::<Host>().unwrap().clone();
|
||||
|
||||
// Avoid automatically preserving request headers when redirects occur.
|
||||
// See https://bugzilla.mozilla.org/show_bug.cgi?id=401564 and
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=216828
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=216828 .
|
||||
// Only preserve ones which have been explicitly marked as such.
|
||||
if iters == 1 {
|
||||
// Preserve the `host` header set automatically by Request.
|
||||
let host = req.headers().get::<Host>().unwrap().clone();
|
||||
*req.headers_mut() = load_data.headers.clone();
|
||||
req.headers_mut().set(host);
|
||||
let mut combined_headers = load_data.headers.clone();
|
||||
combined_headers.extend(load_data.preserved_headers.iter());
|
||||
*req.headers_mut() = combined_headers;
|
||||
} else {
|
||||
*req.headers_mut() = load_data.preserved_headers.clone();
|
||||
}
|
||||
|
||||
req.headers_mut().set(host);
|
||||
|
||||
let (tx, rx) = channel();
|
||||
cookies_chan.send(ControlMsg::GetCookiesForUrl(url.clone(), tx, CookieSource::HTTP));
|
||||
if let Some(cookie_list) = rx.recv().unwrap() {
|
||||
let mut v = Vec::new();
|
||||
v.push(cookie_list.into_bytes());
|
||||
load_data.headers.set_raw("Cookie".to_owned(), v);
|
||||
req.headers_mut().set_raw("Cookie".to_owned(), v);
|
||||
}
|
||||
|
||||
// FIXME(seanmonstar): use AcceptEncoding from Hyper once available
|
||||
|
|
|
@ -40,7 +40,10 @@ pub enum ControlMsg {
|
|||
pub struct LoadData {
|
||||
pub url: Url,
|
||||
pub method: Method,
|
||||
/// Headers that will apply to the initial request only
|
||||
pub headers: Headers,
|
||||
/// Headers that will apply to the initial request and any redirects
|
||||
pub preserved_headers: Headers,
|
||||
pub data: Option<Vec<u8>>,
|
||||
pub cors: Option<ResourceCORSData>,
|
||||
pub consumer: Sender<LoadResponse>,
|
||||
|
@ -52,6 +55,7 @@ impl LoadData {
|
|||
url: url,
|
||||
method: Method::Get,
|
||||
headers: Headers::new(),
|
||||
preserved_headers: Headers::new(),
|
||||
data: None,
|
||||
cors: None,
|
||||
consumer: consumer,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue