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

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

Issue 3014036: Allow testserver to run without chromiumsync. (Closed)
Patch Set: 80 char 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 | « 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/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 10 matching lines...) Expand all
21 import shutil 21 import shutil
22 import SocketServer 22 import SocketServer
23 import sys 23 import sys
24 import time 24 import time
25 import urllib2 25 import urllib2
26 26
27 import pyftpdlib.ftpserver 27 import pyftpdlib.ftpserver
28 import tlslite 28 import tlslite
29 import tlslite.api 29 import tlslite.api
30 30
31 import chromiumsync
32
33 try: 31 try:
34 import hashlib 32 import hashlib
35 _new_md5 = hashlib.md5 33 _new_md5 = hashlib.md5
36 except ImportError: 34 except ImportError:
37 import md5 35 import md5
38 _new_md5 = md5.new 36 _new_md5 = md5.new
39 37
40 SERVER_HTTP = 0 38 SERVER_HTTP = 0
41 SERVER_FTP = 1 39 SERVER_FTP = 1
42 40
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 'gif': 'image/gif', 136 'gif': 'image/gif',
139 'jpeg' : 'image/jpeg', 137 'jpeg' : 'image/jpeg',
140 'jpg' : 'image/jpeg', 138 'jpg' : 'image/jpeg',
141 'xml' : 'text/xml' 139 'xml' : 'text/xml'
142 } 140 }
143 self._default_mime_type = 'text/html' 141 self._default_mime_type = 'text/html'
144 142
145 BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, request, 143 BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, request,
146 client_address, 144 client_address,
147 socket_server) 145 socket_server)
148 # Class variable; shared across requests.
149 _sync_handler = chromiumsync.TestServer()
150 146
151 def _ShouldHandleRequest(self, handler_name): 147 def _ShouldHandleRequest(self, handler_name):
152 """Determines if the path can be handled by the handler. 148 """Determines if the path can be handled by the handler.
153 149
154 We consider a handler valid if the path begins with the 150 We consider a handler valid if the path begins with the
155 handler name. It can optionally be followed by "?*", "/*". 151 handler name. It can optionally be followed by "?*", "/*".
156 """ 152 """
157 153
158 pattern = re.compile('%s($|\?|/).*' % handler_name) 154 pattern = re.compile('%s($|\?|/).*' % handler_name)
159 return pattern.match(self.path) 155 return pattern.match(self.path)
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 This covers all sync protocol commands: authentication, getupdates, and 1010 This covers all sync protocol commands: authentication, getupdates, and
1015 commit. 1011 commit.
1016 """ 1012 """
1017 test_name = "/chromiumsync/command" 1013 test_name = "/chromiumsync/command"
1018 if not self._ShouldHandleRequest(test_name): 1014 if not self._ShouldHandleRequest(test_name):
1019 return False 1015 return False
1020 1016
1021 length = int(self.headers.getheader('content-length')) 1017 length = int(self.headers.getheader('content-length'))
1022 raw_request = self.rfile.read(length) 1018 raw_request = self.rfile.read(length)
1023 1019
1024 http_response, raw_reply = self._sync_handler.HandleCommand(raw_request) 1020 if not self.server._sync_handler:
1021 import chromiumsync
1022 self.server._sync_handler = chromiumsync.TestServer()
1023 http_response, raw_reply = self.server._sync_handler.HandleCommand(
1024 raw_request)
1025 self.send_response(http_response) 1025 self.send_response(http_response)
1026 self.end_headers() 1026 self.end_headers()
1027 self.wfile.write(raw_reply) 1027 self.wfile.write(raw_reply)
1028 return True 1028 return True
1029 1029
1030 def MultipartHandler(self): 1030 def MultipartHandler(self):
1031 """Send a multipart response (10 text/html pages).""" 1031 """Send a multipart response (10 text/html pages)."""
1032 test_name = "/multipart" 1032 test_name = "/multipart"
1033 if not self._ShouldHandleRequest(test_name): 1033 if not self._ShouldHandleRequest(test_name):
1034 return False 1034 return False
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 print 'specified cert file not found: ' + options.cert + ' exiting...' 1191 print 'specified cert file not found: ' + options.cert + ' exiting...'
1192 return 1192 return
1193 server = HTTPSServer(('127.0.0.1', port), TestPageHandler, options.cert) 1193 server = HTTPSServer(('127.0.0.1', port), TestPageHandler, options.cert)
1194 print 'HTTPS server started on port %d...' % port 1194 print 'HTTPS server started on port %d...' % port
1195 else: 1195 else:
1196 server = StoppableHTTPServer(('127.0.0.1', port), TestPageHandler) 1196 server = StoppableHTTPServer(('127.0.0.1', port), TestPageHandler)
1197 print 'HTTP server started on port %d...' % port 1197 print 'HTTP server started on port %d...' % port
1198 1198
1199 server.data_dir = MakeDataDir() 1199 server.data_dir = MakeDataDir()
1200 server.file_root_url = options.file_root_url 1200 server.file_root_url = options.file_root_url
1201 server._sync_handler = None
1202
1201 MakeDumpDir(server.data_dir) 1203 MakeDumpDir(server.data_dir)
1202 1204
1203 # means FTP Server 1205 # means FTP Server
1204 else: 1206 else:
1205 my_data_dir = MakeDataDir() 1207 my_data_dir = MakeDataDir()
1206 1208
1207 def line_logger(msg): 1209 def line_logger(msg):
1208 if (msg.find("kill") >= 0): 1210 if (msg.find("kill") >= 0):
1209 server.stop = True 1211 server.stop = True
1210 print 'shutting down server' 1212 print 'shutting down server'
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 option_parser.add_option('', '--file-root-url', default='/files/', 1258 option_parser.add_option('', '--file-root-url', default='/files/',
1257 help='Specify a root URL for files served.') 1259 help='Specify a root URL for files served.')
1258 option_parser.add_option('', '--never-die', default=False, 1260 option_parser.add_option('', '--never-die', default=False,
1259 action="store_true", 1261 action="store_true",
1260 help='Prevent the server from dying when visiting ' 1262 help='Prevent the server from dying when visiting '
1261 'a /kill URL. Useful for manually running some ' 1263 'a /kill URL. Useful for manually running some '
1262 'tests.') 1264 'tests.')
1263 options, args = option_parser.parse_args() 1265 options, args = option_parser.parse_args()
1264 1266
1265 sys.exit(main(options, args)) 1267 sys.exit(main(options, args))
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