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

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

Issue 5141001: Add a PDF test to load all the pdfs in a test directory, using the test serve... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix race condition Created 10 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/plugin/pdf_browsertest.cc ('k') | 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 By default, it listens on an ephemeral port and sends the port number back to 9 By default, it listens on an ephemeral port and sends the port number back to
10 the originating process over a pipe. The originating process can specify an 10 the originating process over a pipe. The originating process can specify an
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 put_handlers = [ 214 put_handlers = [
215 self.EchoTitleHandler, 215 self.EchoTitleHandler,
216 self.EchoAllHandler, 216 self.EchoAllHandler,
217 self.EchoHandler] + get_handlers 217 self.EchoHandler] + get_handlers
218 218
219 self._mime_types = { 219 self._mime_types = {
220 'crx' : 'application/x-chrome-extension', 220 'crx' : 'application/x-chrome-extension',
221 'gif': 'image/gif', 221 'gif': 'image/gif',
222 'jpeg' : 'image/jpeg', 222 'jpeg' : 'image/jpeg',
223 'jpg' : 'image/jpeg', 223 'jpg' : 'image/jpeg',
224 'xml' : 'text/xml' 224 'xml' : 'text/xml',
225 'pdf' : 'application/pdf'
225 } 226 }
226 self._default_mime_type = 'text/html' 227 self._default_mime_type = 'text/html'
227 228
228 BasePageHandler.__init__(self, request, client_address, socket_server, 229 BasePageHandler.__init__(self, request, client_address, socket_server,
229 connect_handlers, get_handlers, post_handlers, 230 connect_handlers, get_handlers, post_handlers,
230 put_handlers) 231 put_handlers)
231 232
232 def GetMIMETypeFromName(self, file_name): 233 def GetMIMETypeFromName(self, file_name):
233 """Returns the mime type for the specified file_name. So far it only looks 234 """Returns the mime type for the specified file_name. So far it only looks
234 at the file extension.""" 235 at the file extension."""
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 for line in f: 692 for line in f:
692 header_values = re.findall('(\S+):\s*(.*)', line) 693 header_values = re.findall('(\S+):\s*(.*)', line)
693 if len(header_values) > 0: 694 if len(header_values) > 0:
694 # "name: value" 695 # "name: value"
695 name, value = header_values[0] 696 name, value = header_values[0]
696 self.send_header(name, value) 697 self.send_header(name, value)
697 f.close() 698 f.close()
698 else: 699 else:
699 # Could be more generic once we support mime-type sniffing, but for 700 # Could be more generic once we support mime-type sniffing, but for
700 # now we need to set it explicitly. 701 # now we need to set it explicitly.
701 self.send_response(200) 702
703 range = self.headers.get('Range')
704 if range and range.startswith('bytes='):
705 # Note this doesn't handle all valid byte range values (i.e. open ended
706 # ones), just enough for what we needed so far.
707 range = range[6:].split('-')
708 start = int(range[0])
709 end = int(range[1])
710
711 self.send_response(206)
712 content_range = 'bytes ' + str(start) + '-' + str(end) + '/' + \
713 str(len(data))
714 self.send_header('Content-Range', content_range)
715 data = data[start: end + 1]
716 else:
717 self.send_response(200)
718
702 self.send_header('Content-type', self.GetMIMETypeFromName(file_path)) 719 self.send_header('Content-type', self.GetMIMETypeFromName(file_path))
720 self.send_header('Accept-Ranges', 'bytes')
703 self.send_header('Content-Length', len(data)) 721 self.send_header('Content-Length', len(data))
722 self.send_header('ETag', '\'' + file_path + '\'')
704 self.end_headers() 723 self.end_headers()
705 724
706 self.wfile.write(data) 725 self.wfile.write(data)
707 726
708 return True 727 return True
709 728
710 def RealFileWithCommonHeaderHandler(self): 729 def RealFileWithCommonHeaderHandler(self):
711 """This handler sends the contents of the requested file without the pseudo 730 """This handler sends the contents of the requested file without the pseudo
712 http head!""" 731 http head!"""
713 732
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 'option may appear multiple times, indicating ' 1374 'option may appear multiple times, indicating '
1356 'multiple algorithms should be enabled.'); 1375 'multiple algorithms should be enabled.');
1357 option_parser.add_option('', '--file-root-url', default='/files/', 1376 option_parser.add_option('', '--file-root-url', default='/files/',
1358 help='Specify a root URL for files served.') 1377 help='Specify a root URL for files served.')
1359 option_parser.add_option('', '--startup-pipe', type='int', 1378 option_parser.add_option('', '--startup-pipe', type='int',
1360 dest='startup_pipe', 1379 dest='startup_pipe',
1361 help='File handle of pipe to parent process') 1380 help='File handle of pipe to parent process')
1362 options, args = option_parser.parse_args() 1381 options, args = option_parser.parse_args()
1363 1382
1364 sys.exit(main(options, args)) 1383 sys.exit(main(options, args))
OLDNEW
« no previous file with comments | « chrome/test/plugin/pdf_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698