mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Make headers available when creating an HTTP request via a factory.
This commit is contained in:
parent
dc790048ec
commit
80eaeac9f4
1 changed files with 12 additions and 3 deletions
|
@ -249,7 +249,16 @@ impl HttpResponse for WrappedHttpResponse {
|
||||||
pub trait HttpRequestFactory {
|
pub trait HttpRequestFactory {
|
||||||
type R: HttpRequest;
|
type R: HttpRequest;
|
||||||
|
|
||||||
fn create(&self, url: Url, method: Method) -> Result<Self::R, LoadError>;
|
fn create(&self, _url: Url, _method: Method) -> Result<Self::R, LoadError> {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
fn create_with_headers(&self, url: Url, method: Method, headers: Headers) -> Result<Self::R, LoadError> {
|
||||||
|
let mut result = self.create(url, method);
|
||||||
|
if let Ok(ref mut req) = result {
|
||||||
|
*req.headers_mut() = headers;
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NetworkHttpRequestFactory {
|
pub struct NetworkHttpRequestFactory {
|
||||||
|
@ -636,8 +645,8 @@ 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(connection_url.clone(), method.clone()));
|
let mut req = try!(request_factory.create_with_headers(connection_url.clone(), method.clone(),
|
||||||
*req.headers_mut() = request_headers.clone();
|
request_headers.clone()));
|
||||||
|
|
||||||
if cancel_listener.is_cancelled() {
|
if cancel_listener.is_cancelled() {
|
||||||
return Err(LoadError::Cancelled(connection_url.clone(), "load cancelled".to_owned()));
|
return Err(LoadError::Cancelled(connection_url.clone(), "load cancelled".to_owned()));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue