mirror of
https://github.com/certbot/certbot.git
synced 2026-04-04 00:24:59 -04:00
Fixes https://github.com/certbot/certbot/issues/8494. I left the `six` dependency pinned in `tests/letstest/requirements.txt` and `tools/oldest_constraints.txt` because `six` is still a transitive dependency with our current pinnings. The extra moving around of imports is due to me using `isort` to help me keep dependencies in sorted order after replacing imports of `six`. * remove some six usage in acme * remove six from acme * remove six.add_metaclass usage * fix six.moves.zip * fix six.moves.builtins.open * six.moves server fixes * 's/six\.moves\.range/range/g' * stop using six.moves.xrange * fix urllib imports * s/six\.binary_type/bytes/g * s/six\.string_types/str/g * 's/six\.text_type/str/g' * fix six.iteritems usage * fix itervalues usage * switch from six.StringIO to io.StringIO * remove six imports * misc fixes * stop using six.reload_module * no six.PY2 * rip out six * keep six pinned in oldest constraints * fix log_test.py * update changelog
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
#!/usr/bin/env python
|
|
# pylint: disable=missing-module-docstring
|
|
|
|
import http.server as BaseHTTPServer
|
|
import json
|
|
import re
|
|
import sys
|
|
|
|
import requests
|
|
|
|
from certbot_integration_tests.utils.misc import GracefulTCPServer
|
|
|
|
|
|
def _create_proxy(mapping):
|
|
# pylint: disable=missing-function-docstring
|
|
class ProxyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|
# pylint: disable=missing-class-docstring
|
|
def do_GET(self):
|
|
headers = {key.lower(): value for key, value in self.headers.items()}
|
|
backend = [backend for pattern, backend in mapping.items()
|
|
if re.match(pattern, headers['host'])][0]
|
|
response = requests.get(backend + self.path, headers=headers)
|
|
|
|
self.send_response(response.status_code)
|
|
for key, value in response.headers.items():
|
|
self.send_header(key, value)
|
|
self.end_headers()
|
|
self.wfile.write(response.content)
|
|
|
|
return ProxyHandler
|
|
|
|
|
|
if __name__ == '__main__':
|
|
http_port = int(sys.argv[1])
|
|
port_mapping = json.loads(sys.argv[2])
|
|
httpd = GracefulTCPServer(('', http_port), _create_proxy(port_mapping))
|
|
try:
|
|
httpd.serve_forever()
|
|
except KeyboardInterrupt:
|
|
pass
|