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

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

Issue 21158: Fix a logic error in the handling the response to an HTTP... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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_response_headers.h ('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) 2006-2008 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2008 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 sessionCache=self.session_cache) 68 sessionCache=self.session_cache)
69 tlsConnection.ignoreAbruptClose = True 69 tlsConnection.ignoreAbruptClose = True
70 return True 70 return True
71 except tlslite.api.TLSError, error: 71 except tlslite.api.TLSError, error:
72 print "Handshake failure:", str(error) 72 print "Handshake failure:", str(error)
73 return False 73 return False
74 74
75 class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler): 75 class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
76 76
77 def __init__(self, request, client_address, socket_server): 77 def __init__(self, request, client_address, socket_server):
78 self._connect_handlers = [
79 self.RedirectConnectHandler,
80 self.DefaultConnectResponseHandler]
78 self._get_handlers = [ 81 self._get_handlers = [
79 self.KillHandler, 82 self.KillHandler,
80 self.NoCacheMaxAgeTimeHandler, 83 self.NoCacheMaxAgeTimeHandler,
81 self.NoCacheTimeHandler, 84 self.NoCacheTimeHandler,
82 self.CacheTimeHandler, 85 self.CacheTimeHandler,
83 self.CacheExpiresHandler, 86 self.CacheExpiresHandler,
84 self.CacheProxyRevalidateHandler, 87 self.CacheProxyRevalidateHandler,
85 self.CachePrivateHandler, 88 self.CachePrivateHandler,
86 self.CachePublicHandler, 89 self.CachePublicHandler,
87 self.CacheSMaxAgeHandler, 90 self.CacheSMaxAgeHandler,
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 return True 850 return True
848 dest = self.path[query_char + 1:] 851 dest = self.path[query_char + 1:]
849 852
850 self.send_response(301) # moved permanently 853 self.send_response(301) # moved permanently
851 self.send_header('Location', dest) 854 self.send_header('Location', dest)
852 self.send_header('Content-type', 'text/html') 855 self.send_header('Content-type', 'text/html')
853 self.end_headers() 856 self.end_headers()
854 self.wfile.write('<html><head>') 857 self.wfile.write('<html><head>')
855 self.wfile.write('</head><body>Redirecting to %s</body></html>' % dest) 858 self.wfile.write('</head><body>Redirecting to %s</body></html>' % dest)
856 859
857 return True; 860 return True
858 861
859 def ClientRedirectHandler(self): 862 def ClientRedirectHandler(self):
860 """Sends a client redirect to the given URL. The syntax is 863 """Sends a client redirect to the given URL. The syntax is
861 '/client-redirect?http://foo.bar/asdf' to redirect to 'http://foo.bar/asdf'" "" 864 '/client-redirect?http://foo.bar/asdf' to redirect to 'http://foo.bar/asdf'" ""
862 865
863 test_name = "/client-redirect" 866 test_name = "/client-redirect"
864 if not self._ShouldHandleRequest(test_name): 867 if not self._ShouldHandleRequest(test_name):
865 return False 868 return False
866 869
867 query_char = self.path.find('?'); 870 query_char = self.path.find('?');
(...skipping 18 matching lines...) Expand all
886 is not closed properly (and the browser keeps expecting data).""" 889 is not closed properly (and the browser keeps expecting data)."""
887 890
888 contents = "Default response given for path: " + self.path 891 contents = "Default response given for path: " + self.path
889 self.send_response(200) 892 self.send_response(200)
890 self.send_header('Content-type', 'text/html') 893 self.send_header('Content-type', 'text/html')
891 self.send_header("Content-Length", len(contents)) 894 self.send_header("Content-Length", len(contents))
892 self.end_headers() 895 self.end_headers()
893 self.wfile.write(contents) 896 self.wfile.write(contents)
894 return True 897 return True
895 898
899 def RedirectConnectHandler(self):
900 """Sends a redirect to the CONNECT request for www.redirect.com. This
901 response is not specified by the RFC, so the browser should not follow
902 the redirect."""
903
904 if (self.path.find("www.redirect.com") < 0):
905 return False
906
907 dest = "http://www.destination.com/foo.js"
908
909 self.send_response(302) # moved temporarily
910 self.send_header('Location', dest)
911 self.send_header('Connection', 'close')
912 self.end_headers()
913 return True
914
915
916 def DefaultConnectResponseHandler(self):
917 """This is the catch-all response handler for CONNECT requests that aren't
918 handled by one of the special handlers above. Real Web servers respond
919 with 400 to CONNECT requests."""
920
921 contents = "Your client has issued a malformed or illegal request."
922 self.send_response(400) # bad request
923 self.send_header('Content-type', 'text/html')
924 self.send_header("Content-Length", len(contents))
925 self.end_headers()
926 self.wfile.write(contents)
927 return True
928
929 def do_CONNECT(self):
930 for handler in self._connect_handlers:
931 if handler():
932 return
933
896 def do_GET(self): 934 def do_GET(self):
897 for handler in self._get_handlers: 935 for handler in self._get_handlers:
898 if handler(): 936 if handler():
899 return 937 return
900 938
901 def do_POST(self): 939 def do_POST(self):
902 for handler in self._post_handlers: 940 for handler in self._post_handlers:
903 if handler(): 941 if handler():
904 return 942 return
905 943
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 help='Port used by the server') 1046 help='Port used by the server')
1009 option_parser.add_option('', '--data-dir', dest='data_dir', 1047 option_parser.add_option('', '--data-dir', dest='data_dir',
1010 help='Directory from which to read the files') 1048 help='Directory from which to read the files')
1011 option_parser.add_option('', '--https', dest='cert', 1049 option_parser.add_option('', '--https', dest='cert',
1012 help='Specify that https should be used, specify ' 1050 help='Specify that https should be used, specify '
1013 'the path to the cert containing the private key ' 1051 'the path to the cert containing the private key '
1014 'the server should use') 1052 'the server should use')
1015 options, args = option_parser.parse_args() 1053 options, args = option_parser.parse_args()
1016 1054
1017 sys.exit(main(options, args)) 1055 sys.exit(main(options, args))
1018 1056
OLDNEW
« no previous file with comments | « net/http/http_response_headers.h ('k') | net/url_request/url_request_http_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698