From a9921351fb4129b375b2b4f00ea53cd13ee41b52 Mon Sep 17 00:00:00 2001 From: Adrien Ferrand Date: Fri, 14 Jun 2019 19:22:49 +0200 Subject: [PATCH] Update proxy.py --- certbot-ci/certbot_integration_tests/utils/proxy.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/certbot-ci/certbot_integration_tests/utils/proxy.py b/certbot-ci/certbot_integration_tests/utils/proxy.py index 99259d1f1..938c092fa 100644 --- a/certbot-ci/certbot_integration_tests/utils/proxy.py +++ b/certbot-ci/certbot_integration_tests/utils/proxy.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import json import sys +import re import requests from six.moves import BaseHTTPServer, socketserver @@ -11,19 +12,17 @@ class _GracefulTCPServer(socketserver.TCPServer): def _get_port(mapping, host): - fqdn = host.split(':')[0] return [port for pattern, port in mapping.items() - if fqdn.endswith(pattern)][0] + if re.matches(pattern, host)][0] def _create_proxy(mapping): class ProxyHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): headers = {key.lower(): value for key, value in self.headers.items()} - url = '{0}:{1}{2}'.format('http://127.0.0.1', - _get_port(mapping, headers['host']), - self.path) - response = requests.get(url, headers=headers) + backend = [backend for pattern, backend in mapping.items() + if re.matches(pattern, host)][0] + response = requests.get(backend + self.path, headers=headers) self.send_response(response.status_code) for key, value in response.headers.items():