PoC: add proxy support · sysfce2/python-pytest-httpserver@51125dd · GitHub
Skip to content

Commit 51125dd

Browse files
committed
PoC: add proxy support
Proof of concept implementation of the proxy support described in #39. It uses wsgiprox and re-uses werkzeug's own wsgi server, and it works like charm. Currently implemented in a separate class. See test_proxy.py for example. Two minor things: - wsgiprox uses gevent, yay - creates a 'ca' directory in cwd
1 parent 077a3f2 commit 51125dd

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

pytest_httpserver/__init__.py

Lines changed: 1 addition & 1 deletion

pytest_httpserver/httpserver.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import werkzeug.urls
2121
from werkzeug.datastructures import MultiDict
22+
from wsgiprox.wsgiprox import WSGIProxMiddleware
23+
2224

2325
URI_DEFAULT = ""
2426
METHOD_ALL = "__ALL"
@@ -1118,3 +1120,12 @@ def __exit__(self, *args, **kwargs):
11181120
"""
11191121
if self.is_running():
11201122
self.stop()
1123+
1124+
1125+
class HTTPProxy(HTTPServer):
1126+
def start(self):
1127+
proxy = WSGIProxMiddleware(self.application, "/proxy/", "wsgiprox")
1128+
self.server = make_server(self.host, self.port, proxy, ssl_context=self.ssl_context)
1129+
self.port = self.server.port # Update port (needed if `port` was set to 0)
1130+
self.server_thread = threading.Thread(target=self.thread_target)
1131+
self.server_thread.start()

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
python_requires=">=3.4",
2020
install_requires=[
2121
"typing;python_version<'3.5'",
22+
"wsgiprox",
2223
"werkzeug"
2324
],
2425
extras_require={

tests/test_proxy.py

Lines changed: 16 additions & 0 deletions

0 commit comments

Comments
 (0)