Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #6 from alfredodeza/master

Get extra logging (and consistency) when Proxying
  • Loading branch information...
commit ed20686531334951dcf5a6b1d99a12582b420372 2 parents 59b320f + 09f79e6
@ironfroggy authored
Showing with 11 additions and 10 deletions.
  1. +4 −1 bettercache/proxy.py
  2. +7 −9 bettercache/views.py
View
5 bettercache/proxy.py
@@ -7,6 +7,7 @@
"""
from httplib2 import Http
+import logging
from django.http import HttpResponse
from django.conf import settings
@@ -26,6 +27,7 @@ def is_hop_by_hop(header_name):
return header_name.lower() in _hop_headers
HOST = getattr(settings, 'BETTERCACHE_ORIGIN_HOST', 'localhost')
+logger = logging.getLogger(__name__)
if getattr(settings, 'BETTERCACHE_ORIGIN_PORT', None):
HOST += ":" + str(settings.BETTERCACHE_ORIGIN_PORT)
@@ -48,13 +50,14 @@ def proxy(request):
# TODO: try/except
http = Http()
http.follow_redirects = False
+ logger.debug("GET for: %s" % uri)
info, content = http.request(uri, 'GET', headers=headers)
response = HttpResponse(content, status=info.pop('status'))
for name, val in info.items():
if not is_hop_by_hop(name):
response[name] = val
-
+ logger.info("PROXY to: %s" % uri)
return response
View
16 bettercache/views.py
@@ -2,10 +2,10 @@
from bettercache.proxy import proxy
import logging
-logger = logging.getLogger()
+logger = logging.getLogger(__name__)
class BetterView(CachingMixin):
- """Accepts any path and attempts to server it from the cache. If it cannot
+ """Accepts any path and attempts to serve it from the cache. If it cannot
find the response in the cache, it will use ``bettercache.proxy`` to fulfill
it, and cache the response.
"""
@@ -17,23 +17,21 @@ def get(self, request):
response, expired = self.get_cache(request)
# send off the celery task if it's expired
if expired:
- logger.info("sending task for %s" %request.build_absolute_uri())
+ logger.info("EXPIRED sending task for %s" % request.build_absolute_uri())
self.send_task(request, response)
elif response:
- logger.info("not sending task for %s" %request.build_absolute_uri())
+ logger.debug("not sending task for %s" % request.build_absolute_uri())
else:
- logger.info("cache miss for %s" %request.build_absolute_uri())
+ logger.info("MISS for: %s" % request.build_absolute_uri())
# if response is still none we have to proxy
if response is None:
- logger.info('request %s proxied' %request.build_absolute_uri())
+ logger.debug('PROXY from: %s' % request.build_absolute_uri())
response = proxy(request)
- #TODO: delete the following two lines
- #self.set_cache(request, response)
response['X-Bettercache-Proxy'] = 'true'
else:
response['X-Bettercache-Proxy'] = 'false'
- logger.info('request %s from cache' %request.build_absolute_uri())
+ logger.info('HIT for: %s' % request.build_absolute_uri())
return response
Please sign in to comment.
Something went wrong with that request. Please try again.