Conversation
…m via configured routes, forwards requests over pooled connections, parses upstream responses, and relays them back to clients.
There was a problem hiding this comment.
Code Review
This pull request implements a comprehensive proxy engine for the HTTP server, adding support for asynchronous request forwarding, header rewriting, and configurable retry policies. The changes include a new upstream HTTP codec, request serialization, and logic to handle early upstream responses within the connection pool. Review feedback identifies a critical use-after-free vulnerability during route registration, a protocol violation concerning the Via header in responses, and several opportunities for code refactoring to reduce duplication. Additionally, it is recommended to integrate the existing backoff logic into the retry mechanism.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb710daaf2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new HTTP proxy engine, enabling the server to forward requests to upstream services with configurable header rewriting and retry policies. Key changes include new configuration structures for proxy behavior, the implementation of ProxyHandler and ProxyTransaction to manage proxy request lifecycles, and HeaderRewriter and RetryPolicy for request/response transformation and error handling. The HttpServer and HttpRequest classes were updated to support proxy routing and client metadata propagation. Comprehensive unit and integration tests for the new proxy functionality have also been added. Review feedback indicates that the proxy's retry mechanism currently lacks backoff, which could lead to a thundering herd problem, and suggests implementing a timer-based deferred retry. Additionally, a duplicated string literal in HeaderRewriter should be refactored into a constant for better maintainability.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc8f351c37
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
LGTM |
Summary
A proxy engine that:
What was built
Adds the core proxy engine: receive a client HTTP request, select an upstream service via configured route, forward the request over a pooled connection, parse the upstream HTTP/1.1 response, and relay it back to the client.
Builds on the connection pool infrastructure from #13.
What’s new
Proxy engine (
ProxyHandler→ProxyTransaction)Per-upstream
ProxyHandlerStart()RouteAsyncPer-request
ProxyTransactionINITCHECKOUT_PENDINGSENDING_REQUESTAWAITING_RESPONSERECEIVING_BODYCOMPLETEshared_from_this()self-capture for async safetyConfig-driven auto-registration
proxysection auto-register routes at startupHttpServer::Proxy()API is also availableHTTP/2 downstream transparent
AsyncCompletionCallback) handles H1/H2 deliveryProxyTransactionis protocol-agnosticFoundation components
UpstreamHttpCodecllhttpinHTTP_RESPONSEmoderesume + discardloop)vector<pair<...>>HttpRequestSerializerHeaderRewriterX-Forwarded-ForappendX-Forwarded-ProtoViaHostrewriteConnectionRetryPolicyInfrastructure changes
HttpRequestclient_ipclient_tlsclient_fdHttpResponseBadGateway()andGatewayTimeout()factory methodsPoolPartition::ReturnConnectionIsClosing()checkProxyConfigroute_prefixstrip_prefixmethodsresponse_timeout_msheader_rewriteretryConfigLoaderNew files (14)
include/upstream/upstream_response.hinclude/upstream/upstream_http_codec.hllhttpresponse-mode parser with 1xx handlinginclude/upstream/http_request_serializer.hinclude/upstream/header_rewriter.hinclude/upstream/retry_policy.hinclude/upstream/proxy_transaction.hinclude/upstream/proxy_handler.hserver/upstream_http_codec.ccserver/http_request_serializer.ccserver/header_rewriter.ccserver/retry_policy.ccserver/proxy_transaction.ccserver/proxy_handler.cctest/proxy_test.hModified files
include/config/server_config.hProxyConfigstructsinclude/http/http_request.hclient_ip,client_tls,client_fd)include/http/http_response.hBadGateway(),GatewayTimeout()factoriesserver/config_loader.ccserver/http_connection_handler.ccserver/http2_session.ccserver/http_server.ccProxy(),RegisterProxyRoutes()server/pool_partition.ccIsClosing()check inReturnConnectionserver/http_response.ccBadGateway()/GatewayTimeout()implementationsMakefiletest_proxytargetKey design decisions
complete(HttpResponse)API requires fully-formed responses. Streaming deferred to v2.parser_.Reset()immediately after handler returns, so storingconst HttpRequest*would be a use-after-reset.MarkClosing()+ poolIsClosing()check prevents corrupted connection reuse.llhttpfireson_message_completefor100 Continue. Codec loop detects status< 200, callsllhttp_resume(), resets interim response, and continues parsing.weak_ptrin transport callbacksProxyTransaction→ lease →ConnectionHandler→ callbacks →ProxyTransaction.static_prefixProxyHandlerconstructor, not per request.Configuration example
{ "upstreams": [{ "name": "user-service", "host": "10.0.1.10", "port": 8081, "pool": { "max_connections": 64 }, "proxy": { "route_prefix": "/api/users", "strip_prefix": true, "methods": ["GET", "POST", "PUT", "DELETE"], "response_timeout_ms": 30000, "header_rewrite": { "set_x_forwarded_for": true, "rewrite_host": true }, "retry": { "max_retries": 1, "retry_on_connect_failure": true } } }] }Error mapping
502 Bad Gateway504 Gateway Timeout502 Bad Gateway502 Bad GatewayTest plan
50 new tests in
test/proxy_test.h(./test_runner proxy/-P):Unit tests (39)
UpstreamHttpCodec(11)HttpRequestSerializer(5)HeaderRewriter(8)RetryPolicy(9)ProxyConfigparsing (6)Integration tests (11)
strip_prefixValidation