14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from cStringIO import StringIO
101
class HTTPServerWithSmarts(HttpServer):
102
"""HTTPServerWithSmarts extends the HttpServer with POST methods that will
103
trigger a smart server to execute with a transport rooted at the rootdir of
108
HttpServer.__init__(self, SmartRequestHandler)
111
class SmartRequestHandler(TestingHTTPRequestHandler):
112
"""Extend TestingHTTPRequestHandler to support smart client POSTs."""
115
"""Hand the request off to a smart server instance."""
116
self.send_response(200)
117
self.send_header("Content-type", "application/octet-stream")
118
transport = get_transport(self.server.test_case._home_dir)
119
# TODO: We might like to support streaming responses. 1.0 allows no
120
# Content-length in this case, so for integrity we should perform our
121
# own chunking within the stream.
122
# 1.1 allows chunked responses, and in this case we could chunk using
123
# the HTTP chunking as this will allow HTTP persistence safely, even if
124
# we have to stop early due to error, but we would also have to use the
125
# HTTP trailer facility which may not be widely available.
126
out_buffer = StringIO()
127
smart_protocol_request = smart.SmartServerRequestProtocolOne(
128
transport, out_buffer.write)
129
# if this fails, we should return 400 bad request, but failure is
130
# failure for now - RBC 20060919
131
data_length = int(self.headers['Content-Length'])
132
# Perhaps there should be a SmartServerHTTPMedium that takes care of
133
# feeding the bytes in the http request to the smart_protocol_request,
134
# but for now it's simpler to just feed the bytes directly.
135
smart_protocol_request.accept_bytes(self.rfile.read(data_length))
136
assert smart_protocol_request.next_read_size() == 0, (
137
"not finished reading, but all data sent to protocol.")
138
self.send_header("Content-Length", str(len(out_buffer.getvalue())))
140
self.wfile.write(out_buffer.getvalue())
96
143
class TestCaseWithWebserver(TestCaseWithTransport):
97
144
"""A support class that provides readonly urls that are http://.