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

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

Issue 10879029: reland: Launch pywebsocket via net::TestServer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for review Created 8 years, 3 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
11 explicit port if necessary. 11 explicit port if necessary.
12 It can use https if you specify the flag --https=CERT where CERT is the path 12 It can use https if you specify the flag --https=CERT where CERT is the path
13 to a pem file containing the certificate and private key that should be used. 13 to a pem file containing the certificate and private key that should be used.
14 """ 14 """
15 15
16 import asyncore 16 import asyncore
17 import base64 17 import base64
18 import BaseHTTPServer 18 import BaseHTTPServer
19 import cgi 19 import cgi
20 import errno 20 import errno
21 import httplib 21 import httplib
22 import logging
22 import minica 23 import minica
23 import optparse 24 import optparse
24 import os 25 import os
25 import random 26 import random
26 import re 27 import re
27 import select 28 import select
28 import socket 29 import socket
29 import SocketServer 30 import SocketServer
30 import struct 31 import struct
31 import sys 32 import sys
32 import threading 33 import threading
33 import time 34 import time
34 import urllib 35 import urllib
35 import urlparse 36 import urlparse
36 import warnings 37 import warnings
37 import zlib 38 import zlib
38 39
39 # Ignore deprecation warnings, they make our output more cluttered. 40 # Ignore deprecation warnings, they make our output more cluttered.
40 warnings.filterwarnings("ignore", category=DeprecationWarning) 41 warnings.filterwarnings("ignore", category=DeprecationWarning)
41 42
42 import echo_message 43 import echo_message
44 from mod_pywebsocket.standalone import WebSocketServer
43 import pyftpdlib.ftpserver 45 import pyftpdlib.ftpserver
44 import tlslite 46 import tlslite
45 import tlslite.api 47 import tlslite.api
46 48
47 try: 49 try:
48 import hashlib 50 import hashlib
49 _new_md5 = hashlib.md5 51 _new_md5 = hashlib.md5
50 except ImportError: 52 except ImportError:
51 import md5 53 import md5
52 _new_md5 = md5.new 54 _new_md5 = md5.new
53 55
54 try: 56 try:
55 import json 57 import json
56 except ImportError: 58 except ImportError:
57 import simplejson as json 59 import simplejson as json
58 60
59 if sys.platform == 'win32': 61 if sys.platform == 'win32':
60 import msvcrt 62 import msvcrt
61 63
62 SERVER_HTTP = 0 64 SERVER_HTTP = 0
63 SERVER_FTP = 1 65 SERVER_FTP = 1
64 SERVER_SYNC = 2 66 SERVER_SYNC = 2
65 SERVER_TCP_ECHO = 3 67 SERVER_TCP_ECHO = 3
66 SERVER_UDP_ECHO = 4 68 SERVER_UDP_ECHO = 4
69 SERVER_WEBSOCKET = 5
70
71 # Default request queue size for WebSocketServer.
72 _DEFAULT_REQUEST_QUEUE_SIZE = 128
67 73
68 # Using debug() seems to cause hangs on XP: see http://crbug.com/64515 . 74 # Using debug() seems to cause hangs on XP: see http://crbug.com/64515 .
69 debug_output = sys.stderr 75 debug_output = sys.stderr
70 def debug(str): 76 def debug(str):
71 debug_output.write(str + "\n") 77 debug_output.write(str + "\n")
72 debug_output.flush() 78 debug_output.flush()
73 79
80 class WebSocketOptions:
81 """Holds options for WebSocketServer."""
82
83 def __init__(self, host, port, data_dir):
84 self.request_queue_size = _DEFAULT_REQUEST_QUEUE_SIZE
85 self.server_host = host
86 self.port = port
87 self.websock_handlers = data_dir
88 self.scan_dir = None
89 self.allow_handlers_outside_root_dir = False
90 self.websock_handlers_map_file = None
91 self.cgi_directories = []
92 self.is_executable_method = None
93 self.allow_draft75 = False
94 self.strict = True
95
96 # TODO(toyoshim): Support SSL and authenticates (http://crbug.com/137639)
97 self.use_tls = False
98 self.private_key = None
99 self.certificate = None
100 self.tls_client_ca = None
101 self.use_basic_auth = False
102
74 class RecordingSSLSessionCache(object): 103 class RecordingSSLSessionCache(object):
75 """RecordingSSLSessionCache acts as a TLS session cache and maintains a log of 104 """RecordingSSLSessionCache acts as a TLS session cache and maintains a log of
76 lookups and inserts in order to test session cache behaviours.""" 105 lookups and inserts in order to test session cache behaviours."""
77 106
78 def __init__(self): 107 def __init__(self):
79 self.log = [] 108 self.log = []
80 109
81 def __getitem__(self, sessionID): 110 def __getitem__(self, sessionID):
82 self.log.append(('lookup', sessionID)) 111 self.log.append(('lookup', sessionID))
83 raise KeyError() 112 raise KeyError()
(...skipping 2025 matching lines...) Expand 10 before | Expand all | Expand 10 after
2109 server = HTTPServer((host, port), TestPageHandler) 2138 server = HTTPServer((host, port), TestPageHandler)
2110 print 'HTTP server started on %s:%d...' % (host, server.server_port) 2139 print 'HTTP server started on %s:%d...' % (host, server.server_port)
2111 2140
2112 server.data_dir = MakeDataDir() 2141 server.data_dir = MakeDataDir()
2113 server.file_root_url = options.file_root_url 2142 server.file_root_url = options.file_root_url
2114 server_data['port'] = server.server_port 2143 server_data['port'] = server.server_port
2115 server._device_management_handler = None 2144 server._device_management_handler = None
2116 server.policy_keys = options.policy_keys 2145 server.policy_keys = options.policy_keys
2117 server.policy_user = options.policy_user 2146 server.policy_user = options.policy_user
2118 server.gdata_auth_token = options.auth_token 2147 server.gdata_auth_token = options.auth_token
2148 elif options.server_type == SERVER_WEBSOCKET:
2149 # Launch pywebsocket via WebSocketServer.
2150 logger = logging.getLogger()
2151 logger.addHandler(logging.StreamHandler())
2152 os.chdir(MakeDataDir())
Ryan Sleevi 2012/08/30 02:54:15 This strikes me as a little odd, just because it's
Takashi Toyoshima 2012/08/31 17:38:20 This is pywebsocket specific requirement. It need
2153 server = WebSocketServer(WebSocketOptions(host, port, MakeDataDir()))
2154 print 'WebSocket server started on %s:%d...' % (host, server.server_port)
2155 server_data['port'] = server.server_port
2119 elif options.server_type == SERVER_SYNC: 2156 elif options.server_type == SERVER_SYNC:
2120 xmpp_port = options.xmpp_port 2157 xmpp_port = options.xmpp_port
2121 server = SyncHTTPServer((host, port), xmpp_port, SyncPageHandler) 2158 server = SyncHTTPServer((host, port), xmpp_port, SyncPageHandler)
2122 print 'Sync HTTP server started on port %d...' % server.server_port 2159 print 'Sync HTTP server started on port %d...' % server.server_port
2123 print 'Sync XMPP server started on port %d...' % server.xmpp_port 2160 print 'Sync XMPP server started on port %d...' % server.xmpp_port
2124 server_data['port'] = server.server_port 2161 server_data['port'] = server.server_port
2125 server_data['xmpp_port'] = server.xmpp_port 2162 server_data['xmpp_port'] = server.xmpp_port
2126 elif options.server_type == SERVER_TCP_ECHO: 2163 elif options.server_type == SERVER_TCP_ECHO:
2127 # Used for generating the key (randomly) that encodes the "echo request" 2164 # Used for generating the key (randomly) that encodes the "echo request"
2128 # message. 2165 # message.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2204 dest='server_type', 2241 dest='server_type',
2205 help='start up a sync server.') 2242 help='start up a sync server.')
2206 option_parser.add_option('', '--tcp-echo', action='store_const', 2243 option_parser.add_option('', '--tcp-echo', action='store_const',
2207 const=SERVER_TCP_ECHO, default=SERVER_HTTP, 2244 const=SERVER_TCP_ECHO, default=SERVER_HTTP,
2208 dest='server_type', 2245 dest='server_type',
2209 help='start up a tcp echo server.') 2246 help='start up a tcp echo server.')
2210 option_parser.add_option('', '--udp-echo', action='store_const', 2247 option_parser.add_option('', '--udp-echo', action='store_const',
2211 const=SERVER_UDP_ECHO, default=SERVER_HTTP, 2248 const=SERVER_UDP_ECHO, default=SERVER_HTTP,
2212 dest='server_type', 2249 dest='server_type',
2213 help='start up a udp echo server.') 2250 help='start up a udp echo server.')
2251 option_parser.add_option('', '--websocket', action='store_const',
2252 const=SERVER_WEBSOCKET, default=SERVER_HTTP,
2253 dest='server_type',
2254 help='start up a WebSocket server.')
2214 option_parser.add_option('', '--log-to-console', action='store_const', 2255 option_parser.add_option('', '--log-to-console', action='store_const',
2215 const=True, default=False, 2256 const=True, default=False,
2216 dest='log_to_console', 2257 dest='log_to_console',
2217 help='Enables or disables sys.stdout logging to ' 2258 help='Enables or disables sys.stdout logging to '
2218 'the console.') 2259 'the console.')
2219 option_parser.add_option('', '--port', default='0', type='int', 2260 option_parser.add_option('', '--port', default='0', type='int',
2220 help='Port used by the server. If unspecified, the ' 2261 help='Port used by the server. If unspecified, the '
2221 'server will listen on an ephemeral port.') 2262 'server will listen on an ephemeral port.')
2222 option_parser.add_option('', '--xmpp-port', default='0', type='int', 2263 option_parser.add_option('', '--xmpp-port', default='0', type='int',
2223 help='Port used by the XMPP server. If unspecified, ' 2264 help='Port used by the XMPP server. If unspecified, '
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2286 dest='host', 2327 dest='host',
2287 help='Hostname or IP upon which the server will ' 2328 help='Hostname or IP upon which the server will '
2288 'listen. Client connections will also only be ' 2329 'listen. Client connections will also only be '
2289 'allowed from this address.') 2330 'allowed from this address.')
2290 option_parser.add_option('', '--auth-token', dest='auth_token', 2331 option_parser.add_option('', '--auth-token', dest='auth_token',
2291 help='Specify the auth token which should be used' 2332 help='Specify the auth token which should be used'
2292 'in the authorization header for GData.') 2333 'in the authorization header for GData.')
2293 options, args = option_parser.parse_args() 2334 options, args = option_parser.parse_args()
2294 2335
2295 sys.exit(main(options, args)) 2336 sys.exit(main(options, args))
OLDNEW
« net/tools/testserver/run_testserver.cc ('K') | « net/tools/testserver/run_testserver.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698