# 502 Bad Gateway, response from upstream server is blocked by haproxy

**URL:** <https://discourse.haproxy.org/t/502-bad-gateway-response-from-upstream-server-is-blocked-by-haproxy/7692>\
**Category:** Help!\
**Created:** [May 27, 2022, 12:26pm UTC](https://discourse.haproxy.org/t/502-bad-gateway-response-from-upstream-server-is-blocked-by-haproxy/7692 "2022-05-27T12:26:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siva](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Siva](https://discourse.haproxy.org/u/Siva)\
**Post date:** [May 27, 2022, 12:26pm UTC](https://discourse.haproxy.org/t/502-bad-gateway-response-from-upstream-server-is-blocked-by-haproxy/7692/1 "2022-05-27T12:26:56Z")

</div>

Issue: Haproxy is blocking a response from the upstream server and responding back to the client with 502 Bad Gateway. The show error output says " error at position 181" Can anyone help in deciphering the message and the steps to rectify if any .

**HAProxy version** 2.4.17-9f97155  
**Show errors on Socket:**

[DATE] backend ew-backend (#4): invalid response  
frontend http-in (#3), server dest\_server (#1), event #0, src 127.0.0.1:28680  
buffer starts at 0 (including 0 out), 15593 free,  
len 791, wraps at 16336, error at position 181  
H1 connection flags 0x80002200, H1 stream flags 0x00004810  
H1 msg state MSG\_HDR\_NAME(17), H1 msg flags 0x00001414  
H1 chunk len 0 bytes, H1 body len 0 bytes :

00000 HTTP/1.1 200 OK\r\n  
00017 Cache-Control: no-cache\r\n  
00042 Pragma: no-cache\r\n  
00060 Content-Type: application/json; charset=utf-8\r\n  
00107 Expires: -1\r\n  
00120 Server: \r\n  
00130 Access-Control-Allow-Origin: none\r\n  
00165 X-XSS-Protection : 1; mode=block\r\n  
00200 X-Content-Type-Options : nosniff\r\n  
00234 X-Frame-Options: SAMEORIGIN\r\n  
00263 Accept-Bytes: none\r\n  
00283 Referrer-Policy: origin\r\n  
00308 X-Permitted-Cross-Domain-Policies: none\r\n  
00349 X-XSS-Protection: 1;mode=block [2]\r\n  
00385 X-Content-Type-Options: nosniff\r\n  
00418 Strict-Transport-Security: max-age=; includeSubDomains; preloa  
00488+ d\r\n  
00491 Content-security-policy: script-src ‘self’\r\n  
00535 ASPNET: \r\n  
00545 X-POWERED-BY: \r\n  
00561 X-ASPNET-VERSION: \r\n  
00581 X-ASPNETMVC-VERSION: \r\n  
00604 Date: \< **removed** \>1 GMT\r\n  
00641 Content-Length: 127\r\n  
00662 \r\n  
00664{Body  
00734}

---

<div class="post-metadata">

**Author:** ![Siva](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Siva](https://discourse.haproxy.org/u/Siva)\
**Post date:** [May 31, 2022, 5:49am UTC](https://discourse.haproxy.org/t/502-bad-gateway-response-from-upstream-server-is-blocked-by-haproxy/7692/2 "2022-05-31T05:49:37Z")

</div>

The upstream server was responding with invalid header names (whitespaces before the colon : in the response. So had to delete those headers in the config.
