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

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

Issue 8203005: Implement chrome.experimental.downloads.onChanged (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: re-disable apitest on mac -- see 9392013 Created 8 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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/FTP/SYNC/TCP/UDP/ server used for testing Chrome. 6 """This is a simple HTTP/FTP/SYNC/TCP/UDP/ 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 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 self.wfile.write(data) 901 self.wfile.write(data)
902 902
903 return True 903 return True
904 904
905 def FileHandler(self): 905 def FileHandler(self):
906 """This handler sends the contents of the requested file. Wow, it's like 906 """This handler sends the contents of the requested file. Wow, it's like
907 a real webserver!""" 907 a real webserver!"""
908 prefix = self.server.file_root_url 908 prefix = self.server.file_root_url
909 if not self.path.startswith(prefix): 909 if not self.path.startswith(prefix):
910 return False 910 return False
911 # Consume a request body if present.
912 if self.command == 'POST' or self.command == 'PUT' :
913 self.ReadRequestBody()
914 return self._FileHandlerHelper(prefix) 911 return self._FileHandlerHelper(prefix)
915 912
916 def PostOnlyFileHandler(self): 913 def PostOnlyFileHandler(self):
917 """This handler sends the contents of the requested file on a POST.""" 914 """This handler sends the contents of the requested file on a POST."""
918 prefix = urlparse.urljoin(self.server.file_root_url, 'post/') 915 prefix = urlparse.urljoin(self.server.file_root_url, 'post/')
919 if not self.path.startswith(prefix): 916 if not self.path.startswith(prefix):
920 return False 917 return False
921 self.ReadRequestBody()
922 return self._FileHandlerHelper(prefix) 918 return self._FileHandlerHelper(prefix)
923 919
924 def _FileHandlerHelper(self, prefix): 920 def _FileHandlerHelper(self, prefix):
921 request_body = ''
922 if self.command == 'POST' or self.command == 'PUT':
923 # Consume a request body if present.
924 request_body = self.ReadRequestBody()
925
925 _, _, url_path, _, query, _ = urlparse.urlparse(self.path) 926 _, _, url_path, _, query, _ = urlparse.urlparse(self.path)
927 query_dict = cgi.parse_qs(query)
928
929 expected_body = query_dict.get('expected_body', [])
930 if expected_body and request_body not in expected_body:
931 self.send_response(404)
932 self.end_headers()
933 self.wfile.write('')
934 return True
935
936 expected_headers = query_dict.get('expected_headers', [])
937 for expected_header in expected_headers:
938 header_name, expected_value = expected_header.split(':')
939 if self.headers.getheader(header_name) != expected_value:
940 self.send_response(404)
941 self.end_headers()
942 self.wfile.write('')
943 return True
944
926 sub_path = url_path[len(prefix):] 945 sub_path = url_path[len(prefix):]
927 entries = sub_path.split('/') 946 entries = sub_path.split('/')
928 file_path = os.path.join(self.server.data_dir, *entries) 947 file_path = os.path.join(self.server.data_dir, *entries)
929 if os.path.isdir(file_path): 948 if os.path.isdir(file_path):
930 file_path = os.path.join(file_path, 'index.html') 949 file_path = os.path.join(file_path, 'index.html')
931 950
932 if not os.path.isfile(file_path): 951 if not os.path.isfile(file_path):
933 print "File not found " + sub_path + " full path:" + file_path 952 print "File not found " + sub_path + " full path:" + file_path
934 self.send_error(404) 953 self.send_error(404)
935 return True 954 return True
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 'random key if none is specified on the command ' 2024 'random key if none is specified on the command '
2006 'line.') 2025 'line.')
2007 option_parser.add_option('', '--policy-user', default='user@example.com', 2026 option_parser.add_option('', '--policy-user', default='user@example.com',
2008 dest='policy_user', 2027 dest='policy_user',
2009 help='Specify the user name the server should ' 2028 help='Specify the user name the server should '
2010 'report back to the client as the user owning the ' 2029 'report back to the client as the user owning the '
2011 'token used for making the policy request.') 2030 'token used for making the policy request.')
2012 options, args = option_parser.parse_args() 2031 options, args = option_parser.parse_args()
2013 2032
2014 sys.exit(main(options, args)) 2033 sys.exit(main(options, args))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698