06-backend_configuration.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 = {
  28. "x-test-3": "abcd",
  29. }
  30. self.expected_header_patterns = {
  31. "x-test-1": r"^[1-4]{4}$",
  32. }
  33. self.expected_body_pattern = r".*just.*"
  34. self.expected_status = 301
  35. self.proxy_config = ProxyConfig(
  36. binary_path=Path.home() / "bin/haproxy"
  37. )
  38. async def run_test(self):
  39. await self.make_request()
  40. return True