HTTP Reverse Proxy for HCM upstream/downstream Event-Driven Collaboration#
General flow of HTTP reverse proxy#
The overall HTTP reverse proxy flow for socket event driven collaboration is as follows:
The diagram shows that there are 4 types of events driving the whole process. Each of them will be analyzed in later sections.
To avoid getting lost in the details of the individual steps at once, the reader is advised to review the total flow of all the steps in the previous examples: Envoy Configuration Example under Istio.
The following is a 5-step explanation of the HTTP proxy process, using HTTP/1.1 as an example:
Downstream Read Request module collaboration
Downstream Request Router Module Collaboration
Upstream Write Request module collaboration
Upstream Read Response Module Collaboration
Downstream Write Response Module Collaboration
Downstream Read Request Module Collaboration#
A rough description of the process:
downstream socket readable callback
Http::ConnectionManagerImpl reads the socket and incrementally puts it into Http1::ConnectionImpl.
Http1::ConnectionImpl calls nghttp2 to incrementally interpret the HTTP request.
if nghttp2 thinks it has read the HTTP Request in its entirety, it calls `Http::ServerConnection::onMessageCompleteBase()’
Http::ServerConnection::onMessageCompleteBase()
First stops the downstream ReadReady listener.Http::ServerConnection::onMessageCompleteBase()
callsHttp::FilterManager
to initiate the decodeHeaders iteration of thehttp filter chain
.In general, the last http filter in the
http filter chain
is aRouter::Filter
, andRouter::Filter::decodeHeaders()
is called.The logic of
Router::Filter::decodeHeaders()
is shown below.
Downstream Request Router Module Collaboration#
A rough description of the process:
Router::Filter
,Router::Filter::decodeHeaders()
is called.Match to Cluster based on the configured Router rules.
If the Cluster connection pool object does not exist, create a new one.
create a new
Envoy::Router::UpstreamRequest
object. 5. callEnvoy::Router::UpstreamRequest
.call
Envoy::Router::UpstreamRequest::encodeHeaders(bool end_stream)
to encode HTTP headerafter a series of load balancing algorithms, match the host (endpoint) of the upstream.
if the connection to the selected upstream host is insufficient:
open a new socket fd (not connected)
Register the WriteReady / Connected event for the upstream socket FD. Prepare to write the upstream request in the event callback.
Initiate an asynchronous connection request to the upstream host with socket fd. 8.
associate downstream with upstream fd
Upstream Write Request Module Collaboration#
A rough description of the flow:
upstream socket write ready callback.
upstream socket write ready callback, find successful connection callback, associate upstream socket to
ConnectionPool::ActiveClient
.upstream socket write ready callback
upstream socket write ready callback, write upstream HTTP request.