HTX_BLK_TLR = 5, /* trailer name/value block */
HTX_BLK_EOT = 6, /* end-of-trailers block */
HTX_BLK_RAW_DATA = 7, /* raw data block (tunneled data) */
- /* 8 .. 14 unused */
+ HTX_BLK_NOOP = 8, /* no-op block, carries nothing, may carry the EOM flag */
HTX_BLK_UNUSED = 15, /* unused/removed block */
};
return blk;
}
-/* Adds an HTX block of type EOH or EOT in <htx>. It returns the new block on
- * success. Otherwise, it returns NULL.
+/* Adds an HTX block of type EOH, EOT or NOOP in <htx>. It returns the new
+ * block on success. Otherwise, it returns NULL.
*/
static inline struct htx_blk *htx_add_endof(struct htx *htx, enum htx_blk_type type)
{
return blk;
}
+/* Adds a NOOP block in <htx>. It carries no data and nothing is emitted when
+ * it is encountered by the consumers. But, like the EOH and EOT blocks, its
+ * size is 1 to be able to wake the endpoint up when it is emitted alone. It
+ * may carry the EOM flag and it is allowed anywhere in the message.
+ *
+ * It returns the new block on success. Otherwise, it returns NULL.
+ */
+static inline struct htx_blk *htx_add_noop(struct htx *htx)
+{
+ return htx_add_endof(htx, HTX_BLK_NOOP);
+}
+
+
/* Add all headers from the list <hdrs> into the HTX message <htx>, followed by
* the EOH. On success, it returns the last block inserted (the EOH), otherwise
* NULL is returned.
/* Set EOM flag in <htx>. This function must always be called to report the end
* of the message. Corresponding flags must never be added by hand, except from
* the HTX API itself. It must also be called after the last block of the
- * message was added. Finally, this function takes care to add an EOT block if
- * the HTX message is empty.
+ * message was added. Finally, this function takes care to add a NOOP block if
+ * the HTX message is empty, so the EOM flag is not carried by an EOT block.
*
* Returns 1 on success else 0.
*/
struct htx_blk *blk;
if (htx_is_empty(htx)) {
- if (!htx_add_endof(htx, HTX_BLK_EOT))
+ if (!htx_add_noop(htx))
return 0;
}
BUG_ON(htx_get_blk_type(blk) != HTX_BLK_EOH &&
htx_get_blk_type(blk) != HTX_BLK_EOT &&
+ htx_get_blk_type(blk) != HTX_BLK_NOOP &&
htx_get_blk_type(blk) != HTX_BLK_DATA);
blk->flags |= HTX_BLK_FL_EOM;
return 1;
return htx_append_msg(htx, htx_msg);
}
-/* Remove all blocks except headers. Trailers will also be removed too. The EOM
- * flag, if set on the payload part, it is then reinserted. It means a EOT black
- * could be added if the message only contains payload.
+/* Remove all blocks except headers. Trailers will also be removed too. The
+ * EOM flag, if set on the payload part, it is then reinserted. It means a
+ * NOOP block could be added if the message only contains payload.
*/
static inline void htx_skip_msg_payload(struct htx *htx)
{
case HTX_BLK_RAW_DATA: return "HTX_BLK_RAW_DATA";
case HTX_BLK_TLR: return "HTX_BLK_TLR";
case HTX_BLK_EOT: return "HTX_BLK_EOT";
+ case HTX_BLK_NOOP: return "HTX_BLK_NOOP";
case HTX_BLK_UNUSED: return "HTX_BLK_UNUSED";
default: return "HTX_BLK_???";
};
* carried by this block. It was lost if the block
* was removed and was the last one of the
* message. In this case, it must be restored,
- * adding an EOT block to support it.
+ * adding a NOOP block to support it.
*/
if (!htx_msg_ended(htx)) {
unsigned int data = htx->data;
list[hdr].v = htx_get_blk_value(htx, blk);
hdr++;
}
- else {
+ else if (type != HTX_BLK_NOOP) {
TRACE_ERROR("unexpected HTX block", H3_EV_TX_FRAME|H3_EV_TX_HDR, qcs->qcc->conn, qcs);
goto err;
}
}
break;
+ case HTX_BLK_NOOP:
+ /* Nothing is emitted for a NOOP block. But if it
+ * carries the EOM flag, the end of the message is
+ * reported.
+ */
+ if (blk->flags & HTX_BLK_FL_EOM) {
+ TRACE_USER("transcoding last HTX message", H3_EV_STRM_SEND, qcs->qcc->conn, qcs);
+ *fin = 1;
+ }
+ htx_remove_blk(htx, blk);
+ total += bsize;
+ count -= bsize;
+ break;
+
default:
htx_remove_blk(htx, blk);
total += bsize;
}
__fallthrough;
+ case HTX_BLK_NOOP:
+ /* Nothing is emitted for a NOOP block. But if it
+ * carries the EOM flag, an empty STDIN record
+ * is sent to signal the end of the request.
+ */
+ if (blk->flags & HTX_BLK_FL_EOM) {
+ TRACE_PROTO("sending FCGI STDIN record", FCGI_EV_TX_RECORD|FCGI_EV_TX_STDIN, fconn->conn, fstrm, htx);
+ ret = fcgi_strm_send_empty_stdin(fconn, fstrm);
+ if (!ret)
+ goto done;
+ }
+ __fallthrough;
+
default:
remove_blk:
htx_remove_blk(htx, blk);
h1m->state = H1_MSG_TRAILERS;
break;
}
+ else if (type == HTX_BLK_NOOP) {
+ /* Consume the NOOP block, nothing is emitted. If it
+ * carries the EOM flag, the end of the message is
+ * reported, exactly like a last DATA block.
+ */
+ if (blk->flags & HTX_BLK_FL_EOM) {
+ if ((!(h1m->flags & H1_MF_RESP) && (h1s->flags & H1S_F_BODYLESS_REQ)) ||
+ ((h1m->flags & H1_MF_RESP) && (h1s->flags & H1S_F_BODYLESS_RESP))) {
+ last_data = 1;
+ }
+ else if (h1m->flags & H1_MF_CHNK) {
+ if (h1m->curr_len) {
+ COUNT("chunk smaller than announced");
+ TRACE_ERROR("chunk smaller than announced",
+ H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
+ goto error;
+ }
+ /* Emit the last chunk for chunked messages */
+ if (!chunk_memcat(&outbuf, "0\r\n\r\n", 5))
+ goto full;
+ last_data = 1;
+ }
+ else
+ last_data = 1;
+ }
+ }
else
goto error;
if (!h1_format_htx_data(v, &outbuf, 0))
goto full;
}
+ else if (type == HTX_BLK_NOOP) {
+ /* Consume the NOOP block, nothing is emitted */
+ }
else
goto error;
}
h1m->state = H1_MSG_DONE;
}
- else
- goto error;
+ else if (type == HTX_BLK_NOOP) {
+ /* Consume the NOOP block, nothing is emitted */
+ }
nextblk:
ret += sz;
int ret = 0;
int hdr;
int idx;
+ int eom = 0;
TRACE_ENTER(H2_EV_TX_FRAME|H2_EV_TX_HDR, h2c->conn, h2s);
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)
+ if (type == HTX_BLK_EOT) {
+ eom = !!(blk->flags & HTX_BLK_FL_EOM);
break;
+ }
if (type == HTX_BLK_TLR) {
if (unlikely(hdr >= sizeof(list)/sizeof(list[0]) - 1)) {
TRACE_ERROR("too many headers", H2_EV_TX_FRAME|H2_EV_TX_HDR|H2_EV_H2S_ERR, h2c->conn, h2s);
list[hdr].v = htx_get_blk_value(htx, blk);
hdr++;
}
- else {
+ else if (type != HTX_BLK_NOOP) {
TRACE_ERROR("will not encode unexpected htx block", H2_EV_TX_FRAME|H2_EV_TX_HDR|H2_EV_H2S_ERR, h2c->conn, h2s);
goto fail;
}
/* 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 */
- memcpy(outbuf.area, "\x00\x00\x00\x01\x05", 5);
+ /* 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;
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.
+ * 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.
*/
+ BUG_ON(!eom);
outbuf.area[3] = H2_FT_DATA;
outbuf.area[4] = H2_F_DATA_END_STREAM;
}
h2c->flags &= ~H2_CF_SHTS_UPDATED;
}
- if (h2s->st == H2_SS_OPEN)
- h2s->st = H2_SS_HLOC;
- else
- h2s_close(h2s);
+ if (eom) {
+ if (h2s->st == H2_SS_OPEN)
+ h2s->st = H2_SS_HLOC;
+ else
+ h2s_close(h2s);
+ }
/* OK we could properly deliver the response */
done:
}
break;
+ case HTX_BLK_NOOP:
+ /* Nothing is emitted for a NOOP block. But if it
+ * carries the EOM flag, the end of the message
+ * is reported, like for an empty DATA block.
+ */
+ if (blk->flags & HTX_BLK_FL_EOM) {
+ h2s->flags &= ~H2_SF_MORE_HTX_DATA;
+ if (!(h2s->flags & H2_SF_BODY_TUNNEL)) {
+ if (h2_send_empty_data_es(h2s) > 0) {
+ if (h2s->st == H2_SS_OPEN)
+ h2s->st = H2_SS_HLOC;
+ else
+ h2s_close(h2s);
+ }
+ }
+ }
+ htx_remove_blk(htx, blk);
+ total += bsize;
+ count -= bsize;
+ break;
+
default:
htx_remove_blk(htx, blk);
total += bsize;