Make sure self._answer is available
authorGuido Günther <agx@sigxcpu.org>
Tue, 28 May 2013 16:46:15 +0000 (10:46 -0600)
committerKeith Packard <keithp@keithp.com>
Tue, 28 May 2013 16:46:15 +0000 (10:46 -0600)
Otherwise we might end up referencing self._answer in do_GET
when we caught an exception early in do_HEAD:

127.0.0.1 - - [24/May/2013 15:12:56] "GET /asfd/ HTTP/1.1" 400 -
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 45386)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 649, in __init__ self.handle()
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/var/scratch/debian/calypso/calypso/calypso/__init__.py", line 169, in handle_one_request
    method()
  File "/var/scratch/debian/calypso/calypso/calypso/__init__.py", line 131, in <lambda>
    check_rights = lambda function: lambda request: _check(request, function)
  File "/var/scratch/debian/calypso/calypso/calypso/__init__.py", line 86, in _check
    function(request, context={"user": user, "user-agent": request.headers.get("User-Agent", None)})
  File "/var/scratch/debian/calypso/calypso/calypso/__init__.py", line 225, in do_GET
    if self._answer:
AttributeError: CollectionHTTPHandler instance has no attribute '_answer'
----------------------------------------

Use an empty string instead of None since len() work on the former so we
can compute the Content-Length

fixup! Make sure self._answer is available

Signed-off-by: Keith Packard <keithp@keithp.com>
calypso/__init__.py

index 266fcea591f217178bc95ceee53dca1aa7eefdc2..1eac311db0abc14aab75a326b7278144469dfef4 100644 (file)
@@ -236,6 +236,7 @@ class CollectionHTTPHandler(server.BaseHTTPRequestHandler):
     @check_rights
     def do_HEAD(self, context):
         """Manage HEAD request."""
+        self._answer = ''
         try:
             item_name = paths.resource_from_path(self.path)
             if item_name and self._collection:
@@ -245,7 +246,6 @@ class CollectionHTTPHandler(server.BaseHTTPRequestHandler):
                     answer_text = item.text
                     etag = item.etag
                 else:
-                    self._answer = None
                     self.send_response(client.GONE)
                     self.end_headers()
                     return
@@ -254,7 +254,6 @@ class CollectionHTTPHandler(server.BaseHTTPRequestHandler):
                 answer_text = self._collection.text
                 etag = self._collection.etag
             else:
-                self._answer = None
                 self.send_response(client.NOT_FOUND)
                 self.end_headers()
                 return