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

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: '' 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
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='):
cbentzel 2010/11/17 03:02:01 Maybe a quick comment that this doesn't handle all
jam 2010/11/17 04:10:10 Done.
705 range = range[6:].split('-')
706 start = int(range[0])
707 end = int(range[1])
708
709 self.send_response(206)
710 content_range = 'bytes ' + str(start) + '-' + str(end) + '/' + \
711 str(len(data))
712 self.send_header('Content-Range', content_range)
713 data = data[start: end + 1]
714 else:
715 self.send_response(200)
716
702 self.send_header('Content-type', self.GetMIMETypeFromName(file_path)) 717 self.send_header('Content-type', self.GetMIMETypeFromName(file_path))
718 self.send_header('Accept-Ranges', 'bytes')
703 self.send_header('Content-Length', len(data)) 719 self.send_header('Content-Length', len(data))
720 self.send_header('ETag', '\'' + file_path + '\'')
cbentzel 2010/11/17 03:02:01 Why did etag need to be added?
jam 2010/11/17 04:10:10 the cache code needs it
704 self.end_headers() 721 self.end_headers()
705 722
706 self.wfile.write(data) 723 self.wfile.write(data)
707 724
708 return True 725 return True
709 726
710 def RealFileWithCommonHeaderHandler(self): 727 def RealFileWithCommonHeaderHandler(self):
711 """This handler sends the contents of the requested file without the pseudo 728 """This handler sends the contents of the requested file without the pseudo
712 http head!""" 729 http head!"""
713 730
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 'option may appear multiple times, indicating ' 1372 'option may appear multiple times, indicating '
1356 'multiple algorithms should be enabled.'); 1373 'multiple algorithms should be enabled.');
1357 option_parser.add_option('', '--file-root-url', default='/files/', 1374 option_parser.add_option('', '--file-root-url', default='/files/',
1358 help='Specify a root URL for files served.') 1375 help='Specify a root URL for files served.')
1359 option_parser.add_option('', '--startup-pipe', type='int', 1376 option_parser.add_option('', '--startup-pipe', type='int',
1360 dest='startup_pipe', 1377 dest='startup_pipe',
1361 help='File handle of pipe to parent process') 1378 help='File handle of pipe to parent process')
1362 options, args = option_parser.parse_args() 1379 options, args = option_parser.parse_args()
1363 1380
1364 sys.exit(main(options, args)) 1381 sys.exit(main(options, args))
OLDNEW
« chrome/test/plugin/pdf_browsertest.cc ('K') | « chrome/test/plugin/pdf_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698