Permalink
Browse files

Bugfix: Include Etag in 304 Not Modified responses, allow all HTTPPre…

…amble kwargs to be passed to HTTPResponse subclasses
  • Loading branch information...
1 parent 831cc7d commit 5f428ed4d83d8efdf64da721297a9263c14d1993 @alekstorm committed Mar 12, 2012
Showing with 27 additions and 26 deletions.
  1. +5 −4 vortex/resources.py
  2. +22 −22 vortex/responses.py
View
9 vortex/resources.py
@@ -7,7 +7,7 @@
import time
import uuid
-from vortex import HTTPStream, Resource, authenticate, http_date, signed_cookie, xsrf
+from vortex import SAFE_METHODS, HTTPStream, Resource, authenticate, http_date, signed_cookie, xsrf
from vortex.responses import *
class DictResource(Resource):
@@ -77,20 +77,21 @@ def get(self, request, **kwargs):
# Don't send the result if the content has not been modified since the If-Modified-Since
modified = self.os.stat(self.path).st_mtime
- if 'If-Modified-Since' in request.headers and time.mktime(email.utils.parsedate(request.headers['If-Modified-Since'])) >= modified:
- return HTTPNotModifiedResponse()
headers = {
'Etag': '"%s"' % hashlib.sha1('\0'.join([self.path, str(modified)])).hexdigest(),
'Last-Modified': http_date(modified),
}
+ if 'If-Modified-Since' in request.headers and time.mktime(email.utils.parsedate(request.headers['If-Modified-Since'])) >= modified:
+ return HTTPNotModifiedResponse(headers=headers)
+
inm = request.headers.get('If-None-Match', None)
if inm:
if request.method not in SAFE_METHODS:
return HTTPPreconditionFailedResponse()
elif inm.find(headers['Etag']) != -1 or inm == '*':
- return HTTPNotModifiedResponse()
+ return HTTPNotModifiedResponse(headers=headers)
mimetype = mimetypes.guess_type(self.path)[0]
if mimetype:
View
44 vortex/responses.py
@@ -3,55 +3,55 @@
from vortex import HTTPPreamble, HTTPResponse
class HTTPCreatedResponse(HTTPResponse):
- def __init__(self, cookies=None):
- HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.CREATED, cookies=cookies))
+ def __init__(self, **kwargs):
+ HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.CREATED, **kwargs))
class HTTPNoContentResponse(HTTPResponse):
- def __init__(self, cookies=None):
- HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.NO_CONTENT, cookies=cookies))
+ def __init__(self, **kwargs):
+ HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.NO_CONTENT, **kwargs))
class HTTPFoundResponse(HTTPResponse):
- def __init__(self, location, body='', cookies=None):
- HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.FOUND, headers={'Location': location}, cookies=cookies), body=body)
+ def __init__(self, location, body='', **kwargs):
+ HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.FOUND, headers={'Location': location}, **kwargs), body=body)
class HTTPNotModifiedResponse(HTTPResponse):
- def __init__(self, body='', cookies=None):
- HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.NOT_MODIFIED, cookies=cookies), body=body)
+ def __init__(self, body='', **kwargs):
+ HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.NOT_MODIFIED, **kwargs), body=body)
class HTTPNotFoundResponse(HTTPResponse):
- def __init__(self, body='', cookies=None):
- HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.NOT_FOUND, cookies=cookies), body=body)
+ def __init__(self, body='', **kwargs):
+ HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.NOT_FOUND, **kwargs), body=body)
class HTTPBadRequestResponse(HTTPResponse):
- def __init__(self, body='', cookies=None):
- HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.BAD_REQUEST, cookies=cookies), body=body)
+ def __init__(self, body='', **kwargs):
+ HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.BAD_REQUEST, **kwargs), body=body)
class HTTPUnauthorizedResponse(HTTPResponse):
- def __init__(self, body='', cookies=None):
- HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.UNAUTHORIZED, cookies=cookies), body=body)
+ def __init__(self, body='', **kwargs):
+ HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.UNAUTHORIZED, **kwargs), body=body)
class HTTPForbiddenResponse(HTTPResponse):
- def __init__(self, body='', cookies=None):
- HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.FORBIDDEN, cookies=cookies), body=body)
+ def __init__(self, body='', **kwargs):
+ HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.FORBIDDEN, **kwargs), body=body)
class HTTPMethodNotAllowedResponse(HTTPResponse):
- def __init__(self, allowed, body='', cookies=None):
- HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.METHOD_NOT_ALLOWED, headers={'Allowed': allowed}, cookies=cookies), body=body)
+ def __init__(self, allowed, body='', **kwargs):
+ HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.METHOD_NOT_ALLOWED, headers={'Allowed': allowed}, **kwargs), body=body)
class HTTPNotImplementedResponse(HTTPResponse):
- def __init__(self, body='', cookies=None):
- HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.NOT_IMPLEMENTED, cookies=cookies), body=body)
+ def __init__(self, body='', **kwargs):
+ HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.NOT_IMPLEMENTED, **kwargs), body=body)
class HTTPInternalServerErrorResponse(HTTPResponse):
- def __init__(self, body='', cookies=None):
- HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.INTERNAL_SERVER_ERROR, cookies=cookies), body=body)
+ def __init__(self, body='', **kwargs):
+ HTTPResponse.__init__(self, HTTPPreamble(status_code=httplib.INTERNAL_SERVER_ERROR, **kwargs), body=body)

0 comments on commit 5f428ed

Please sign in to comment.