What is the difference between Connection and Proxy-connection in HTTP header?
Asked Answered
A

2

20

What is the difference between Connection and Proxy-Connection in HTTP header?

Is the Proxy-Connection field added by the proxy? Or the client and server? What will the proxy, client or server do after receiving a header with these two fields with value keep-alive and close respectively?

Arnulfo answered 17/3, 2013 at 12:43 Comment(1)
A "smart" HTTP proxy will convert a Proxy-Connection header into an equivalent Connection header ("proving" that the proxy understands that the Connection header is a hop-by-hop header). A "dumb" HTTP/1.0 proxy will blindly forward the header to a client or server which is expected to ignore it.Chthonian
A
22

The Connection header is a standard header defined in the HTTP 1.0 and 1.1 specifications (RFC 2068 and RFC 2616) for maintaining keep-alive behaviour on an HTTP connection.

Proxy-Connection was an experimental header created by the Netscape developers to do similar things due to a misunderstanding about when Connection header could be used. It has never worked properly and is ignored by many of the common HTTP systems in existence today. When it does work as designed there is no difference between the two.

Ambience answered 31/5, 2013 at 2:12 Comment(1)
"due to a misunderstanding about when Connection header could be used." No, this was an explicit design to trick "legacy" HTTP/1.0 proxies not to blindly forward the hop-by-hop Connection header to a HTTP/1.1 client or server.Chthonian
V
4

Quoted from https://www.rfc-editor.org/rfc/rfc7230#appendix-A.1.2

In HTTP/1.0, each connection is established by the client prior to the request and closed by the server after sending the response. However, some implementations implement the explicitly negotiated ("Keep-Alive") version of persistent connections described in Section 19.7.1 of [RFC2068].

Some clients and servers might wish to be compatible with these previous approaches to persistent connections, by explicitly negotiating for them with a "Connection: keep-alive" request header field. However, some experimental implementations of HTTP/1.0 persistent connections are faulty; for example, if an HTTP/1.0 proxy server doesn't understand Connection, it will erroneously forward that header field to the next inbound server, which would result in a hung connection.

One attempted solution was the introduction of a Proxy-Connection header field, targeted specifically at proxies. In practice, this was also unworkable, because proxies are often deployed in multiple layers, bringing about the same problem discussed above.

As a result, clients are encouraged not to send the Proxy-Connection header field in any requests.

Clients are also encouraged to consider the use of Connection: keep-alive in requests carefully; while they can enable persistent connections with HTTP/1.0 servers, clients using them will need to monitor the connection for "hung" requests (which indicate that the client ought stop sending the header field), and this mechanism ought not be used by clients at all when a proxy is being used.

Vinery answered 28/5, 2019 at 1:40 Comment(1)
I am wondering why vanilla http_proxy=myproxy.io:8080 curl -v ... will actually send > Proxy-Connection: Keep-Alive when it is discouraged for clients.Shayne

© 2022 - 2024 — McMap. All rights reserved.