--- /dev/null
+# This test checks the H1 mux reports an error when the end of a message is
+# reached while the payload is smaller than the announced content-length,
+# instead of considering the message as finished. Otherwise, the server would
+# wait for the remaining payload until a timeout. Here, the content-length is
+# modified by an http-request rule. The end of the message is reported on the
+# last DATA block for the H1 client (c1) and alone on a NOOP block for the H2
+# client (c2), the END_STREAM being received in a separate empty DATA frame.
+# For the H1 client c3, the payload is sent once the request headers were
+# received by the server, so it is fast-forwarded (zero-copy) with the end of
+# the input. In that case, the error is reported on the server side, hence the
+# 502.
+
+varnishtest "H1 request with a payload smaller than the announced content-length"
+feature ignore_unknown_macro
+
+barrier b1 cond 2
+barrier b2 cond 2
+
+server s1 {
+ rxreqhdrs
+ expect req.http.content-length == "10"
+ expect_close
+} -start
+
+server s2 {
+ rxreqhdrs
+ expect req.http.content-length == "10"
+ # the payload is sent before the end of the message
+ recv 3
+ barrier b1 sync
+ expect_close
+} -start
+
+server s3 {
+ rxreqhdrs
+ expect req.http.content-length == "10"
+ barrier b2 sync
+ recv 3
+ expect_close
+} -start
+
+haproxy h1 -conf {
+ global
+ .if feature(THREAD)
+ thread-groups 1
+ .endif
+
+ defaults
+ mode http
+ timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
+ timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
+ timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
+
+ frontend fe1
+ bind "fd@${fe1}"
+ http-request set-header content-length 10
+ default_backend be1
+
+ frontend fe2
+ bind "fd@${fe2}" proto h2
+ http-request set-header content-length 10
+ default_backend be2
+
+ frontend fe3
+ bind "fd@${fe3}"
+ http-request set-header content-length 10
+ default_backend be3
+
+ backend be1
+ server s1 ${s1_addr}:${s1_port}
+
+ backend be2
+ server s2 ${s2_addr}:${s2_port}
+
+ backend be3
+ server s3 ${s3_addr}:${s3_port}
+} -start
+
+client c1 -connect ${h1_fe1_sock} {
+ txreq -req POST -url "/" -body "abc"
+ rxresp
+ expect resp.status == 500
+} -run
+
+client c2 -connect ${h1_fe2_sock} {
+ txpri
+ stream 0 {
+ txsettings
+ rxsettings
+ txsettings -ack
+ rxsettings
+ } -run
+
+ stream 1 {
+ txreq -req "POST" -scheme "https" -url "/" -hdr "content-length" "3" -nostrend
+ txdata -data "abc" -nostrend
+ barrier b1 sync
+ txdata -data ""
+ rxresp
+ expect resp.status == 500
+ } -run
+} -run
+
+client c3 -connect ${h1_fe3_sock} {
+ send "POST / HTTP/1.1\r\nhost: localhost\r\ncontent-length: 3\r\n\r\n"
+ barrier b2 sync
+ send "abc"
+ rxresp
+ expect resp.status == 502
+} -run
goto error;
}
h1m->curr_len -= count;
+ if (eom && h1m->curr_len) {
+ COUNT("less payload than announced (0-copy)");
+ TRACE_ERROR("less payload than announced",
+ H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
+ goto error;
+ }
if (!h1m->curr_len)
h1m->state = (eom ? H1_MSG_DONE : H1_MSG_TRAILERS);
}
goto error;
}
h1m->curr_len -= vlen;
+ if (last_data && h1m->curr_len) {
+ COUNT("less payload than announced");
+ TRACE_ERROR("less payload than announced",
+ H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
+ goto error;
+ }
}
else if (h1m->flags & H1_MF_CHNK) {
h1m->curr_len -= vlen;
if (!chunk_memcat(&outbuf, "0\r\n", 3))
goto full;
}
+ else if ((h1m->flags & H1_MF_CLEN) && h1m->curr_len) {
+ /* The trailers are after the payload */
+ COUNT("less payload than announced");
+ TRACE_ERROR("less payload than announced",
+ H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
+ goto error;
+ }
h1m->state = H1_MSG_TRAILERS;
break;
}
goto full;
last_data = 1;
}
+ else if ((h1m->flags & H1_MF_CLEN) && h1m->curr_len) {
+ COUNT("less payload than announced");
+ TRACE_ERROR("less payload than announced",
+ H1_EV_TX_DATA|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
+ goto error;
+ }
else
last_data = 1;
}
if (h1m->curr_len)
h1m->curr_len -= total;
- if (!h1m->curr_len && (h1m->flags & H1_MF_CLEN)) {
+ if ((sd->iobuf.flags & IOBUF_FL_EOI) && (h1m->flags & H1_MF_CLEN) &&
+ h1m->curr_len > (sd->iobuf.pipe ? sd->iobuf.pipe->data : 0)) {
+ /* The end of the message was reached but less payload than
+ * announced was forwarded (data still in the pipe will be sent
+ * later). Here we are called by the producer, so the stream
+ * must be woken up to be notified of the error.
+ */
+ h1s->flags |= H1S_F_PROCESSING_ERROR;
+ se_fl_set(h1s->sd, SE_FL_ERROR);
+ se_report_term_evt(h1s->sd, se_tevt_type_proto_err);
+ COUNT("less payload than announced (fast-forward)");
+ TRACE_ERROR("less payload than announced",
+ H1_EV_STRM_SEND|H1_EV_STRM_ERR|H1_EV_H1C_ERR|H1_EV_H1S_ERR, h1c->conn, h1s);
+ h1_alert(h1s);
+ }
+ else if (!h1m->curr_len && (h1m->flags & H1_MF_CLEN)) {
h1m->state = ((sd->iobuf.flags & IOBUF_FL_EOI) ? H1_MSG_DONE : H1_MSG_TRAILERS);
/* Remove H1C_F_CO_MSG_MORE if a content-length was set and all the payload was sent.
* At worst, it remains trailers from H2/QUIC messages that will be dropped.