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

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

Issue 6881106: Treat ERR_CONNECTION_CLOSED as end-of-data marker for downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unit test. Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_stream_parser.cc ('k') | net/url_request/url_request_http_job.cc » ('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) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 12 matching lines...) Expand all
23 import re 23 import re
24 import select 24 import select
25 import simplejson 25 import simplejson
26 import SocketServer 26 import SocketServer
27 import socket 27 import socket
28 import sys 28 import sys
29 import struct 29 import struct
30 import time 30 import time
31 import urlparse 31 import urlparse
32 import warnings 32 import warnings
33 import zlib
33 34
34 # Ignore deprecation warnings, they make our output more cluttered. 35 # Ignore deprecation warnings, they make our output more cluttered.
35 warnings.filterwarnings("ignore", category=DeprecationWarning) 36 warnings.filterwarnings("ignore", category=DeprecationWarning)
36 37
37 import pyftpdlib.ftpserver 38 import pyftpdlib.ftpserver
38 import tlslite 39 import tlslite
39 import tlslite.api 40 import tlslite.api
40 41
41 try: 42 try:
42 import hashlib 43 import hashlib
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 self.CacheMustRevalidateHandler, 274 self.CacheMustRevalidateHandler,
274 self.CacheMustRevalidateMaxAgeHandler, 275 self.CacheMustRevalidateMaxAgeHandler,
275 self.CacheNoStoreHandler, 276 self.CacheNoStoreHandler,
276 self.CacheNoStoreMaxAgeHandler, 277 self.CacheNoStoreMaxAgeHandler,
277 self.CacheNoTransformHandler, 278 self.CacheNoTransformHandler,
278 self.DownloadHandler, 279 self.DownloadHandler,
279 self.DownloadFinishHandler, 280 self.DownloadFinishHandler,
280 self.EchoHeader, 281 self.EchoHeader,
281 self.EchoHeaderCache, 282 self.EchoHeaderCache,
282 self.EchoAllHandler, 283 self.EchoAllHandler,
284 self.ZipFileHandler,
283 self.FileHandler, 285 self.FileHandler,
284 self.SetCookieHandler, 286 self.SetCookieHandler,
285 self.AuthBasicHandler, 287 self.AuthBasicHandler,
286 self.AuthDigestHandler, 288 self.AuthDigestHandler,
287 self.SlowServerHandler, 289 self.SlowServerHandler,
288 self.ContentTypeHandler, 290 self.ContentTypeHandler,
289 self.NoContentHandler, 291 self.NoContentHandler,
290 self.ServerRedirectHandler, 292 self.ServerRedirectHandler,
291 self.ClientRedirectHandler, 293 self.ClientRedirectHandler,
292 self.MultipartHandler, 294 self.MultipartHandler,
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 if len(replace_text_args) != 2: 741 if len(replace_text_args) != 2:
740 raise ValueError( 742 raise ValueError(
741 'replace_text must be of form old_text:new_text. Actual value: %s' % 743 'replace_text must be of form old_text:new_text. Actual value: %s' %
742 replace_text_value) 744 replace_text_value)
743 old_text_b64, new_text_b64 = replace_text_args 745 old_text_b64, new_text_b64 = replace_text_args
744 old_text = base64.urlsafe_b64decode(old_text_b64) 746 old_text = base64.urlsafe_b64decode(old_text_b64)
745 new_text = base64.urlsafe_b64decode(new_text_b64) 747 new_text = base64.urlsafe_b64decode(new_text_b64)
746 data = data.replace(old_text, new_text) 748 data = data.replace(old_text, new_text)
747 return data 749 return data
748 750
751 def ZipFileHandler(self):
752 """This handler sends the contents of the requested file in compressed form.
753 Can pass in a parameter that specifies that the content length be
754 C - the compressed size (OK),
755 U - the uncompressed size (Non-standard, but handled),
756 S - less than compressed (OK because we keep going),
757 M - larger than compressed but less than uncompressed (an error),
758 L - larger than uncompressed (an error)
759 Example: downloads/Picture_1.doc?C
760 """
761
762 prefix = self.server.file_root_url
763 if not self.path.startswith(prefix):
764 return False
765
766 # Consume a request body if present.
767 if self.command == 'POST' or self.command == 'PUT' :
768 self.ReadRequestBody()
769
770 _, _, url_path, _, query, _ = urlparse.urlparse(self.path)
771
772 if not query in ('C', 'U', 'S', 'M', 'L'):
773 return False
774
775 sub_path = url_path[len(prefix):]
776 entries = sub_path.split('/')
777 file_path = os.path.join(self.server.data_dir, *entries)
778 if os.path.isdir(file_path):
779 file_path = os.path.join(file_path, 'index.html')
780
781 if not os.path.isfile(file_path):
782 print "File not found " + sub_path + " full path:" + file_path
783 self.send_error(404)
784 return True
785
786 f = open(file_path, "rb")
787 data = f.read()
788 uncompressed_len = len(data)
789 f.close()
790
791 # Compress the data.
792 data = zlib.compress(data)
793 compressed_len = len(data)
794
795 content_length = compressed_len
796 if query == 'U':
797 content_length = uncompressed_len
798 elif query == 'S':
799 content_length = compressed_len / 2
800 elif query == 'M':
801 content_length = (compressed_len + uncompressed_len) / 2
802 elif query == 'L':
803 content_length = compressed_len + uncompressed_len
804
805 self.send_response(200)
806 # self.send_header('Content-type', 'gzip')
ahendrickson 2011/05/22 06:43:34 Removing these commented-out lines . . .
807 ## self.send_header('Content-encoding', 'gzip')
808 self.send_header('Content-type', 'application/msword')
809 self.send_header('Content-encoding', 'deflate')
810 self.send_header('Connection', 'close')
811 self.send_header('Content-Length', content_length)
812 self.send_header('ETag', '\'' + file_path + '\'')
813 self.end_headers()
814
815 self.wfile.write(data)
816
817 return True
818
749 def FileHandler(self): 819 def FileHandler(self):
750 """This handler sends the contents of the requested file. Wow, it's like 820 """This handler sends the contents of the requested file. Wow, it's like
751 a real webserver!""" 821 a real webserver!"""
752 822
753 prefix = self.server.file_root_url 823 prefix = self.server.file_root_url
754 if not self.path.startswith(prefix): 824 if not self.path.startswith(prefix):
755 return False 825 return False
756 826
757 # Consume a request body if present. 827 # Consume a request body if present.
758 if self.command == 'POST' or self.command == 'PUT' : 828 if self.command == 'POST' or self.command == 'PUT' :
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 'random key if none is specified on the command ' 1565 'random key if none is specified on the command '
1496 'line.') 1566 'line.')
1497 option_parser.add_option('', '--policy-user', default='user@example.com', 1567 option_parser.add_option('', '--policy-user', default='user@example.com',
1498 dest='policy_user', 1568 dest='policy_user',
1499 help='Specify the user name the server should ' 1569 help='Specify the user name the server should '
1500 'report back to the client as the user owning the ' 1570 'report back to the client as the user owning the '
1501 'token used for making the policy request.') 1571 'token used for making the policy request.')
1502 options, args = option_parser.parse_args() 1572 options, args = option_parser.parse_args()
1503 1573
1504 sys.exit(main(options, args)) 1574 sys.exit(main(options, args))
OLDNEW
« no previous file with comments | « net/http/http_stream_parser.cc ('k') | net/url_request/url_request_http_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698