blob: ef1b78cda4854804f8e3d0cdd0de6a363d94ef7f [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
maruel@chromium.org756cf982009-03-05 12:46:38 +000042SERVER_HTTP = 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
rsimha@chromium.org99a6f172013-01-20 01:10:24 +000074class HTTPServer(testserver_base.ClientRestrictingServerMixIn,
75 testserver_base.BrokenPipeHandlerMixIn,
76 testserver_base.StoppableHTTPServer):
agl@chromium.org77a9ad92012-03-20 15:14:27 +000077 """This is a specialization of StoppableHTTPServer that adds client
erikwright@chromium.org847ef282012-02-22 16:41:10 +000078 verification."""
79
80 pass
81
David Benjaminf025abe2021-09-17 22:59:19 +000082
83class ThreadingHTTPServer(socketserver.ThreadingMixIn, HTTPServer):
Adam Rice34b2e312018-04-06 16:48:30 +000084 """This variant of HTTPServer creates a new thread for every connection. It
85 should only be used with handlers that are known to be threadsafe."""
86
87 pass
88
mattm@chromium.org830a3712012-11-07 23:00:07 +000089
rsimha@chromium.org99a6f172013-01-20 01:10:24 +000090class TestPageHandler(testserver_base.BasePageHandler):
initial.commit94958cf2008-07-26 22:42:52 +000091 def __init__(self, request, client_address, socket_server):
David Benjamin1f5bdcf2021-09-15 14:46:41 +000092 connect_handlers = [self.DefaultConnectResponseHandler]
93 get_handlers = [self.DefaultResponseHandler]
94 post_handlers = get_handlers
95 put_handlers = get_handlers
96 head_handlers = [self.DefaultResponseHandler]
rsimha@chromium.org99a6f172013-01-20 01:10:24 +000097 testserver_base.BasePageHandler.__init__(self, request, client_address,
98 socket_server, connect_handlers,
99 get_handlers, head_handlers,
100 post_handlers, put_handlers)
nsylvain@chromium.org8d5763b2008-12-30 23:44:27 +0000101
initial.commit94958cf2008-07-26 22:42:52 +0000102 def DefaultResponseHandler(self):
103 """This is the catch-all response handler for requests that aren't handled
104 by one of the special handlers above.
105 Note that we specify the content-length as without it the https connection
106 is not closed properly (and the browser keeps expecting data)."""
107
108 contents = "Default response given for path: " + self.path
109 self.send_response(200)
mmenke@chromium.orgbfff75b2011-11-01 02:32:05 +0000110 self.send_header('Content-Type', 'text/html')
111 self.send_header('Content-Length', len(contents))
initial.commit94958cf2008-07-26 22:42:52 +0000112 self.end_headers()
mmenke@chromium.orgbfff75b2011-11-01 02:32:05 +0000113 if (self.command != 'HEAD'):
David Benjaminf025abe2021-09-17 22:59:19 +0000114 self.wfile.write(contents.encode('utf8'))
initial.commit94958cf2008-07-26 22:42:52 +0000115 return True
116
wtc@chromium.org743d77b2009-02-11 02:48:15 +0000117 def DefaultConnectResponseHandler(self):
118 """This is the catch-all response handler for CONNECT requests that aren't
119 handled by one of the special handlers above. Real Web servers respond
120 with 400 to CONNECT requests."""
121
122 contents = "Your client has issued a malformed or illegal request."
123 self.send_response(400) # bad request
mmenke@chromium.orgbfff75b2011-11-01 02:32:05 +0000124 self.send_header('Content-Type', 'text/html')
125 self.send_header('Content-Length', len(contents))
wtc@chromium.org743d77b2009-02-11 02:48:15 +0000126 self.end_headers()
David Benjaminf025abe2021-09-17 22:59:19 +0000127 self.wfile.write(contents.encode('utf8'))
wtc@chromium.org743d77b2009-02-11 02:48:15 +0000128 return True
129
akalin@chromium.org154bb132010-11-12 02:20:27 +0000130
Adam Rice9476b8c2018-08-02 15:28:43 +0000131class ProxyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
132 """A request handler that behaves as a proxy server. Only CONNECT, GET and
133 HEAD methods are supported.
bashi@chromium.org33233532012-09-08 17:37:24 +0000134 """
135
Pavol Marko8ccaaed2018-01-04 18:40:04 +0100136 redirect_connect_to_localhost = False;
bashi@chromium.org33233532012-09-08 17:37:24 +0000137
bashi@chromium.org33233532012-09-08 17:37:24 +0000138 def _start_read_write(self, sock):
139 sock.setblocking(0)
140 self.request.setblocking(0)
141 rlist = [self.request, sock]
142 while True:
toyoshim@chromium.org9d7219e2012-10-25 03:30:10 +0000143 ready_sockets, _unused, errors = select.select(rlist, [], [])
bashi@chromium.org33233532012-09-08 17:37:24 +0000144 if errors:
145 self.send_response(500)
146 self.end_headers()
147 return
148 for s in ready_sockets:
149 received = s.recv(1024)
150 if len(received) == 0:
151 return
152 if s == self.request:
153 other = sock
154 else:
155 other = self.request
Adam Rice54443aa2018-06-06 00:11:54 +0000156 # This will lose data if the kernel write buffer fills up.
157 # TODO(ricea): Correctly use the return value to track how much was
158 # written and buffer the rest. Use select to determine when the socket
159 # becomes writable again.
bashi@chromium.org33233532012-09-08 17:37:24 +0000160 other.send(received)
161
162 def _do_common_method(self):
163 url = urlparse.urlparse(self.path)
164 port = url.port
165 if not port:
166 if url.scheme == 'http':
167 port = 80
168 elif url.scheme == 'https':
169 port = 443
170 if not url.hostname or not port:
171 self.send_response(400)
172 self.end_headers()
173 return
174
175 if len(url.path) == 0:
176 path = '/'
177 else:
178 path = url.path
179 if len(url.query) > 0:
180 path = '%s?%s' % (url.path, url.query)
181
182 sock = None
183 try:
184 sock = socket.create_connection((url.hostname, port))
David Benjaminf025abe2021-09-17 22:59:19 +0000185 sock.send(('%s %s %s\r\n' %
186 (self.command, path, self.protocol_version)).encode('utf-8'))
187 for name, value in self.headers.items():
188 if (name.lower().startswith('connection')
189 or name.lower().startswith('proxy')):
bashi@chromium.org33233532012-09-08 17:37:24 +0000190 continue
David Benjaminf025abe2021-09-17 22:59:19 +0000191 # HTTP headers are encoded in Latin-1.
192 sock.send(b'%s: %s\r\n' %
193 (name.encode('latin-1'), value.encode('latin-1')))
194 sock.send(b'\r\n')
Adam Rice54443aa2018-06-06 00:11:54 +0000195 # This is wrong: it will pass through connection-level headers and
196 # misbehave on connection reuse. The only reason it works at all is that
197 # our test servers have never supported connection reuse.
198 # TODO(ricea): Use a proper HTTP client library instead.
bashi@chromium.org33233532012-09-08 17:37:24 +0000199 self._start_read_write(sock)
toyoshim@chromium.org9d7219e2012-10-25 03:30:10 +0000200 except Exception:
Adam Rice54443aa2018-06-06 00:11:54 +0000201 logging.exception('failure in common method: %s %s', self.command, path)
bashi@chromium.org33233532012-09-08 17:37:24 +0000202 self.send_response(500)
203 self.end_headers()
204 finally:
205 if sock is not None:
206 sock.close()
207
208 def do_CONNECT(self):
209 try:
210 pos = self.path.rfind(':')
211 host = self.path[:pos]
212 port = int(self.path[pos+1:])
toyoshim@chromium.org9d7219e2012-10-25 03:30:10 +0000213 except Exception:
bashi@chromium.org33233532012-09-08 17:37:24 +0000214 self.send_response(400)
215 self.end_headers()
216
Adam Rice9476b8c2018-08-02 15:28:43 +0000217 if ProxyRequestHandler.redirect_connect_to_localhost:
Pavol Marko8ccaaed2018-01-04 18:40:04 +0100218 host = "127.0.0.1"
219
Adam Rice54443aa2018-06-06 00:11:54 +0000220 sock = None
bashi@chromium.org33233532012-09-08 17:37:24 +0000221 try:
222 sock = socket.create_connection((host, port))
223 self.send_response(200, 'Connection established')
224 self.end_headers()
225 self._start_read_write(sock)
toyoshim@chromium.org9d7219e2012-10-25 03:30:10 +0000226 except Exception:
Adam Rice54443aa2018-06-06 00:11:54 +0000227 logging.exception('failure in CONNECT: %s', path)
bashi@chromium.org33233532012-09-08 17:37:24 +0000228 self.send_response(500)
229 self.end_headers()
230 finally:
Adam Rice54443aa2018-06-06 00:11:54 +0000231 if sock is not None:
232 sock.close()
bashi@chromium.org33233532012-09-08 17:37:24 +0000233
234 def do_GET(self):
235 self._do_common_method()
236
237 def do_HEAD(self):
238 self._do_common_method()
239
Adam Rice9476b8c2018-08-02 15:28:43 +0000240class BasicAuthProxyRequestHandler(ProxyRequestHandler):
241 """A request handler that behaves as a proxy server which requires
242 basic authentication.
243 """
244
245 _AUTH_CREDENTIAL = 'Basic Zm9vOmJhcg==' # foo:bar
246
247 def parse_request(self):
248 """Overrides parse_request to check credential."""
249
250 if not ProxyRequestHandler.parse_request(self):
251 return False
252
David Benjaminf025abe2021-09-17 22:59:19 +0000253 auth = self.headers.get('Proxy-Authorization', None)
Adam Rice9476b8c2018-08-02 15:28:43 +0000254 if auth != self._AUTH_CREDENTIAL:
255 self.send_response(407)
256 self.send_header('Proxy-Authenticate', 'Basic realm="MyRealm1"')
257 self.end_headers()
258 return False
259
260 return True
261
bashi@chromium.org33233532012-09-08 17:37:24 +0000262
mattm@chromium.org830a3712012-11-07 23:00:07 +0000263class ServerRunner(testserver_base.TestServerRunner):
264 """TestServerRunner for the net test servers."""
phajdan.jr@chromium.orgbf74e2b2010-08-17 20:07:11 +0000265
mattm@chromium.org830a3712012-11-07 23:00:07 +0000266 def __init__(self):
267 super(ServerRunner, self).__init__()
phajdan.jr@chromium.orgbf74e2b2010-08-17 20:07:11 +0000268
mattm@chromium.org830a3712012-11-07 23:00:07 +0000269 def __make_data_dir(self):
270 if self.options.data_dir:
271 if not os.path.isdir(self.options.data_dir):
272 raise testserver_base.OptionError('specified data dir not found: ' +
273 self.options.data_dir + ' exiting...')
274 my_data_dir = self.options.data_dir
275 else:
276 # Create the default path to our data dir, relative to the exe dir.
Asanka Herath0ec37152019-08-02 15:23:57 +0000277 my_data_dir = os.path.join(BASE_DIR, "..", "..", "data")
phajdan.jr@chromium.orgbf74e2b2010-08-17 20:07:11 +0000278
mattm@chromium.org830a3712012-11-07 23:00:07 +0000279 return my_data_dir
newt@chromium.org1fc32742012-10-20 00:28:35 +0000280
mattm@chromium.org830a3712012-11-07 23:00:07 +0000281 def create_server(self, server_data):
282 port = self.options.port
283 host = self.options.host
newt@chromium.org1fc32742012-10-20 00:28:35 +0000284
Adam Rice54443aa2018-06-06 00:11:54 +0000285 logging.basicConfig()
286
estark21667d62015-04-08 21:00:16 -0700287 # Work around a bug in Mac OS 10.6. Spawning a WebSockets server
288 # will result in a call to |getaddrinfo|, which fails with "nodename
289 # nor servname provided" for localhost:0 on 10.6.
Adam Rice54443aa2018-06-06 00:11:54 +0000290 # TODO(ricea): Remove this if no longer needed.
estark21667d62015-04-08 21:00:16 -0700291 if self.options.server_type == SERVER_WEBSOCKET and \
292 host == "localhost" and \
293 port == 0:
294 host = "127.0.0.1"
295
Ryan Sleevi3bfd15d2018-01-23 21:12:24 +0000296 # Construct the subjectAltNames for any ad-hoc generated certificates.
297 # As host can be either a DNS name or IP address, attempt to determine
298 # which it is, so it can be placed in the appropriate SAN.
299 dns_sans = None
300 ip_sans = None
301 ip = None
302 try:
303 ip = socket.inet_aton(host)
304 ip_sans = [ip]
305 except socket.error:
306 pass
307 if ip is None:
308 dns_sans = [host]
309
mattm@chromium.org830a3712012-11-07 23:00:07 +0000310 if self.options.server_type == SERVER_HTTP:
David Benjamin85999442021-11-22 21:01:55 +0000311 server = HTTPServer((host, port), TestPageHandler)
312 print('HTTP server started on http://%s:%d...' %
313 (host, server.server_port))
mattm@chromium.org830a3712012-11-07 23:00:07 +0000314
315 server.data_dir = self.__make_data_dir()
316 server.file_root_url = self.options.file_root_url
317 server_data['port'] = server.server_port
mattm@chromium.org830a3712012-11-07 23:00:07 +0000318 elif self.options.server_type == SERVER_WEBSOCKET:
mattm@chromium.org830a3712012-11-07 23:00:07 +0000319 # TODO(toyoshim): Remove following os.chdir. Currently this operation
320 # is required to work correctly. It should be fixed from pywebsocket side.
321 os.chdir(self.__make_data_dir())
322 websocket_options = WebSocketOptions(host, port, '.')
davidben@chromium.org009843a2014-06-03 00:13:08 +0000323 scheme = "ws"
mattm@chromium.org830a3712012-11-07 23:00:07 +0000324 if self.options.cert_and_key_file:
davidben@chromium.org009843a2014-06-03 00:13:08 +0000325 scheme = "wss"
mattm@chromium.org830a3712012-11-07 23:00:07 +0000326 websocket_options.use_tls = True
Sergey Ulanovdd8b8ea2017-09-08 22:53:25 +0000327 key_path = os.path.join(ROOT_DIR, self.options.cert_and_key_file)
328 if not os.path.isfile(key_path):
329 raise testserver_base.OptionError(
330 'specified server cert file not found: ' +
331 self.options.cert_and_key_file + ' exiting...')
332 websocket_options.private_key = key_path
333 websocket_options.certificate = key_path
334
mattm@chromium.org830a3712012-11-07 23:00:07 +0000335 if self.options.ssl_client_auth:
pneubeck@chromium.orgf5007112014-07-21 15:22:41 +0000336 websocket_options.tls_client_cert_optional = False
mattm@chromium.org830a3712012-11-07 23:00:07 +0000337 websocket_options.tls_client_auth = True
338 if len(self.options.ssl_client_ca) != 1:
339 raise testserver_base.OptionError(
340 'one trusted client CA file should be specified')
341 if not os.path.isfile(self.options.ssl_client_ca[0]):
342 raise testserver_base.OptionError(
343 'specified trusted client CA file not found: ' +
344 self.options.ssl_client_ca[0] + ' exiting...')
345 websocket_options.tls_client_ca = self.options.ssl_client_ca[0]
David Benjaminf025abe2021-09-17 22:59:19 +0000346 print('Trying to start websocket server on %s://%s:%d...' %
347 (scheme, websocket_options.server_host, websocket_options.port))
mattm@chromium.org830a3712012-11-07 23:00:07 +0000348 server = WebSocketServer(websocket_options)
David Benjaminf025abe2021-09-17 22:59:19 +0000349 print('WebSocket server started on %s://%s:%d...' %
350 (scheme, host, server.server_port))
mattm@chromium.org830a3712012-11-07 23:00:07 +0000351 server_data['port'] = server.server_port
ricea@chromium.orga52ebdc2014-07-29 07:42:29 +0000352 websocket_options.use_basic_auth = self.options.ws_basic_auth
Adam Rice9476b8c2018-08-02 15:28:43 +0000353 elif self.options.server_type == SERVER_PROXY:
354 ProxyRequestHandler.redirect_connect_to_localhost = \
355 self.options.redirect_connect_to_localhost
356 server = ThreadingHTTPServer((host, port), ProxyRequestHandler)
David Benjaminf025abe2021-09-17 22:59:19 +0000357 print('Proxy server started on port %d...' % server.server_port)
Adam Rice9476b8c2018-08-02 15:28:43 +0000358 server_data['port'] = server.server_port
mattm@chromium.org830a3712012-11-07 23:00:07 +0000359 elif self.options.server_type == SERVER_BASIC_AUTH_PROXY:
Adam Rice9476b8c2018-08-02 15:28:43 +0000360 ProxyRequestHandler.redirect_connect_to_localhost = \
Pavol Marko8ccaaed2018-01-04 18:40:04 +0100361 self.options.redirect_connect_to_localhost
Adam Rice34b2e312018-04-06 16:48:30 +0000362 server = ThreadingHTTPServer((host, port), BasicAuthProxyRequestHandler)
David Benjaminf025abe2021-09-17 22:59:19 +0000363 print('BasicAuthProxy server started on port %d...' % server.server_port)
mattm@chromium.org830a3712012-11-07 23:00:07 +0000364 server_data['port'] = server.server_port
erikkay@google.comd5182ff2009-01-08 20:45:27 +0000365 else:
mattm@chromium.org830a3712012-11-07 23:00:07 +0000366 raise testserver_base.OptionError('unknown server type' +
367 self.options.server_type)
erikkay@google.com70397b62008-12-30 21:49:21 +0000368
mattm@chromium.org830a3712012-11-07 23:00:07 +0000369 return server
erikkay@google.comd5182ff2009-01-08 20:45:27 +0000370
mattm@chromium.org830a3712012-11-07 23:00:07 +0000371 def add_options(self):
372 testserver_base.TestServerRunner.add_options(self)
Adam Rice9476b8c2018-08-02 15:28:43 +0000373 self.option_parser.add_option('--proxy', action='store_const',
374 const=SERVER_PROXY,
375 default=SERVER_HTTP, dest='server_type',
376 help='start up a proxy server.')
mattm@chromium.org830a3712012-11-07 23:00:07 +0000377 self.option_parser.add_option('--basic-auth-proxy', action='store_const',
378 const=SERVER_BASIC_AUTH_PROXY,
379 default=SERVER_HTTP, dest='server_type',
380 help='start up a proxy server which requires '
381 'basic authentication.')
382 self.option_parser.add_option('--websocket', action='store_const',
383 const=SERVER_WEBSOCKET, default=SERVER_HTTP,
384 dest='server_type',
385 help='start up a WebSocket server.')
mattm@chromium.org830a3712012-11-07 23:00:07 +0000386 self.option_parser.add_option('--cert-and-key-file',
387 dest='cert_and_key_file', help='specify the '
388 'path to the file containing the certificate '
389 'and private key for the server in PEM '
390 'format')
mattm@chromium.org830a3712012-11-07 23:00:07 +0000391 self.option_parser.add_option('--ssl-client-auth', action='store_true',
392 help='Require SSL client auth on every '
393 'connection.')
394 self.option_parser.add_option('--ssl-client-ca', action='append',
395 default=[], help='Specify that the client '
396 'certificate request should include the CA '
397 'named in the subject of the DER-encoded '
398 'certificate contained in the specified '
399 'file. This option may appear multiple '
400 'times, indicating multiple CA names should '
401 'be sent in the request.')
mattm@chromium.org830a3712012-11-07 23:00:07 +0000402 self.option_parser.add_option('--file-root-url', default='/files/',
403 help='Specify a root URL for files served.')
ricea@chromium.orga52ebdc2014-07-29 07:42:29 +0000404 # TODO(ricea): Generalize this to support basic auth for HTTP too.
405 self.option_parser.add_option('--ws-basic-auth', action='store_true',
406 dest='ws_basic_auth',
407 help='Enable basic-auth for WebSocket')
Pavol Marko8ccaaed2018-01-04 18:40:04 +0100408 self.option_parser.add_option('--redirect-connect-to-localhost',
409 dest='redirect_connect_to_localhost',
410 default=False, action='store_true',
411 help='If set, the Proxy server will connect '
412 'to localhost instead of the requested URL '
413 'on CONNECT requests')
erikkay@google.comd5182ff2009-01-08 20:45:27 +0000414
toyoshim@chromium.org16f57522012-10-24 06:14:38 +0000415
initial.commit94958cf2008-07-26 22:42:52 +0000416if __name__ == '__main__':
mattm@chromium.org830a3712012-11-07 23:00:07 +0000417 sys.exit(ServerRunner().main())