Index: net/tools/testserver/testserver.py |
diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py |
index 7919f87b8f079dea4fd00546bae5a2c1c3cfbace..a09337f8d196c23eafbe6e25e57e9244ef19255c 100755 |
--- a/net/tools/testserver/testserver.py |
+++ b/net/tools/testserver/testserver.py |
@@ -343,7 +343,6 @@ class TestPageHandler(testserver_base.BasePageHandler): |
self.GetClientCert, |
self.ClientCipherListHandler, |
self.CloseSocketHandler, |
- self.RangeResetHandler, |
self.DefaultResponseHandler] |
post_handlers = [ |
self.EchoTitleHandler, |
@@ -1371,7 +1370,7 @@ class TestPageHandler(testserver_base.BasePageHandler): |
self.send_header('Transfer-Encoding', 'chunked') |
self.end_headers() |
# Chunked encoding: sending all chunks, then final zero-length chunk and |
- # then final CRLF. |
+#then final CRLF. |
svaldez
2015/11/11 20:42:41
Extra change?
asanka
2015/11/11 20:57:25
Indeed. Undone.
|
for i in range(0, chunkedSettings['chunksNumber']): |
if i > 0: |
time.sleep(0.001 * chunkedSettings['waitBetweenChunks']) |
@@ -1560,154 +1559,6 @@ class TestPageHandler(testserver_base.BasePageHandler): |
self.wfile.close() |
return True |
- def RangeResetHandler(self): |
- """Send data broken up by connection resets every N (default 4K) bytes. |
- Support range requests. If the data requested doesn't straddle a reset |
- boundary, it will all be sent. Used for testing resuming downloads.""" |
- |
- def DataForRange(start, end): |
- """Data to be provided for a particular range of bytes.""" |
- # Offset and scale to avoid too obvious (and hence potentially |
- # collidable) data. |
- return ''.join([chr(y % 256) |
- for y in range(start * 2 + 15, end * 2 + 15, 2)]) |
- |
- if not self._ShouldHandleRequest('/rangereset'): |
- return False |
- |
- # HTTP/1.1 is required for ETag and range support. |
- self.protocol_version = 'HTTP/1.1' |
- _, _, url_path, _, query, _ = urlparse.urlparse(self.path) |
- |
- # Defaults |
- size = 8000 |
- # Note that the rst is sent just before sending the rst_boundary byte. |
- rst_boundary = 4000 |
- respond_to_range = True |
- hold_for_signal = False |
- rst_limit = -1 |
- token = 'DEFAULT' |
- fail_precondition = 0 |
- send_verifiers = True |
- |
- # Parse the query |
- qdict = urlparse.parse_qs(query, True) |
- if 'size' in qdict: |
- size = int(qdict['size'][0]) |
- if 'rst_boundary' in qdict: |
- rst_boundary = int(qdict['rst_boundary'][0]) |
- if 'token' in qdict: |
- # Identifying token for stateful tests. |
- token = qdict['token'][0] |
- if 'rst_limit' in qdict: |
- # Max number of rsts for a given token. |
- rst_limit = int(qdict['rst_limit'][0]) |
- if 'bounce_range' in qdict: |
- respond_to_range = False |
- if 'hold' in qdict: |
- # Note that hold_for_signal will not work with null range requests; |
- # see TODO below. |
- hold_for_signal = True |
- if 'no_verifiers' in qdict: |
- send_verifiers = False |
- if 'fail_precondition' in qdict: |
- fail_precondition = int(qdict['fail_precondition'][0]) |
- |
- # Record already set information, or set it. |
- rst_limit = TestPageHandler.rst_limits.setdefault(token, rst_limit) |
- if rst_limit != 0: |
- TestPageHandler.rst_limits[token] -= 1 |
- fail_precondition = TestPageHandler.fail_precondition.setdefault( |
- token, fail_precondition) |
- if fail_precondition != 0: |
- TestPageHandler.fail_precondition[token] -= 1 |
- |
- first_byte = 0 |
- last_byte = size - 1 |
- |
- # Does that define what we want to return, or do we need to apply |
- # a range? |
- range_response = False |
- range_header = self.headers.getheader('range') |
- if range_header and respond_to_range: |
- mo = re.match("bytes=(\d*)-(\d*)", range_header) |
- if mo.group(1): |
- first_byte = int(mo.group(1)) |
- if mo.group(2): |
- last_byte = int(mo.group(2)) |
- if last_byte > size - 1: |
- last_byte = size - 1 |
- range_response = True |
- if last_byte < first_byte: |
- return False |
- |
- if (fail_precondition and |
- (self.headers.getheader('If-Modified-Since') or |
- self.headers.getheader('If-Match'))): |
- self.send_response(412) |
- self.end_headers() |
- return True |
- |
- if range_response: |
- self.send_response(206) |
- self.send_header('Content-Range', |
- 'bytes %d-%d/%d' % (first_byte, last_byte, size)) |
- else: |
- self.send_response(200) |
- self.send_header('Content-Type', 'application/octet-stream') |
- self.send_header('Content-Length', last_byte - first_byte + 1) |
- if send_verifiers: |
- # If fail_precondition is non-zero, then the ETag for each request will be |
- # different. |
- etag = "%s%d" % (token, fail_precondition) |
- self.send_header('ETag', etag) |
- self.send_header('Last-Modified', 'Tue, 19 Feb 2013 14:32 EST') |
- self.end_headers() |
- |
- if hold_for_signal: |
- # TODO(rdsmith/phajdan.jr): http://crbug.com/169519: Without writing |
- # a single byte, the self.server.handle_request() below hangs |
- # without processing new incoming requests. |
- self.wfile.write(DataForRange(first_byte, first_byte + 1)) |
- first_byte = first_byte + 1 |
- # handle requests until one of them clears this flag. |
- self.server.wait_for_download = True |
- while self.server.wait_for_download: |
- self.server.handle_request() |
- |
- possible_rst = ((first_byte / rst_boundary) + 1) * rst_boundary |
- if possible_rst >= last_byte or rst_limit == 0: |
- # No RST has been requested in this range, so we don't need to |
- # do anything fancy; just write the data and let the python |
- # infrastructure close the connection. |
- self.wfile.write(DataForRange(first_byte, last_byte + 1)) |
- self.wfile.flush() |
- return True |
- |
- # We're resetting the connection part way in; go to the RST |
- # boundary and then send an RST. |
- # Because socket semantics do not guarantee that all the data will be |
- # sent when using the linger semantics to hard close a socket, |
- # we send the data and then wait for our peer to release us |
- # before sending the reset. |
- data = DataForRange(first_byte, possible_rst) |
- self.wfile.write(data) |
- self.wfile.flush() |
- self.server.wait_for_download = True |
- while self.server.wait_for_download: |
- self.server.handle_request() |
- l_onoff = 1 # Linger is active. |
- l_linger = 0 # Seconds to linger for. |
- self.connection.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, |
- struct.pack('ii', l_onoff, l_linger)) |
- |
- # Close all duplicates of the underlying socket to force the RST. |
- self.wfile.close() |
- self.rfile.close() |
- self.connection.close() |
- |
- return True |
- |
def DefaultResponseHandler(self): |
"""This is the catch-all response handler for requests that aren't handled |
by one of the special handlers above. |