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

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

Issue 2881028: GTTF: test server cleanup: (Closed)
Patch Set: final Created 10 years, 5 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 | « net/tools/testserver/run_testserver.cc ('k') | net/url_request/url_request_unittest.h » ('j') | 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/python2.4 1 #!/usr/bin/python2.4
2 # Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2010 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 server used for testing Chrome. 6 """This is a simple HTTP server used for testing Chrome.
7 7
8 It supports several test URLs, as specified by the handlers in TestPageHandler. 8 It supports several test URLs, as specified by the handlers in TestPageHandler.
9 It defaults to living on localhost:8888. 9 It defaults to living on localhost:8888.
10 It can use https if you specify the flag --https=CERT where CERT is the path 10 It can use https if you specify the flag --https=CERT where CERT is the path
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 try: 75 try:
76 tlsConnection.handshakeServer(certChain=self.cert_chain, 76 tlsConnection.handshakeServer(certChain=self.cert_chain,
77 privateKey=self.private_key, 77 privateKey=self.private_key,
78 sessionCache=self.session_cache) 78 sessionCache=self.session_cache)
79 tlsConnection.ignoreAbruptClose = True 79 tlsConnection.ignoreAbruptClose = True
80 return True 80 return True
81 except tlslite.api.TLSError, error: 81 except tlslite.api.TLSError, error:
82 print "Handshake failure:", str(error) 82 print "Handshake failure:", str(error)
83 return False 83 return False
84 84
85 class ForkingHTTPServer(SocketServer.ForkingMixIn, StoppableHTTPServer):
86 """This is a specialization of of StoppableHTTPServer which serves each
87 request in a separate process"""
88 pass
89
90 class ForkingHTTPSServer(SocketServer.ForkingMixIn, HTTPSServer):
91 """This is a specialization of of HTTPSServer which serves each
92 request in a separate process"""
93 pass
94
95 class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler): 85 class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
96 86
97 def __init__(self, request, client_address, socket_server): 87 def __init__(self, request, client_address, socket_server):
98 self._connect_handlers = [ 88 self._connect_handlers = [
99 self.RedirectConnectHandler, 89 self.RedirectConnectHandler,
100 self.ServerAuthConnectHandler, 90 self.ServerAuthConnectHandler,
101 self.DefaultConnectResponseHandler] 91 self.DefaultConnectResponseHandler]
102 self._get_handlers = [ 92 self._get_handlers = [
103 self.KillHandler, 93 self.KillHandler,
104 self.NoCacheMaxAgeTimeHandler, 94 self.NoCacheMaxAgeTimeHandler,
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 1183
1194 # Try to free up the port if there's an orphaned old instance. 1184 # Try to free up the port if there's an orphaned old instance.
1195 TryKillingOldServer(port) 1185 TryKillingOldServer(port)
1196 1186
1197 if options.server_type == SERVER_HTTP: 1187 if options.server_type == SERVER_HTTP:
1198 if options.cert: 1188 if options.cert:
1199 # let's make sure the cert file exists. 1189 # let's make sure the cert file exists.
1200 if not os.path.isfile(options.cert): 1190 if not os.path.isfile(options.cert):
1201 print 'specified cert file not found: ' + options.cert + ' exiting...' 1191 print 'specified cert file not found: ' + options.cert + ' exiting...'
1202 return 1192 return
1203 if options.forking: 1193 server = HTTPSServer(('127.0.0.1', port), TestPageHandler, options.cert)
1204 server_class = ForkingHTTPSServer
1205 else:
1206 server_class = HTTPSServer
1207 server = server_class(('127.0.0.1', port), TestPageHandler, options.cert)
1208 print 'HTTPS server started on port %d...' % port 1194 print 'HTTPS server started on port %d...' % port
1209 else: 1195 else:
1210 if options.forking: 1196 server = StoppableHTTPServer(('127.0.0.1', port), TestPageHandler)
1211 server_class = ForkingHTTPServer
1212 else:
1213 server_class = StoppableHTTPServer
1214 server = server_class(('127.0.0.1', port), TestPageHandler)
1215 print 'HTTP server started on port %d...' % port 1197 print 'HTTP server started on port %d...' % port
1216 1198
1217 server.data_dir = MakeDataDir() 1199 server.data_dir = MakeDataDir()
1218 server.file_root_url = options.file_root_url 1200 server.file_root_url = options.file_root_url
1219 MakeDumpDir(server.data_dir) 1201 MakeDumpDir(server.data_dir)
1220 1202
1221 # means FTP Server 1203 # means FTP Server
1222 else: 1204 else:
1223 my_data_dir = MakeDataDir() 1205 my_data_dir = MakeDataDir()
1224 1206
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 except KeyboardInterrupt: 1238 except KeyboardInterrupt:
1257 print 'shutting down server' 1239 print 'shutting down server'
1258 server.stop = True 1240 server.stop = True
1259 1241
1260 if __name__ == '__main__': 1242 if __name__ == '__main__':
1261 option_parser = optparse.OptionParser() 1243 option_parser = optparse.OptionParser()
1262 option_parser.add_option("-f", '--ftp', action='store_const', 1244 option_parser.add_option("-f", '--ftp', action='store_const',
1263 const=SERVER_FTP, default=SERVER_HTTP, 1245 const=SERVER_FTP, default=SERVER_HTTP,
1264 dest='server_type', 1246 dest='server_type',
1265 help='FTP or HTTP server: default is HTTP.') 1247 help='FTP or HTTP server: default is HTTP.')
1266 option_parser.add_option('--forking', action='store_true', default=False,
1267 dest='forking',
1268 help='Serve each request in a separate process.')
1269 option_parser.add_option('', '--port', default='8888', type='int', 1248 option_parser.add_option('', '--port', default='8888', type='int',
1270 help='Port used by the server.') 1249 help='Port used by the server.')
1271 option_parser.add_option('', '--data-dir', dest='data_dir', 1250 option_parser.add_option('', '--data-dir', dest='data_dir',
1272 help='Directory from which to read the files.') 1251 help='Directory from which to read the files.')
1273 option_parser.add_option('', '--https', dest='cert', 1252 option_parser.add_option('', '--https', dest='cert',
1274 help='Specify that https should be used, specify ' 1253 help='Specify that https should be used, specify '
1275 'the path to the cert containing the private key ' 1254 'the path to the cert containing the private key '
1276 'the server should use.') 1255 'the server should use.')
1277 option_parser.add_option('', '--file-root-url', default='/files/', 1256 option_parser.add_option('', '--file-root-url', default='/files/',
1278 help='Specify a root URL for files served.') 1257 help='Specify a root URL for files served.')
1279 option_parser.add_option('', '--never-die', default=False, 1258 option_parser.add_option('', '--never-die', default=False,
1280 action="store_true", 1259 action="store_true",
1281 help='Prevent the server from dying when visiting ' 1260 help='Prevent the server from dying when visiting '
1282 'a /kill URL. Useful for manually running some ' 1261 'a /kill URL. Useful for manually running some '
1283 'tests.') 1262 'tests.')
1284 options, args = option_parser.parse_args() 1263 options, args = option_parser.parse_args()
1285 1264
1286 sys.exit(main(options, args)) 1265 sys.exit(main(options, args))
OLDNEW
« no previous file with comments | « net/tools/testserver/run_testserver.cc ('k') | net/url_request/url_request_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698