06-backend_configuration.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from pathlib import Path
  2. from httphound.main import BaseProxyTest, BackendConfig, ProxyConfig
  3. class ExampleBackendConfigurationTest(BaseProxyTest):
  4. """A simple test to demonstrate some advanced backend configuration options
  5. """
  6. def __init__(self):
  7. super().__init__()
  8. self.description = "Example backend configuration"
  9. self.backend_config = BackendConfig(
  10. # Host and port are used both by the HTTP backend and in the
  11. # reverse proxy configuration
  12. host="127.0.0.1",
  13. port=9999,
  14. # Response headers, body and status are sent to the reverse proxy
  15. # at each request
  16. response_headers={
  17. "X-Test-1": "1234",
  18. "X-Test-2": "5678",
  19. },
  20. response_body="This is just a test body",
  21. response_status=301,
  22. )
  23. # Now we check some headers, body (regex) and status code
  24. self.expected_headers = {
  25. "x-test-2": "5678",
  26. }
  27. self.forbidden_client_headers = ["x-test-3"]
  28. self.expected_header_patterns = {
  29. "x-test-1": r"^[1-4]{4}$",
  30. }
  31. self.expected_body_pattern = r".*just.*"
  32. self.expected_status = 301
  33. self.proxy_config = ProxyConfig(
  34. binary_path=Path.home() / "bin/haproxy"
  35. )
  36. async def run_test(self):
  37. await self.make_request()
  38. return True