How yihaozhadan/http-proxy works
Main components
• Client Applications: These are the external HTTP clients that send POST requests (to endpoints like /delay and /failure).
• Request Handler: Responsible for parsing incoming HTTP requests and headers.
• Delay Simulator: Logic that implements constant and/or random delay configurations.
• Failure Simulator: Logic that uses the configured success probability (or failure rate) to simulate failures.
• Forwarder/Proxy Module: Forwards HTTP/HTTPS requests to the target URL (configured via environment variables or headers).
• Logger & Error Reporter: Captures detailed error reporting and logs for both successful and simulated-failure paths.
• Target Server: The external service to which the HTTP proxy forwards requests (e.g., https://httpbin.org/post or any custom URL via the “X-Proxy-Url” header).
• Configuration & Environment Components: Utilize environment variables (like TARGET_URL and SUCCESS_PROBABILITY) and dynamic header overrides to configure the behavior of the proxy.
Relationships and interactions
• How the Client sends a POST request to the HTTP Proxy.
• The Proxy’s internal decision process splitting between the delay simulation or the failure simulation endpoints.
• How the delay and failure simulation logic intervenes before passing the request to the Forwarder.
• The forwarded request from the proxy to the Target Server and the reverse flow of the response/error back to the client.
• That configuration comes from both static (environment variables) and dynamic (HTTP headers) sources, influencing the processing logic.
Architectural patterns and design principles
• Separation of concerns: the logic for delay vs. failure simulations is distinct from the core forwarding mechanism.
• That the system follows a proxy/middleware pattern where incoming requests are processed, potentially modified, and then relayed.
• That this is a microservice-like design with the possibility of containerized deployment (using Docker).
Technologies and specific tools
• Rust, as indicated by Cargo.toml, is the language for implementation.
• Docker and docker-compose for containerized deployment.
• Node.js script in the “perf-test” directory (failure-rate.js) which is likely used to simulate load or test failure rates.
• Environment Variable management tools (like .env files) for local development.
• Clearly separate the client, proxy, and target server components.
• For each path (delay simulation and failure simulation), illustrate how the configuration parameters (CUSTOM delays, success probabilities, header overrides) are applied.
• If desired, include a subsection for Docker-based deployment to illustrate how external requests enter via the container and invoke the service.
• Use clear labels for each component (e.g., “HTTP Proxy Service”, “Delay Simulator”, “Failure Simulator”, “Request Forwarder”, “Client”, “Target Server”, “Configuration Module”).
• From the Client to the HTTP Proxy (incoming HTTP POST).
• From the HTTP Proxy’s decision components (delay and failure modules) to the Request Forwarder.
• From the Request Forwarder to the Target Server.
• A separate node for Docker indicating container boundaries, which links into development and deployment practices.
Putting it all together
• Inside the HTTP Proxy, split out the relevant modules (request parsing, delay simulation, failure simulation, forwarding, logging/error handling).
• Annotations for configuration settings derived from environment variables and/or HTTP headers—indicating how they alter the behavior for endpoints /delay and /failure.