diff options
author | Gregory Terzian <gterzian@users.noreply.github.com> | 2018-06-22 12:36:28 +0800 |
---|---|---|
committer | Gregory Terzian <gterzian@users.noreply.github.com> | 2018-06-23 16:49:50 +0800 |
commit | 96c124230b367c0c9658e3628bcb0a33533cc96c (patch) | |
tree | d59c637732e0f262a72b9c6d669b5b10b9a9870f /components/net/http_cache.rs | |
parent | 3279d1fe85d3aa8dbb99c59b4184e4bc3cc6c54b (diff) | |
download | servo-96c124230b367c0c9658e3628bcb0a33533cc96c.tar.gz servo-96c124230b367c0c9658e3628bcb0a33533cc96c.zip |
Ensure done_chan is Some, when refreshing a still receiving resource
Diffstat (limited to 'components/net/http_cache.rs')
-rw-r--r-- | components/net/http_cache.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/components/net/http_cache.rs b/components/net/http_cache.rs index e45c8577215..601a4f6cc65 100644 --- a/components/net/http_cache.rs +++ b/components/net/http_cache.rs @@ -624,6 +624,23 @@ impl HttpCache { let entry_key = CacheKey::new(request.clone()); if let Some(cached_resources) = self.entries.get_mut(&entry_key) { for cached_resource in cached_resources.iter_mut() { + // done_chan will have been set to Some(..) by http_network_fetch. + // If the body is not receiving data, set the done_chan back to None. + // Otherwise, create a new dedicated channel to update the consumer. + // The response constructed here will replace the 304 one from the network. + let in_progress_channel = match *cached_resource.body.lock().unwrap() { + ResponseBody::Receiving(..) => { + Some(channel()) + }, + ResponseBody::Empty | ResponseBody::Done(..) => None + }; + match in_progress_channel { + Some((done_sender, done_receiver)) => { + *done_chan = Some((done_sender.clone(), done_receiver)); + cached_resource.awaiting_body.lock().unwrap().push(done_sender); + }, + None => *done_chan = None + } // Received a response with 304 status code, in response to a request that matches a cached resource. // 1. update the headers of the cached resource. // 2. return a response, constructed from the cached resource. @@ -635,9 +652,6 @@ impl HttpCache { constructed_response.referrer_policy = request.referrer_policy.clone(); constructed_response.raw_status = cached_resource.data.raw_status.clone(); constructed_response.url_list = cached_resource.data.url_list.clone(); - // done_chan will have been set to Some by http_network_fetch, - // set it back to None since the response returned here replaces the 304 one from the network. - *done_chan = None; cached_resource.data.expires = get_response_expiry(&constructed_response); let mut stored_headers = cached_resource.data.metadata.headers.lock().unwrap(); stored_headers.extend(response.headers.iter()); |