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

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}

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.