from pathlib import Path from proxytester.main import BaseProxyTest, BackendConfig, ProxyConfig class ExampleBackendConfigurationTest(BaseProxyTest): """A simple test to demonstrate some advanced backend configuration options """ def __init__(self): super().__init__() self.description = "Example backend configuration" self.backend_config = BackendConfig( # Host and port are used both by the HTTP backend and in the # reverse proxy configuration host="127.0.0.1", port="9999", # Response headers, body and status are sent to the reverse proxy # at each request response_headers={ "X-Test-1": "1234", "X-Test-2": "5678", }, response_body="This is just a test body", response_status=301, ) # Now we check some headers, body (regex) and status code self.expected_headers = { "x-test-2": "5678", } self.forbidden_client_headers = { "x-test-3": "abcd", } self.expected_header_patterns = { "x-test-1": r"^[1-4]{4}$", } self.expected_body_pattern = r".*just.*" self.expected_status = 301 self.proxy_config = ProxyConfig( binary_path=Path.home() / "bin/haproxy" ) async def run_test(self): await self.make_request() return True