blob: 400e59395046246de1794490e81bf7331cbc0015 [file] [log] [blame]
David Benjaminf025abe2021-09-17 22:59:19 +00001#!/usr/bin/env vpython3
rsimha@chromium.org99a6f172013-01-20 01:10:24 +00002# Copyright 2013 The Chromium Authors. All rights reserved.
license.botf3378c22008-08-24 00:55:55 +00003# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
initial.commit94958cf2008-07-26 22:42:52 +00005
Matt Menke3a293bd2021-08-13 20:34:43 +00006"""This is a simple HTTP/TCP/PROXY/BASIC_AUTH_PROXY/WEBSOCKET server used for
7testing Chrome.
initial.commit94958cf2008-07-26 22:42:52 +00008
9It supports several test URLs, as specified by the handlers in TestPageHandler.
cbentzel@chromium.org0787bc72010-11-11 20:31:31 +000010By default, it listens on an ephemeral port and sends the port number back to
11the originating process over a pipe. The originating process can specify an
12explicit port if necessary.
initial.commit94958cf2008-07-26 22:42:52 +000013"""
14
David Benjaminf025abe2021-09-17 22:59:19 +000015from __future__ import print_function
16
initial.commit94958cf2008-07-26 22:42:52 +000017import base64
toyoshim@chromium.orgaa1b6e72012-10-09 03:43:19 +000018import logging
initial.commit94958cf2008-07-26 22:42:52 +000019import os
akalin@chromium.org4e4f3c92010-11-27 04:04:52 +000020import select
David Benjaminf025abe2021-09-17 22:59:19 +000021from six.moves import BaseHTTPServer, socketserver
22import six.moves.urllib.parse as urlparse
agl@chromium.orgb3ec3462012-03-19 20:32:47 +000023import socket
yhirano@chromium.org51f90d92014-03-24 04:49:23 +000024import ssl
agl@chromium.org77a9ad92012-03-20 15:14:27 +000025import sys
phajdan.jr@chromium.orgbf74e2b2010-08-17 20:07:11 +000026
maruel@chromium.org5ddc64e2013-12-05 17:50:12 +000027BASE_DIR = os.path.dirname(os.path.abspath(__file__))
28ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(BASE_DIR)))
29
davidben@chromium.org7d53b542014-04-10 17:56:44 +000030# Insert at the beginning of the path, we want to use our copies of the library
Robert Iannucci0e7ec952018-01-18 22:44:16 +000031# unconditionally (since they contain modifications from anything that might be
32# obtained from e.g. PyPi).
Keita Suzuki83e26f92020-03-06 09:42:48 +000033sys.path.insert(0, os.path.join(ROOT_DIR, 'third_party', 'pywebsocket3', 'src'))
davidben@chromium.org7d53b542014-04-10 17:56:44 +000034
yhirano@chromium.org51f90d92014-03-24 04:49:23 +000035import mod_pywebsocket.standalone
pliard@chromium.org3f8873f2012-11-14 11:38:55 +000036from mod_pywebsocket.standalone import WebSocketServer
yhirano@chromium.org51f90d92014-03-24 04:49:23 +000037# import manually
38mod_pywebsocket.standalone.ssl = ssl
davidben@chromium.org06fcf202010-09-22 18:15:23 +000039
davidben@chromium.org7d53b542014-04-10 17:56:44 +000040import testserver_base
41
David Benjamin69ef0402022-02-23 16:34:11 +000042SERVER_UNSET = 0
Matt Menke3a293bd2021-08-13 20:34:43 +000043SERVER_BASIC_AUTH_PROXY = 1
44SERVER_WEBSOCKET = 2
45SERVER_PROXY = 3
toyoshim@chromium.orgaa1b6e72012-10-09 03:43:19 +000046
47# Default request queue size for WebSocketServer.
48_DEFAULT_REQUEST_QUEUE_SIZE = 128
initial.commit94958cf2008-07-26 22:42:52 +000049
toyoshim@chromium.orgaa1b6e72012-10-09 03:43:19 +000050class WebSocketOptions:
51 """Holds options for WebSocketServer."""
52
53 def __init__(self, host, port, data_dir):
54 self.request_queue_size = _DEFAULT_REQUEST_QUEUE_SIZE
55 self.server_host = host
56 self.port = port
57 self.websock_handlers = data_dir
58 self.scan_dir = None
59 self.allow_handlers_outside_root_dir = False
60 self.websock_handlers_map_file = None
61 self.cgi_directories = []
62 self.is_executable_method = None
toyoshim@chromium.orgaa1b6e72012-10-09 03:43:19 +000063
toyoshim@chromium.orgaa1b6e72012-10-09 03:43:19 +000064 self.use_tls = False
65 self.private_key = None
66 self.certificate = None
toyoshim@chromium.orgd532cf32012-10-18 05:05:51 +000067 self.tls_client_auth = False
toyoshim@chromium.orgaa1b6e72012-10-09 03:43:19 +000068 self.tls_client_ca = None
69 self.use_basic_auth = False
Keita Suzuki83e26f92020-03-06 09:42:48 +000070 self.basic_auth_credential = 'Basic ' + base64.b64encode(
David Benjaminf025abe2021-09-17 22:59:19 +000071 b'test:test').decode()
toyoshim@chromium.orgaa1b6e72012-10-09 03:43:19 +000072
mattm@chromium.org830a3712012-11-07 23:00:07 +000073
David Benjamin69ef0402022-02-23 16:34:11 +000074class ThreadingHTTPServer(socketserver.ThreadingMixIn,
75 testserver_base.ClientRestrictingServerMixIn,
76 testserver_base.BrokenPipeHandlerMixIn,
77 testserver_base.StoppableHTTPServer):
agl@chromium.org77a9ad92012-03-20 15:14:27 +000078 """This is a specialization of StoppableHTTPServer that adds client
David Benjamin69ef0402022-02-23 16:34:11 +000079 verification and creates a new thread for every connection. It
Adam Rice34b2e312018-04-06 16:48:30 +000080 should only be used with handlers that are known to be threadsafe."""
81
82 pass
83
mattm@chromium.org830a3712012-11-07 23:00:07 +000084
rsimha@chromium.org99a6f172013-01-20 01:10:24 +000085class TestPageHandler(testserver_base.BasePageHandler):
initial.commit94958cf2008-07-26 22:42:52 +000086 def __init__(self, request, client_address, socket_server):
David Benjamin1f5bdcf2021-09-15 14:46:41 +000087 connect_handlers = [self.DefaultConnectResponseHandler]
88 get_handlers = [self.DefaultResponseHandler]
89 post_handlers = get_handlers
90 put_handlers = get_handlers
91 head_handlers = [self.DefaultResponseHandler]
rsimha@chromium.org99a6f172013-01-20 01:10:24 +000092 testserver_base.BasePageHandler.__init__(self, request, client_address,
93 socket_server, connect_handlers,
94 get_handlers, head_handlers,
95 post_handlers, put_handlers)
nsylvain@chromium.org8d5763b2008-12-30 23:44:27 +000096
initial.commit94958cf2008-07-26 22:42:52 +000097 def DefaultResponseHandler(self):
98 """This is the catch-all response handler for requests that aren't handled
99 by one of the special handlers above.
100 Note that we specify the content-length as without it the https connection
101 is not closed properly (and the browser keeps expecting data)."""
102
103 contents = "Default response given for path: " + self.path
104 self.send_response(200)
mmenke@chromium.orgbfff75b2011-11-01 02:32:05 +0000105 self.send_header('Content-Type', 'text/html')
106 self.send_header('Content-Length', len(contents))
initial.commit94958cf2008-07-26 22:42:52 +0000107 self.end_headers()
mmenke@chromium.orgbfff75b2011-11-01 02:32:05 +0000108 if (self.command != 'HEAD'):
David Benjaminf025abe2021-09-17 22:59:19 +0000109 self.wfile.write(contents.encode('utf8'))
initial.commit94958cf2008-07-26 22:42:52 +0000110 return True
111
wtc@chromium.org743d77b2009-02-11 02:48:15 +0000112 def DefaultConnectResponseHandler(self):
113 """This is the catch-all response handler for CONNECT requests that aren't
114 handled by one of the special handlers above. Real Web servers respond
115 with 400 to CONNECT requests."""
116
117 contents = "Your client has issued a malformed or illegal request."
118 self.send_response(400) # bad request
mmenke@chromium.orgbfff75b2011-11-01 02:32:05 +0000119 self.send_header('Content-Type', 'text/html')
120 self.send_header('Content-Length', len(contents))
wtc@chromium.org743d77b2009-02-11 02:48:15 +0000121 self.end_headers()
David Benjaminf025abe2021-09-17 22:59:19 +0000122 self.wfile.write(contents.encode('utf8'))
wtc@chromium.org743d77b2009-02-11 02:48:15 +0000123 return True
124
akalin@chromium.org154bb132010-11-12 02:20:27 +0000125
Adam Rice9476b8c2018-08-02 15:28:43 +0000126class ProxyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
127 """A request handler that behaves as a proxy server. Only CONNECT, GET and
128 HEAD methods are supported.
bashi@chromium.org33233532012-09-08 17:37:24 +0000129 """
130
Pavol Marko8ccaaed2018-01-04 18:40:04 +0100131 redirect_connect_to_localhost = False;
bashi@chromium.org33233532012-09-08 17:37:24 +0000132
bashi@chromium.org33233532012-09-08 17:37:24 +0000133 def _start_read_write(self, sock):
134 sock.setblocking(0)
135 self.request.setblocking(0)
136 rlist = [self.request, sock]
137 while True:
toyoshim@chromium.org9d7219e2012-10-25 03:30:10 +0000138 ready_sockets, _unused, errors = select.select(rlist, [], [])
bashi@chromium.org33233532012-09-08 17:37:24 +0000139 if errors:
140 self.send_response(500)
141 self.end_headers()
142 return
143 for s in ready_sockets:
144 received = s.recv(1024)
145 if len(received) == 0:
146 return
147 if s == self.request:
148 other = sock
149 else:
150 other = self.request
Adam Rice54443aa2018-06-06 00:11:54 +0000151 # This will lose data if the kernel write buffer fills up.
152 # TODO(ricea): Correctly use the return value to track how much was
153 # written and buffer the rest. Use select to determine when the socket
154 # becomes writable again.
bashi@chromium.org33233532012-09-08 17:37:24 +0000155 other.send(received)
156
157 def _do_common_method(self):
158 url = urlparse.urlparse(self.path)
159 port = url.port
160 if not port:
161 if url.scheme == 'http':
162 port = 80
163 elif url.scheme == 'https':
164 port = 443
165 if not url.hostname or not port:
166 self.send_response(400)
167 self.end_headers()
168 return
169
170 if len(url.path) == 0:
171 path = '/'
172 else:
173 path = url.path
174 if len(url.query) > 0:
175 path = '%s?%s' % (url.path, url.query)
176
177 sock = None
178 try:
179 sock = socket.create_connection((url.hostname, port))
David Benjaminf025abe2021-09-17 22:59:19 +0000180 sock.send(('%s %s %s\r\n' %
181 (self.command, path, self.protocol_version)).encode('utf-8'))
182 for name, value in self.headers.items():
183 if (name.lower().startswith('connection')
184 or name.lower().startswith('proxy')):
bashi@chromium.org33233532012-09-08 17:37:24 +0000185 continue
David Benjaminf025abe2021-09-17 22:59:19 +0000186 # HTTP headers are encoded in Latin-1.
187 sock.send(b'%s: %s\r\n' %
188 (name.encode('latin-1'), value.encode('latin-1')))
189 sock.send(b'\r\n')
Adam Rice54443aa2018-06-06 00:11:54 +0000190 # This is wrong: it will pass through connection-level headers and
191 # misbehave on connection reuse. The only reason it works at all is that
192 # our test servers have never supported connection reuse.
193 # TODO(ricea): Use a proper HTTP client library instead.
bashi@chromium.org33233532012-09-08 17:37:24 +0000194 self._start_read_write(sock)
toyoshim@chromium.org9d7219e2012-10-25 03:30:10 +0000195 except Exception:
Adam Rice54443aa2018-06-06 00:11:54 +0000196 logging.exception('failure in common method: %s %s', self.command, path)
bashi@chromium.org33233532012-09-08 17:37:24 +0000197 self.send_response(500)
198 self.end_headers()
199 finally:
200 if sock is not None:
201 sock.close()
202
203 def do_CONNECT(self):
204 try:
205 pos = self.path.rfind(':')
206 host = self.path[:pos]
207 port = int(self.path[pos+1:])
toyoshim@chromium.org9d7219e2012-10-25 03:30:10 +0000208 except Exception:
bashi@chromium.org33233532012-09-08 17:37:24 +0000209 self.send_response(400)
210 self.end_headers()
211
Adam Rice9476b8c2018-08-02 15:28:43 +0000212 if ProxyRequestHandler.redirect_connect_to_localhost:
Pavol Marko8ccaaed2018-01-04 18:40:04 +0100213 host = "127.0.0.1"
214
Adam Rice54443aa2018-06-06 00:11:54 +0000215 sock = None
bashi@chromium.org33233532012-09-08 17:37:24 +0000216 try:
217 sock = socket.create_connection((host, port))
218 self.send_response(200, 'Connection established')
219 self.end_headers()
220 self._start_read_write(sock)
toyoshim@chromium.org9d7219e2012-10-25 03:30:10 +0000221 except Exception:
Adam Rice54443aa2018-06-06 00:11:54 +0000222 logging.exception('failure in CONNECT: %s', path)
bashi@chromium.org33233532012-09-08 17:37:24 +0000223 self.send_response(500)
224 self.end_headers()
225 finally:
Adam Rice54443aa2018-06-06 00:11:54 +0000226 if sock is not None:
227 sock.close()
bashi@chromium.org33233532012-09-08 17:37:24 +0000228
229 def do_GET(self):
230 self._do_common_method()
231
232 def do_HEAD(self):
233 self._do_common_method()
234
Adam Rice9476b8c2018-08-02 15:28:43 +0000235class BasicAuthProxyRequestHandler(ProxyRequestHandler):
236 """A request handler that behaves as a proxy server which requires
237 basic authentication.
238 """
239
240 _AUTH_CREDENTIAL = 'Basic Zm9vOmJhcg==' # foo:bar
241
242 def parse_request(self):
243 """Overrides parse_request to check credential."""
244
245 if not ProxyRequestHandler.parse_request(self):
246 return False
247
David Benjaminf025abe2021-09-17 22:59:19 +0000248 auth = self.headers.get('Proxy-Authorization', None)
Adam Rice9476b8c2018-08-02 15:28:43 +0000249 if auth != self._AUTH_CREDENTIAL:
250 self.send_response(407)
251 self.send_header('Proxy-Authenticate', 'Basic realm="MyRealm1"')
252 self.end_headers()
253 return False
254
255 return True
256
bashi@chromium.org33233532012-09-08 17:37:24 +0000257
mattm@chromium.org830a3712012-11-07 23:00:07 +0000258class ServerRunner(testserver_base.TestServerRunner):
259 """TestServerRunner for the net test servers."""
phajdan.jr@chromium.orgbf74e2b2010-08-17 20:07:11 +0000260
mattm@chromium.org830a3712012-11-07 23:00:07 +0000261 def __init__(self):
262 super(ServerRunner, self).__init__()
phajdan.jr@chromium.orgbf74e2b2010-08-17 20:07:11 +0000263
mattm@chromium.org830a3712012-11-07 23:00:07 +0000264 def __make_data_dir(self):
265 if self.options.data_dir:
266 if not os.path.isdir(self.options.data_dir):
267 raise testserver_base.OptionError('specified data dir not found: ' +
268 self.options.data_dir + ' exiting...')
269 my_data_dir = self.options.data_dir
270 else:
271 # Create the default path to our data dir, relative to the exe dir.
Asanka Herath0ec37152019-08-02 15:23:57 +0000272 my_data_dir = os.path.join(BASE_DIR, "..", "..", "data")
phajdan.jr@chromium.orgbf74e2b2010-08-17 20:07:11 +0000273
mattm@chromium.org830a3712012-11-07 23:00:07 +0000274 return my_data_dir
newt@chromium.org1fc32742012-10-20 00:28:35 +0000275
mattm@chromium.org830a3712012-11-07 23:00:07 +0000276 def create_server(self, server_data):
277 port = self.options.port
278 host = self.options.host
newt@chromium.org1fc32742012-10-20 00:28:35 +0000279
Adam Rice54443aa2018-06-06 00:11:54 +0000280 logging.basicConfig()
281
estark21667d62015-04-08 21:00:16 -0700282 # Work around a bug in Mac OS 10.6. Spawning a WebSockets server
283 # will result in a call to |getaddrinfo|, which fails with "nodename
284 # nor servname provided" for localhost:0 on 10.6.
Adam Rice54443aa2018-06-06 00:11:54 +0000285 # TODO(ricea): Remove this if no longer needed.
estark21667d62015-04-08 21:00:16 -0700286 if self.options.server_type == SERVER_WEBSOCKET and \
287 host == "localhost" and \
288 port == 0:
289 host = "127.0.0.1"
290
Ryan Sleevi3bfd15d2018-01-23 21:12:24 +0000291 # Construct the subjectAltNames for any ad-hoc generated certificates.
292 # As host can be either a DNS name or IP address, attempt to determine
293 # which it is, so it can be placed in the appropriate SAN.
294 dns_sans = None
295 ip_sans = None
296 ip = None
297 try:
298 ip = socket.inet_aton(host)
299 ip_sans = [ip]
300 except socket.error:
301 pass
302 if ip is None:
303 dns_sans = [host]
304
David Benjamin69ef0402022-02-23 16:34:11 +0000305 if self.options.server_type == SERVER_UNSET:
306 raise testserver_base.OptionError('no server type specified')
mattm@chromium.org830a3712012-11-07 23:00:07 +0000307 elif self.options.server_type == SERVER_WEBSOCKET:
mattm@chromium.org830a3712012-11-07 23:00:07 +0000308 # TODO(toyoshim): Remove following os.chdir. Currently this operation
309 # is required to work correctly. It should be fixed from pywebsocket side.
310 os.chdir(self.__make_data_dir())
311 websocket_options = WebSocketOptions(host, port, '.')
davidben@chromium.org009843a2014-06-03 00:13:08 +0000312 scheme = "ws"
mattm@chromium.org830a3712012-11-07 23:00:07 +0000313 if self.options.cert_and_key_file:
davidben@chromium.org009843a2014-06-03 00:13:08 +0000314 scheme = "wss"
mattm@chromium.org830a3712012-11-07 23:00:07 +0000315 websocket_options.use_tls = True
Sergey Ulanovdd8b8ea2017-09-08 22:53:25 +0000316 key_path = os.path.join(ROOT_DIR, self.options.cert_and_key_file)
317 if not os.path.isfile(key_path):
318 raise testserver_base.OptionError(
319 'specified server cert file not found: ' +
320 self.options.cert_and_key_file + ' exiting...')
321 websocket_options.private_key = key_path
322 websocket_options.certificate = key_path
323
mattm@chromium.org830a3712012-11-07 23:00:07 +0000324 if self.options.ssl_client_auth:
pneubeck@chromium.orgf5007112014-07-21 15:22:41 +0000325 websocket_options.tls_client_cert_optional = False
mattm@chromium.org830a3712012-11-07 23:00:07 +0000326 websocket_options.tls_client_auth = True
327 if len(self.options.ssl_client_ca) != 1:
328 raise testserver_base.OptionError(
329 'one trusted client CA file should be specified')
330 if not os.path.isfile(self.options.ssl_client_ca[0]):
331 raise testserver_base.OptionError(
332 'specified trusted client CA file not found: ' +
333 self.options.ssl_client_ca[0] + ' exiting...')
334 websocket_options.tls_client_ca = self.options.ssl_client_ca[0]
David Benjaminf025abe2021-09-17 22:59:19 +0000335 print('Trying to start websocket server on %s://%s:%d...' %
336 (scheme, websocket_options.server_host, websocket_options.port))
mattm@chromium.org830a3712012-11-07 23:00:07 +0000337 server = WebSocketServer(websocket_options)
David Benjaminf025abe2021-09-17 22:59:19 +0000338 print('WebSocket server started on %s://%s:%d...' %
339 (scheme, host, server.server_port))
mattm@chromium.org830a3712012-11-07 23:00:07 +0000340 server_data['port'] = server.server_port
ricea@chromium.orga52ebdc2014-07-29 07:42:29 +0000341 websocket_options.use_basic_auth = self.options.ws_basic_auth
Adam Rice9476b8c2018-08-02 15:28:43 +0000342 elif self.options.server_type == SERVER_PROXY:
343 ProxyRequestHandler.redirect_connect_to_localhost = \
344 self.options.redirect_connect_to_localhost
345 server = ThreadingHTTPServer((host, port), ProxyRequestHandler)
David Benjaminf025abe2021-09-17 22:59:19 +0000346 print('Proxy server started on port %d...' % server.server_port)
Adam Rice9476b8c2018-08-02 15:28:43 +0000347 server_data['port'] = server.server_port
mattm@chromium.org830a3712012-11-07 23:00:07 +0000348 elif self.options.server_type == SERVER_BASIC_AUTH_PROXY:
Adam Rice9476b8c2018-08-02 15:28:43 +0000349 ProxyRequestHandler.redirect_connect_to_localhost = \
Pavol Marko8ccaaed2018-01-04 18:40:04 +0100350 self.options.redirect_connect_to_localhost
Adam Rice34b2e312018-04-06 16:48:30 +0000351 server = ThreadingHTTPServer((host, port), BasicAuthProxyRequestHandler)
David Benjaminf025abe2021-09-17 22:59:19 +0000352 print('BasicAuthProxy server started on port %d...' % server.server_port)
mattm@chromium.org830a3712012-11-07 23:00:07 +0000353 server_data['port'] = server.server_port
erikkay@google.comd5182ff2009-01-08 20:45:27 +0000354 else:
mattm@chromium.org830a3712012-11-07 23:00:07 +0000355 raise testserver_base.OptionError('unknown server type' +
356 self.options.server_type)
erikkay@google.com70397b62008-12-30 21:49:21 +0000357
mattm@chromium.org830a3712012-11-07 23:00:07 +0000358 return server
erikkay@google.comd5182ff2009-01-08 20:45:27 +0000359
mattm@chromium.org830a3712012-11-07 23:00:07 +0000360 def add_options(self):
361 testserver_base.TestServerRunner.add_options(self)
David Benjamin69ef0402022-02-23 16:34:11 +0000362 self.option_parser.add_option('--proxy',
363 action='store_const',
Adam Rice9476b8c2018-08-02 15:28:43 +0000364 const=SERVER_PROXY,
David Benjamin69ef0402022-02-23 16:34:11 +0000365 default=SERVER_UNSET,
366 dest='server_type',
Adam Rice9476b8c2018-08-02 15:28:43 +0000367 help='start up a proxy server.')
David Benjamin69ef0402022-02-23 16:34:11 +0000368 self.option_parser.add_option('--basic-auth-proxy',
369 action='store_const',
mattm@chromium.org830a3712012-11-07 23:00:07 +0000370 const=SERVER_BASIC_AUTH_PROXY,
David Benjamin69ef0402022-02-23 16:34:11 +0000371 default=SERVER_UNSET,
372 dest='server_type',
mattm@chromium.org830a3712012-11-07 23:00:07 +0000373 help='start up a proxy server which requires '
374 'basic authentication.')
David Benjamin69ef0402022-02-23 16:34:11 +0000375 self.option_parser.add_option('--websocket',
376 action='store_const',
377 const=SERVER_WEBSOCKET,
378 default=SERVER_UNSET,
mattm@chromium.org830a3712012-11-07 23:00:07 +0000379 dest='server_type',
380 help='start up a WebSocket server.')
mattm@chromium.org830a3712012-11-07 23:00:07 +0000381 self.option_parser.add_option('--cert-and-key-file',
382 dest='cert_and_key_file', help='specify the '
383 'path to the file containing the certificate '
384 'and private key for the server in PEM '
385 'format')
mattm@chromium.org830a3712012-11-07 23:00:07 +0000386 self.option_parser.add_option('--ssl-client-auth', action='store_true',
387 help='Require SSL client auth on every '
388 'connection.')
389 self.option_parser.add_option('--ssl-client-ca', action='append',
390 default=[], help='Specify that the client '
391 'certificate request should include the CA '
392 'named in the subject of the DER-encoded '
393 'certificate contained in the specified '
394 'file. This option may appear multiple '
395 'times, indicating multiple CA names should '
396 'be sent in the request.')
mattm@chromium.org830a3712012-11-07 23:00:07 +0000397 self.option_parser.add_option('--file-root-url', default='/files/',
398 help='Specify a root URL for files served.')
ricea@chromium.orga52ebdc2014-07-29 07:42:29 +0000399 # TODO(ricea): Generalize this to support basic auth for HTTP too.
400 self.option_parser.add_option('--ws-basic-auth', action='store_true',
401 dest='ws_basic_auth',
402 help='Enable basic-auth for WebSocket')
Pavol Marko8ccaaed2018-01-04 18:40:04 +0100403 self.option_parser.add_option('--redirect-connect-to-localhost',
404 dest='redirect_connect_to_localhost',
405 default=False, action='store_true',
406 help='If set, the Proxy server will connect '
407 'to localhost instead of the requested URL '
408 'on CONNECT requests')
erikkay@google.comd5182ff2009-01-08 20:45:27 +0000409
toyoshim@chromium.org16f57522012-10-24 06:14:38 +0000410
initial.commit94958cf2008-07-26 22:42:52 +0000411if __name__ == '__main__':
mattm@chromium.org830a3712012-11-07 23:00:07 +0000412 sys.exit(ServerRunner().main())