From 5f8a310bd16b3ecbe131a516ce79afd221a95535 Mon Sep 17 00:00:00 2001 From: Gregory Terzian Date: Fri, 17 Nov 2017 21:36:30 +0800 Subject: also cache redirects --- components/net/http_cache.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'components/net/http_cache.rs') diff --git a/components/net/http_cache.rs b/components/net/http_cache.rs index 764fa3651df..c35f02a3d4d 100644 --- a/components/net/http_cache.rs +++ b/components/net/http_cache.rs @@ -35,7 +35,7 @@ pub struct CacheKey { impl CacheKey { fn new(request: Request) -> CacheKey { CacheKey { - url: request.url().clone() + url: request.current_url().clone() } } @@ -57,6 +57,7 @@ struct CachedResource { metadata: CachedMetadata, request_headers: Arc>, body: Arc>, + location_url: Option>, https_state: HttpsState, status: Option, raw_status: Option<(u16, Vec)>, @@ -273,6 +274,7 @@ fn create_cached_response(request: &Request, cached_resource: &CachedResource, c let mut response = Response::new(cached_resource.metadata.final_url.clone()); response.headers = cached_headers.clone(); response.body = cached_resource.body.clone(); + response.location_url = cached_resource.location_url.clone(); response.status = cached_resource.status.clone(); response.raw_status = cached_resource.raw_status.clone(); response.url_list = cached_resource.url_list.clone(); @@ -300,6 +302,7 @@ fn create_resource_with_bytes_from_resource(bytes: &[u8], resource: &CachedResou metadata: resource.metadata.clone(), request_headers: resource.request_headers.clone(), body: Arc::new(Mutex::new(ResponseBody::Done(bytes.to_owned()))), + location_url: resource.location_url.clone(), https_state: resource.https_state.clone(), status: Some(StatusCode::PartialContent), raw_status: Some((206, b"Partial Content".to_vec())), @@ -606,12 +609,6 @@ impl HttpCache { /// Storing Responses in Caches. /// pub fn store(&mut self, request: &Request, response: &Response) { - if let Some(status) = response.status { - // Not caching redirects, for simplicity, not per the spec. - if is_redirect_status(status) { - return - } - } if request.method != Method::Get { // Only Get requests are cached. return @@ -639,6 +636,7 @@ impl HttpCache { metadata: cacheable_metadata, request_headers: Arc::new(Mutex::new(request.headers.clone())), body: response.body.clone(), + location_url: response.location_url.clone(), https_state: response.https_state.clone(), status: response.status.clone(), raw_status: response.raw_status.clone(), -- cgit v1.2.3