Commit 5be1af2c authored by Sam Rushing's avatar Sam Rushing

remove(): new method

HTTP_Protocol_Error: forgot to move this from server.py
http_file.__init__(), http_file._gen_read_all() : handle the old-school situation where data goes until "connection: close"
parent 78518a7b
......@@ -5,6 +5,9 @@ from coro import read_stream
W = coro.write_stderr
class HTTP_Protocol_Error:
pass
# candidate for sync.pyx?
class latch:
......@@ -41,6 +44,8 @@ class http_file:
if content_length:
self.content_length = int (content_length)
self.streamo = read_stream.buffered_stream (self._gen_read_fixed().next)
elif headers.test ('connection', 'close'):
self.streamo = read_stream.buffered_stream (self._gen_read_all().next)
else:
raise HTTP_Protocol_Error ("no way to determine length of HTTP data")
......@@ -73,6 +78,17 @@ class http_file:
self.done_cv.wake_all()
return
def _gen_read_all (self):
"generate content from all remaining data from socket"
s = self.streami
while 1:
block = s.read_exact (self.buffer_size)
if not block:
self.done_cv.wake_all()
return
else:
yield block
# XXX implement <size> argument
def read (self, join=True):
"read the entire contents. join=False returns a generator, join=True returns a string."
......@@ -155,8 +171,14 @@ class header_set:
probe.append (value)
def __delitem__ (self, name):
"Remove a header."
del self.headers[name]
def remove (self, name):
"remove a header [if present]"
if self.headers.has_key (name):
del self.headers[name]
def __str__ (self):
"Render the set of headers."
r = []
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment