HAProxy community

Convert HTTP/1.0 from clients into HTTP/1.1 to backends

My HAProxy 1.9.x instance is receiving a mix of HTTP/1.0 and HTTP/1.1 requests from clients (clients are mostly things like curl, wget and http libraries, not web browsers).

I can see from the logs that when HAProxy receives a HTTP/1.0 request from a client, it makes a HTTP/1.0 request to a backend. I.e., it doesn’t convert it to HTTP/1.1 before handing off to the backend. This is messing with keepalive connections to the backend: for HTTP/1.0 requests, the backend server (nginx) returns a “Connection: Close” response header, and Haproxy closes that specific connection.

Is it possible to tell Haproxy to only ever make HTTP/1.1 requests to backends?

I’m aware of the possibility to use HTTP/2 to backends with http-use-htx. But I’d like to keep things plain and simple if possible.

You may enable the HTX with the option http-use-htx both on your frontend and your backend (or you may set it in your defaults section). And then you may add the header Connection: keep-alive on your HTTP/1.0 requests by adding the following http-request rule:

  http-request set-header Connection "keep-alive" if { req.ver "1.0" }

It doesn’t work with the HTTP legacy mode because the server connection depends on the client one more deeply than with the HTX mode. Note also, with HAProxy 2.0, the HTX is enabled by default. It also tries, as far as possible, to keep the server connection alive. So, in your case, the http-request is also unnecessary. It works “by design” with HAProxy 2.0 :slight_smile:

Cool, thanks, I will try that!

And yes, will eventually switch to HAProxy 2.0. I’m very new to HAProxy and want to start out with the mature version, before jumping on to the just-released version…