BUG/MEDIUM: fcgi-app: Use http_msg flags to know if C-L header can be added
Instead of relying on the HTX start-line flags, it is better to rely on
http_msg flags to know if a content-length header can be added or not. In
addition, if the header is added, HTTP_MSGF_CNT_LEN flag must be added.
Because of this bug, an invalid message can be emitted when the response is
compressed because it may contain C-L and a T-E headers.
This patch should fix the issue #1660. It must be backported as far as 2.2.
(cherry picked from commit 32af9a78303cc798eaf1dc506552862cc197e561)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 4bf907d961369102b1829aab40f67ee0123ea98e)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/fcgi-app.c b/src/fcgi-app.c
index ef22651..52b82b9 100644
--- a/src/fcgi-app.c
+++ b/src/fcgi-app.c
@@ -350,7 +350,7 @@
/* Add the header "Content-Length:" if possible */
sl = http_get_stline(htx);
if (s->txn->meth != HTTP_METH_HEAD && sl &&
- (sl->flags & (HTX_SL_F_XFER_LEN|HTX_SL_F_CLEN|HTX_SL_F_CHNK)) == HTX_SL_F_XFER_LEN &&
+ (msg->flags & (HTTP_MSGF_XFER_LEN|HTTP_MSGF_CNT_LEN|HTTP_MSGF_TE_CHNK)) == HTTP_MSGF_XFER_LEN &&
(htx->flags & HTX_FL_EOM)) {
struct htx_blk * blk;
char *end;
@@ -365,8 +365,10 @@
len += htx_get_blksz(blk);
}
end = ultoa_o(len, trash.area, trash.size);
- if (http_add_header(htx, ist("content-length"), ist2(trash.area, end-trash.area)))
+ if (http_add_header(htx, ist("content-length"), ist2(trash.area, end-trash.area))) {
sl->flags |= HTX_SL_F_CLEN;
+ msg->flags |= HTTP_MSGF_CNT_LEN;
+ }
}
return 1;