I am trying to implement an HTTP proxy server, aimed for low latency.
From what I understand, an HTTP proxy request is either a raw request with the HOST header set to the destination, or a CONNECT request that forwards the subsequential bytes as a raw TCP connection.
So I may implement it with the following behavior:
Read until the first space.
If it is
CONNECT, consume the head, establish a TCP connection to the destination, and response a head, then forward the subsequential data in both way.Otherwise, forward the whole request data to the destination and the whole response data to the client in parallel.
This would simply cover HTTP 1.1 and HTTPS connections.
But I am not sure if it would also work when it comes to HTTP2, due to the following questions:
Is a cleartext HTTP2 request sent via raw request or a
CONNECT? Is it guaranteed by some standard or commonly used client implementations?An HTTP2 connection would contain multiple streams, that may contain multiple
HOSTs. Is the client guaranteed to send requests that contain differentHOSTs via different proxy connection?.Does the client assume the specified proxy server is not HTTP2-awared and support the case of 'HTTP2 over HTTP 1.1 proxy'? Is it guaranteed by some standard or commonly used client implementations?
I could not even find a formal protocol specification about the detailed proxying behavior that may answer these questions.