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.
This commit is contained in:
Christopher Faulet 2022-04-15 15:26:24 +02:00
parent f7ff9cbfe1
commit 32af9a7830

View File

@ -350,7 +350,7 @@ static int fcgi_flt_http_headers(struct stream *s, struct filter *filter, struct
/* 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 @@ static int fcgi_flt_http_headers(struct stream *s, struct filter *filter, struct
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;