Add Accept header to HTTP loader

The value of the header is the same as that of Firefox 35.0.1:
`text/html, application/xhtml+xml, application/xml; q=0.9, */*; q=0.8`

Closes #5399
This commit is contained in:
Brandon DeRosier 2015-03-27 21:49:15 -04:00
parent f5d21faa8b
commit 0a7a853a01

View file

@ -12,7 +12,7 @@ use std::collections::HashSet;
use file_loader;
use flate2::read::{DeflateDecoder, GzDecoder};
use hyper::client::Request;
use hyper::header::{AcceptEncoding, ContentLength, ContentType, Host, Location};
use hyper::header::{AcceptEncoding, Accept, ContentLength, ContentType, Host, Location, qitem, Quality, QualityItem};
use hyper::HttpError;
use hyper::method::Method;
use hyper::mime::{Mime, TopLevel, SubLevel};
@ -167,6 +167,16 @@ reason: \"certificate verify failed\" }]";
req.headers_mut().set(host);
if !req.headers().has::<Accept>() {
let accept = Accept(vec![
qitem(Mime(TopLevel::Text, SubLevel::Html, vec![])),
qitem(Mime(TopLevel::Application, SubLevel::Ext("xhtml+xml".to_string()), vec![])),
QualityItem::new(Mime(TopLevel::Application, SubLevel::Xml, vec![]), Quality(900u16)),
QualityItem::new(Mime(TopLevel::Star, SubLevel::Star, vec![]), Quality(800u16)),
]);
req.headers_mut().set(accept);
}
let (tx, rx) = channel();
cookies_chan.send(ControlMsg::GetCookiesForUrl(url.clone(), tx, CookieSource::HTTP)).unwrap();
if let Some(cookie_list) = rx.recv().unwrap() {