# Httpchk POST adding "Connection: close" after data

**URL:** <https://discourse.haproxy.org/t/httpchk-post-adding-connection-close-after-data/1875>\
**Category:** Help!\
**Created:** [December 7, 2017, 3:36pm UTC](https://discourse.haproxy.org/t/httpchk-post-adding-connection-close-after-data/1875 "2017-12-07T15:36:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahul.ghanate](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@rahul.ghanate](https://discourse.haproxy.org/u/rahul.ghanate)\
**Post date:** [December 7, 2017, 3:36pm UTC](https://discourse.haproxy.org/t/httpchk-post-adding-connection-close-after-data/1875/1 "2017-12-07T15:36:19Z")

</div>

I have setup haproxy 1.7.8 with option httpchk for my backend servers and have working GET requests.  
But while configuring the POST request with json data, I am getting error code 400.

Here is my check added in backend block,

> ```
> option httpchk POST /myService/endpt HTTP/1.1\r\nContent-Type:\ application/json;charset=UTF-8\r\nContent-Length:\ 169\r\n\r\n{\"inputs\":[{\"id\":1,\"productType\":\"productType\",\"productDescription\":\"productDescription\",\"metaDescription\":\"metaDescription\",\"metaTitle\":\"metaTitle\",\"rawxyz\":\"rawxyz\"}]}
> http-check expect rstatus (2|3)[0-9][0-9]
> 
> ```

After debugging with wireshark capture I came to know that, haproxy is adding _ **\r\f"Connection: close"\r\f\r\f** _ at the end of the post json data.  
From this manual, [https://www.haproxy.org/download/1.7/doc/configuration.txt](https://www.haproxy.org/download/1.7/doc/configuration.txt), I found that haproxy appends it if httpchk is combined with **_http-check expect_**.  
But it should be added to header fields and not after data.

This is causing packet parse failure, as it considering POST data as a part of header and reporting extra CRLF in headers.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/haproxy/original/1X/99bf68d48ab6538ba29d14a88307daa7b50c694f.png)

I would need the http-check expect block to verify error code, but then how would I avoid adding **Connection: close** at the end.  
I tried adding it as part of header itself, but it still appends one of its own.  
Is it a bug? I can’t find it in known bugs list.

---

<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:** [December 7, 2017, 11:39pm UTC](https://discourse.haproxy.org/t/httpchk-post-adding-connection-close-after-data/1875/2 "2017-12-07T23:39:06Z")

</div>

It was certainly a conscious decision to disable keep-alive:  
[http://git.haproxy.org/?p=haproxy-1.7.git;a=commitdiff;h=32602d23610981b48143d1f82885b8cfae286e0f](http://git.haproxy.org/?p=haproxy-1.7.git;a=commitdiff;h=32602d23610981b48143d1f82885b8cfae286e0f)

Obviously the way the code adds this header does not work for a HTTP request with a body, like HTTP POST request.

You can certainly just remove those 3 lines in src/checks.c by hand, this will stop the issue.

As for a proper solution this needs to be discussed on the mailing list. If you can send request to the mailing list, please CC Willy and Cyril (author and committer) and include the link I to the commit I posted above.

---

<div class="post-metadata">

**Author:** ![rahul.ghanate](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@rahul.ghanate](https://discourse.haproxy.org/u/rahul.ghanate)\
**Post date:** [December 8, 2017, 6:19am UTC](https://discourse.haproxy.org/t/httpchk-post-adding-connection-close-after-data/1875/3 "2017-12-08T06:19:04Z")

</div>

Thanks @lukastribus,  
I will send it to [haproxy@formilux.org](mailto:haproxy@formilux.org)
