r6840 - bigboard/trunk/bigboard/httplib2
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r6840 - bigboard/trunk/bigboard/httplib2
- Date: Fri, 26 Oct 2007 15:25:06 -0500 (CDT)
Author: walters
Date: 2007-10-26 15:25:06 -0500 (Fri, 26 Oct 2007)
New Revision: 6840
Modified:
bigboard/trunk/bigboard/httplib2/__init__.py
Log:
Return immediately with 504 if we used Cache-Control: only-if-cached;
this fixes a major issue where we were doing HTTP requests synchronously
in the main thread.
Patch filed upstream:
http://code.google.com/p/httplib2/issues/detail?id=12
Modified: bigboard/trunk/bigboard/httplib2/__init__.py
===================================================================
--- bigboard/trunk/bigboard/httplib2/__init__.py 2007-10-26 20:03:37 UTC (rev 6839)
+++ bigboard/trunk/bigboard/httplib2/__init__.py 2007-10-26 20:25:06 UTC (rev 6840)
@@ -965,6 +965,8 @@
if method in ["GET", "HEAD"] and 'range' not in headers:
headers['accept-encoding'] = 'compress, gzip'
+ cache_control = _parse_cache_control(headers)
+
info = email.Message.Message()
cached_value = None
if self.cache:
@@ -989,7 +991,14 @@
# RFC 2616 Section 13.10
self.cache.delete(cachekey)
- if cached_value and method in ["GET", "HEAD"] and self.cache and 'range' not in headers:
+ if not cached_value and cache_control.has_key('only-if-cached'):
+ # Immediately handle the case where we are instructed to only
+ # check the cache; RFC 2616 Section 14.9.4
+ info['status'] = '504'
+ content = ""
+ response = Response(info)
+ return (response, content)
+ elif cached_value and method in ["GET", "HEAD"] and self.cache and 'range' not in headers:
if info.has_key('-x-permanent-redirect-url'):
# Should cached permanent redirects be counted in our redirection count? For now, yes.
(response, new_content) = self.request(info['-x-permanent-redirect-url'], "GET", headers = headers, redirections = redirections - 1)
@@ -1007,12 +1016,8 @@
entry_disposition = _entry_disposition(info, headers)
if entry_disposition == "FRESH":
- if not cached_value:
- info['status'] = '504'
- content = ""
response = Response(info)
- if cached_value:
- response.fromcache = True
+ response.fromcache = True
return (response, content)
if entry_disposition == "STALE":
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]