Haproxy errorfile + keepalive?

We occasionally use haproxy to return a static API response (using the errorfile directive).
However, we’ve noticed that when we do so, haproxy closes the connection (instead of respecting the Connection: Keep-Alive header).

Is there any way to get haproxy to keep the connection alive, instead of closing it right away?

I’ve tried various permuations of setting option http-keep-alive, option httpclose, forcepersist, to no avail. We use haproxy 1.8.

Here’s the backend configuration:

### backend for blackholing heartbeats
backend mybackend
  mode http
  errorfile 503 /srv/www/response.http

Here are the contents of the errorfile:

HTTP/1.1 200 Ok
Content-Type: application/json; charset=utf-8
Connection: Keep-Alive
Content-Length: 17

{"success":false}

This is not possible in HTTP/1.1 and haproxy 1.8. It may work when you use H2 though (as it hides some of the H1 internals). With Haproxy 1.9 a lot of those old HTTP/1.1 assumptions will be removed from the code, so I’d assume those keep-alive restriction in the error paths will go away as well.

If you need something working for now, you will have to recirculate through another layer (make sure you are using CRLF line endings and that the content-length accounts for it, always check with curl):

backend mybackend
 mode http
 server listenerror 127.0.0.1:81
listen error
 bind 127.0.0.1:81
 mode http
 errorfile 503 /srv/www/response.http

thank you @lukastribus!