# Haproxy errorfile + keepalive?

**URL:** <https://discourse.haproxy.org/t/haproxy-errorfile-keepalive/2098>\
**Category:** Help!\
**Created:** [February 9, 2018, 12:52am UTC](https://discourse.haproxy.org/t/haproxy-errorfile-keepalive/2098 "2018-02-09T00:52:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikas](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@vikas](https://discourse.haproxy.org/u/vikas)\
**Post date:** [February 9, 2018, 12:52am UTC](https://discourse.haproxy.org/t/haproxy-errorfile-keepalive/2098/1 "2018-02-09T00:52:22Z")

</div>

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:

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

```

Here are the contents of the errorfile:

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

{"success":false}

```

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 12, 2018, 10:00pm UTC](https://discourse.haproxy.org/t/haproxy-errorfile-keepalive/2098/2 "2018-02-12T22:00:19Z")

</div>

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](https://www.mail-archive.com/haproxy@formilux.org/msg28939.html) 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
```

---

<div class="post-metadata">

**Author:** ![vikas](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@vikas](https://discourse.haproxy.org/u/vikas)\
**Post date:** [February 12, 2018, 10:22pm UTC](https://discourse.haproxy.org/t/haproxy-errorfile-keepalive/2098/3 "2018-02-12T22:22:37Z")

</div>

thank you @lukastribus!
