mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-02 01:21:34 +01:00
Previously, a function qcs_http_handle_standalone_fin() was implemented to handle a received standalone FIN, bypassing app_ops layer decoding. However, this was removed as app_ops layer interaction is necessary. For example, HTTP/3 checks that FIN is never sent on the control uni stream. This patch reintroduces qcs_http_handle_standalone_fin(), albeit in a slightly diminished version. Most importantly, it is now the responsibility of the app_ops layer itself to use it, to avoid the shortcoming described above. The main objective of this patch is to be able to support standalone FIN in HTTP/0.9 layer. This is easily done via the reintroduction of qcs_http_handle_standalone_fin() usage. This will be useful to perform testing, as standalone FIN is a corner case which can easily be broken.
119 lines
3.0 KiB
C
119 lines
3.0 KiB
C
#include <haproxy/qmux_http.h>
|
|
|
|
#include <haproxy/api-t.h>
|
|
#include <haproxy/htx.h>
|
|
#include <haproxy/qmux_trace.h>
|
|
|
|
/* QUIC MUX rcv_buf operation using HTX data. Received data from stream <qcs>
|
|
* will be transferred as HTX in <buf>. Output buffer is expected to be of
|
|
* length <count>. <fin> will be set to signal the last data to receive on this
|
|
* stream.
|
|
*
|
|
* Return the size in bytes of transferred data.
|
|
*/
|
|
size_t qcs_http_rcv_buf(struct qcs *qcs, struct buffer *buf, size_t count,
|
|
char *fin)
|
|
{
|
|
struct htx *qcs_htx = NULL;
|
|
struct htx *cs_htx = NULL;
|
|
size_t ret = 0;
|
|
|
|
TRACE_ENTER(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs);
|
|
|
|
*fin = 0;
|
|
qcs_htx = htx_from_buf(&qcs->rx.app_buf);
|
|
if (htx_is_empty(qcs_htx)) {
|
|
/* Set buffer data to 0 as HTX is empty. */
|
|
htx_to_buf(qcs_htx, &qcs->rx.app_buf);
|
|
goto end;
|
|
}
|
|
|
|
ret = qcs_htx->data;
|
|
|
|
cs_htx = htx_from_buf(buf);
|
|
if (htx_is_empty(cs_htx) && htx_used_space(qcs_htx) <= count) {
|
|
/* EOM will be copied to cs_htx via b_xfer(). */
|
|
if (qcs_htx->flags & HTX_FL_EOM)
|
|
*fin = 1;
|
|
|
|
htx_to_buf(cs_htx, buf);
|
|
htx_to_buf(qcs_htx, &qcs->rx.app_buf);
|
|
b_xfer(buf, &qcs->rx.app_buf, b_data(&qcs->rx.app_buf));
|
|
goto end;
|
|
}
|
|
|
|
htx_xfer_blks(cs_htx, qcs_htx, count, HTX_BLK_UNUSED);
|
|
BUG_ON(qcs_htx->flags & HTX_FL_PARSING_ERROR);
|
|
|
|
/* Copy EOM from src to dst buffer if all data copied. */
|
|
if (htx_is_empty(qcs_htx) && (qcs_htx->flags & HTX_FL_EOM)) {
|
|
cs_htx->flags |= HTX_FL_EOM;
|
|
*fin = 1;
|
|
}
|
|
|
|
cs_htx->extra = qcs_htx->extra ? (qcs_htx->data + qcs_htx->extra) : 0;
|
|
htx_to_buf(cs_htx, buf);
|
|
htx_to_buf(qcs_htx, &qcs->rx.app_buf);
|
|
ret -= qcs_htx->data;
|
|
|
|
end:
|
|
TRACE_LEAVE(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs);
|
|
|
|
return ret;
|
|
}
|
|
|
|
int qcs_http_handle_standalone_fin(struct qcs *qcs)
|
|
{
|
|
struct buffer *appbuf;
|
|
struct htx *htx;
|
|
int eom;
|
|
|
|
if (!(appbuf = qcc_get_stream_rxbuf(qcs)))
|
|
goto err;
|
|
|
|
htx = htx_from_buf(appbuf);
|
|
eom = htx_set_eom(htx);
|
|
htx_to_buf(htx, appbuf);
|
|
if (!eom)
|
|
goto err;
|
|
|
|
return 0;
|
|
|
|
err:
|
|
return -1;
|
|
}
|
|
|
|
/* QUIC MUX snd_buf operation using HTX data. HTX data will be transferred from
|
|
* <buf> to <qcs> stream buffer. Input buffer is expected to be of length
|
|
* <count>. <fin> will be set to signal the last data to send for this stream.
|
|
*
|
|
* Return the size in bytes of transferred data.
|
|
*/
|
|
size_t qcs_http_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count,
|
|
char *fin)
|
|
{
|
|
struct htx *htx;
|
|
size_t ret;
|
|
int eom = 0;
|
|
|
|
TRACE_ENTER(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs);
|
|
|
|
htx = htxbuf(buf);
|
|
|
|
/* Extra care required for HTTP/1 responses without Content-Length nor
|
|
* chunked encoding. In this case, shutw callback will be use to signal
|
|
* the end of the message. QC_SF_UNKNOWN_PL_LENGTH is set to prevent a
|
|
* RESET_STREAM emission in this case.
|
|
*/
|
|
if (htx->extra && htx->extra == HTX_UNKOWN_PAYLOAD_LENGTH)
|
|
qcs->flags |= QC_SF_UNKNOWN_PL_LENGTH;
|
|
|
|
eom = (htx->flags & HTX_FL_EOM);
|
|
ret = qcs->qcc->app_ops->snd_buf(qcs, buf, count);
|
|
*fin = (eom && !b_data(buf));
|
|
|
|
TRACE_LEAVE(QMUX_EV_STRM_SEND, qcs->qcc->conn, qcs);
|
|
|
|
return ret;
|
|
}
|