Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: net/tools/testserver/testserver.py

Issue 1049343002: Make the test server's SlowServerHandler match the documentation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """This is a simple HTTP/FTP/TCP/UDP/BASIC_AUTH_PROXY/WEBSOCKET server used for 6 """This is a simple HTTP/FTP/TCP/UDP/BASIC_AUTH_PROXY/WEBSOCKET server used for
7 testing Chrome. 7 testing Chrome.
8 8
9 It supports several test URLs, as specified by the handlers in TestPageHandler. 9 It supports several test URLs, as specified by the handlers in TestPageHandler.
10 By default, it listens on an ephemeral port and sends the port number back to 10 By default, it listens on an ephemeral port and sends the port number back to
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 def SlowServerHandler(self): 1318 def SlowServerHandler(self):
1319 """Wait for the user suggested time before responding. The syntax is 1319 """Wait for the user suggested time before responding. The syntax is
1320 /slow?0.5 to wait for half a second.""" 1320 /slow?0.5 to wait for half a second."""
1321 1321
1322 if not self._ShouldHandleRequest("/slow"): 1322 if not self._ShouldHandleRequest("/slow"):
1323 return False 1323 return False
1324 query_char = self.path.find('?') 1324 query_char = self.path.find('?')
1325 wait_sec = 1.0 1325 wait_sec = 1.0
1326 if query_char >= 0: 1326 if query_char >= 0:
1327 try: 1327 try:
1328 wait_sec = int(self.path[query_char + 1:]) 1328 wait_sec = float(self.path[query_char + 1:])
1329 except ValueError: 1329 except ValueError:
1330 pass 1330 pass
1331 time.sleep(wait_sec) 1331 time.sleep(wait_sec)
1332 self.send_response(200) 1332 self.send_response(200)
1333 self.send_header('Content-Type', 'text/plain') 1333 self.send_header('Content-Type', 'text/plain')
1334 self.end_headers() 1334 self.end_headers()
1335 self.wfile.write("waited %d seconds" % wait_sec) 1335 self.wfile.write("waited %.1f seconds" % wait_sec)
1336 return True 1336 return True
1337 1337
1338 def ChunkedServerHandler(self): 1338 def ChunkedServerHandler(self):
1339 """Send chunked response. Allows to specify chunks parameters: 1339 """Send chunked response. Allows to specify chunks parameters:
1340 - waitBeforeHeaders - ms to wait before sending headers 1340 - waitBeforeHeaders - ms to wait before sending headers
1341 - waitBetweenChunks - ms to wait between chunks 1341 - waitBetweenChunks - ms to wait between chunks
1342 - chunkSize - size of each chunk in bytes 1342 - chunkSize - size of each chunk in bytes
1343 - chunksNumber - number of chunks 1343 - chunksNumber - number of chunks
1344 Example: /chunked?waitBeforeHeaders=1000&chunkSize=5&chunksNumber=5 1344 Example: /chunked?waitBeforeHeaders=1000&chunkSize=5&chunksNumber=5
1345 waits one second, then sends headers and five chunks five bytes each.""" 1345 waits one second, then sends headers and five chunks five bytes each."""
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
2284 'OCSP response.') 2284 'OCSP response.')
2285 self.option_parser.add_option('--alert-after-handshake', 2285 self.option_parser.add_option('--alert-after-handshake',
2286 dest='alert_after_handshake', 2286 dest='alert_after_handshake',
2287 default=False, action='store_true', 2287 default=False, action='store_true',
2288 help='If set, the server will send a fatal ' 2288 help='If set, the server will send a fatal '
2289 'alert immediately after the handshake.') 2289 'alert immediately after the handshake.')
2290 2290
2291 2291
2292 if __name__ == '__main__': 2292 if __name__ == '__main__':
2293 sys.exit(ServerRunner().main()) 2293 sys.exit(ServerRunner().main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698