5
Copyright (C) 1999 Christian Scholz (ruebe@aachen.heimat.de)
7
This library is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Library General Public
9
License as published by the Free Software Foundation; either
10
version 2 of the License, or (at your option) any later version.
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Library General Public License for more details.
17
You should have received a copy of the GNU Library General Public
18
License along with this library; if not, write to the Free
19
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
from utils import VERSION, AUTHOR
28
from BaseHTTPServer import BaseHTTPRequestHandler
30
class BufferedHTTPRequestHandler(BaseHTTPRequestHandler):
32
Buffering HTTP Request Handler
34
This class is an extension to the BaseHTTPRequestHandler
35
class which buffers the whole output and sends it at once
36
after the processing if the request is finished.
38
This makes it possible to work together with some clients
39
which otherwise would break (e.g. cadaver)
44
def _init_buffer(self):
45
"""initialize the buffer.
47
If you override the handle() method remember to call
51
self.__outfp=open("/tmp/out.%s" %self.__class__,"a+")
54
""" append a string to the buffer """
55
self.__buffer=self.__buffer+s
58
""" flush the buffer to wfile """
59
self.wfile.write(self.__buffer)
60
self.__outfp.write(self.__buffer)
66
""" Handle a HTTP request """
69
BaseHTTPRequestHandler.handle(self)
72
def send_header(self, keyword, value):
73
"""Send a MIME header."""
74
if self.request_version != 'HTTP/0.9':
75
self._append("%s: %s\r\n" % (keyword, value))
77
def end_headers(self):
78
"""Send the blank line ending the MIME headers."""
79
if self.request_version != 'HTTP/0.9':
82
def send_response(self, code, message=None):
83
self.log_request(code)
86
if self.responses.has_key(code):
87
message = self.responses[code][0]
91
if self.request_version != 'HTTP/0.9':
92
self._append("%s %s %s\r\n" %
93
(self.protocol_version, str(code), message))
95
self.send_header('Server', self.version_string())
96
self.send_header('Connection', 'close')
97
self.send_header('Date', self.date_time_string())
99
protocol_version="HTTP/1.1"