1
# Copyright (C) 2006, 2007 Canonical Ltd
1
# Copyright (C) 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
60
60
def handle_one_request(self):
61
61
"""Handle a single HTTP request.
63
We catch all socket errors occurring when the client close the
64
connection early to avoid polluting the test results.
63
You normally don't need to override this method; see the class
64
__doc__ string for information on how to handle specific HTTP
65
commands such as GET and POST.
67
SimpleHTTPRequestHandler.handle_one_request(self)
68
except socket.error, e:
70
and e.args[0] in (errno.EPIPE, errno.ECONNRESET,
71
errno.ECONNABORTED,)):
72
self.close_connection = 1
68
for i in xrange(1,11): # Don't try more than 10 times
70
self.raw_requestline = self.rfile.readline()
71
except socket.error, e:
72
if e.args[0] in (errno.EAGAIN, errno.EWOULDBLOCK):
73
# omitted for now because some tests look at the log of
74
# the server and expect to see no errors. see recent
75
# email thread. -- mbp 20051021.
76
## self.log_message('EAGAIN (%d) while reading from raw_requestline' % i)
82
if not self.raw_requestline:
83
self.close_connection = 1
85
if not self.parse_request(): # An error code has been sent, just exit
87
mname = 'do_' + self.command
88
if getattr(self, mname, None) is None:
89
self.send_error(501, "Unsupported method (%r)" % self.command)
91
method = getattr(self, mname)
77
94
_range_regexp = re.compile(r'^(?P<start>\d+)-(?P<end>\d+)$')
78
95
_tail_regexp = re.compile(r'^-(?P<tail>\d+)$')
143
160
self.end_headers()
144
161
self.send_range_content(file, start, end - start + 1)
146
self.wfile.write("--%s\r\n" % boundary)
162
self.wfile.write("--%s\r\n" % boundary)
148
164
def do_GET(self):
149
165
"""Serve a GET request.
151
167
Handles the Range header.
154
self.server.test_case_server.GET_request_nb += 1
156
170
path = self.translate_path(self.path)
157
171
ranges_header_value = self.headers.get('Range')
277
291
# the tests cases.
278
292
self.test_case_server = test_case_server
280
def server_close(self):
281
"""Called to clean-up the server.
283
Since the server may be in a blocking read, we shutdown the socket
286
self.socket.shutdown(socket.SHUT_RDWR)
287
BaseHTTPServer.HTTPServer.server_close(self)
290
295
class HttpServer(Server):
291
296
"""A test server for http transports.