summaryrefslogtreecommitdiff
path: root/paste
diff options
context:
space:
mode:
authorcce <devnull@localhost>2005-12-29 18:44:53 +0000
committercce <devnull@localhost>2005-12-29 18:44:53 +0000
commited9585def36809315b53533fb89026fb621a607f (patch)
treee03fb1d7e24269751e3915d05dc09ec6bfcb361d /paste
parentcfd5e92779fb1da95a03db2b725dc8fbc701bfcb (diff)
downloadpaste-ed9585def36809315b53533fb89026fb621a607f.tar.gz
- removing all entity headers for 304 response
- added abstract parse function to HTTPHeader
Diffstat (limited to 'paste')
-rw-r--r--paste/fileapp.py12
-rw-r--r--paste/httpheaders.py20
2 files changed, 19 insertions, 13 deletions
diff --git a/paste/fileapp.py b/paste/fileapp.py
index ed77bac..57727cd 100644
--- a/paste/fileapp.py
+++ b/paste/fileapp.py
@@ -10,10 +10,11 @@ if-modified-since request header.
import os, time, mimetypes
from httpexceptions import HTTPBadRequest, HTTPForbidden, \
HTTPRequestRangeNotSatisfiable
-from httpheaders import get_header, Expires, Range, \
+from httpheaders import get_header, Expires, Range, list_headers, \
ContentType, AcceptRanges, CacheControl, ContentDisposition, \
ContentLength, ContentRange, LastModified, IfModifiedSince
+
CACHE_SIZE = 4096
BLOCK_SIZE = 4096 * 16
@@ -94,10 +95,9 @@ class DataApp(object):
try:
client_clock = IfModifiedSince.parse(environ)
if client_clock >= int(self.last_modified):
- # the client has a recent copy
- #@@: all entity headers should be removed, not just these
- ContentLength.delete(headers)
- ContentType.delete(headers)
+ # horribly inefficient, n^2 performance, yuck!
+ for head in list_headers(entity=True):
+ head.delete(headers)
start_response('304 Not Modified',headers)
return [''] # empty body
except HTTPBadRequest, exce:
@@ -112,7 +112,7 @@ class DataApp(object):
return HTTPRequestRangeNotSatisfiable((
"Range request was made beyond the end of the content,\r\n"
"which is %s long.\r\n Range: %s\r\n") % (
- self.content_length, range)
+ self.content_length, Range(environ))
).wsgi_application(environ, start_response)
content_length = 1 + (upper - lower)
diff --git a/paste/httpheaders.py b/paste/httpheaders.py
index 1c919e0..40656ef 100644
--- a/paste/httpheaders.py
+++ b/paste/httpheaders.py
@@ -267,6 +267,15 @@ class HTTPHeader(object):
return ''
raise NotImplementedError()
+ def parse(self, *args, **kwargs):
+ """
+ This method invokes __call__ with the arguments provided, parses
+ the header results, and then returns a header-specific data
+ structure corresponding to the header. For example, ``Expires``
+ header returns seconds (as returned by time.time() module).
+ """
+ raise NotImplementedError()
+
def __call__(self, *args, **kwargs):
"""
This finds/constructs field-value(s) for the given header
@@ -440,19 +449,16 @@ def get_header(name, raiseError=True):
raise AssertionError("'%s' is an unknown header" % name)
return retval
-def list_headers(general=True, request=True, response=True, entity=True):
+def list_headers(general=None, request=None, response=None, entity=None):
" list all headers for a given category "
+ if not (general or request or response or entity):
+ general = request = response = entity = True
search = []
for (bool,strval) in ((general,'general'), (request,'request'),
(response,'response'), (entity,'entity')):
if bool:
search.append(strval)
- search = tuple(search)
- for head in _headers.values():
- if head.category in search:
- retval.append(head)
- retval.sort()
- return retval
+ return [head for head in _headers.values() if head.category in search]
def normalize_headers(response_headers, strict=True):
"""