* are automatically removed from the message. The htx message is assumed to be
* valid since produced from the internal code. Processing stops when meeting
* the EOT, which *is* removed. All trailers are processed at once and sent as a
- * single frame. The ES flag is always set.
+ * single frame. The ES flag is always set: in H2, the trailers always end the
+ * stream, even if the EOT block does not carry the EOM flag.
*/
static size_t h2s_make_trailers(struct h2s *h2s, struct htx *htx)
{
int ret = 0;
int hdr;
int idx;
- int eom = 0;
int drop;
TRACE_ENTER(H2_EV_TX_FRAME|H2_EV_TX_HDR, h2c->conn, h2s);
hdr = 0;
/* Skip the trailers if the corresponding conf option was set. But the
- * blocks must still be parsed to find the EOT and to know if the
- * message is finished, to emit the ES flag.
+ * blocks must still be parsed to find the EOT. In all cases, the ES
+ * flag is emitted because the trailers always end the stream.
*/
drop = ((!(h2c->flags & H2_CF_IS_BACK) && (h2c->proxy->options & PR_O_HTTP_DROP_RES_TRLS)) ||
((h2c->flags & H2_CF_IS_BACK) && (h2c->proxy->options & PR_O_HTTP_DROP_REQ_TRLS)));
for (blk = htx_get_head_blk(htx); blk; blk = htx_get_next_blk(htx, blk)) {
type = htx_get_blk_type(blk);
- if (type == HTX_BLK_EOT) {
- eom = !!(blk->flags & HTX_BLK_FL_EOM);
+ if (type == HTX_BLK_EOT)
break;
- }
if (type == HTX_BLK_TLR) {
if (drop)
continue;
/* marker for end of trailers */
list[hdr].n = ist("");
- /* An EOT block without the EOM flag means the message is not
- * finished. The trailers frame must not carry the END_STREAM flag
- * and, if there is nothing to emit, it is simply skipped.
- */
- if (!eom && !hdr)
- goto done;
-
mbuf = br_tail(h2c->mbuf);
retry:
if (!h2_get_buf(h2c, mbuf)) {
if (outbuf.size < 9)
goto full;
- /* len: 0x000000 (fill later), type: 1(HEADERS), flags: ENDH=4[+ES=1 if eom] */
- memcpy(outbuf.area, "\x00\x00\x00\x01\x04", 5);
- if (eom)
- outbuf.area[4] |= 0x01;
+ /* len: 0x000000 (fill later), type: 1(HEADERS), flags: ENDH=4,ES=1 */
+ memcpy(outbuf.area, "\x00\x00\x00\x01\x05", 5);
write_n32(outbuf.area + 5, h2s->id); // 4 bytes
outbuf.data = 9;
-
/* encode all headers */
for (idx = 0; idx < hdr; idx++) {
/* these ones do not exist in H2 or must not appear in
* received an empty trailers block followed or we removed its
* contents above). Because of this we can't send a HEADERS
* frame, so we have to cheat and instead send an empty DATA
- * frame conveying the ES flag. It can only be done when the
- * message is finished, an empty DATA frame without the ES
- * flag is pointless.
+ * frame conveying the ES flag.
*/
- BUG_ON(!eom);
outbuf.area[3] = H2_FT_DATA;
outbuf.area[4] = H2_F_DATA_END_STREAM;
}
h2c->flags &= ~H2_CF_SHTS_UPDATED;
}
- if (eom) {
- if (h2s->st == H2_SS_OPEN)
- h2s->st = H2_SS_HLOC;
- else
- h2s_close(h2s);
- }
+ if (h2s->st == H2_SS_OPEN)
+ h2s->st = H2_SS_HLOC;
+ else
+ h2s_close(h2s);
/* OK we could properly deliver the response */
- done:
/* remove all header blocks till the end and compute the corresponding size. */
ret = 0;
blk = htx_get_head_blk(htx);