Commit 556007bb authored by Reza Naghibi's avatar Reza Naghibi Committed by Poul-Henning Kamp

Don't change the C-L if we detect a failed stream.

Previously we would read the response Content-Length from a failed oc,
which would make the error response valid. Now, if this is detected,
we don't touch the Content-Length.
parent 58fefad0
......@@ -425,7 +425,7 @@ cnt_transmit(struct worker *wrk, struct req *req)
status = http_GetStatus(req->resp);
head = !strcmp(req->http0->hd[HTTP_HDR_METHOD].b, "HEAD");
if (boc != NULL)
if (boc != NULL || (req->objcore->flags & (OC_F_FAILED)))
req->resp_len = clval;
else
req->resp_len = ObjGetLen(req->wrk, req->objcore);
......@@ -477,6 +477,11 @@ cnt_transmit(struct worker *wrk, struct req *req)
HSH_Cancel(wrk, req->objcore, boc);
if (!req->doclose && (req->objcore->flags & OC_F_FAILED))
/* The object we delivered failed due to a streaming error.
* Fail the request. */
req->doclose = SC_TX_ERROR;
if (boc != NULL)
HSH_DerefBoc(wrk, req->objcore);
......
varnishtest "A backend connection error gets returned as a valid short response"
barrier b1 sock 2
server s1 {
rxreq
txresp -nolen -hdr "Content-Length: 10"
barrier b1 sync
send "12345"
# Early connection close error
} -start
varnish v1 -vcl+backend {
import vtc;
sub vcl_deliver {
# Make sure we are streaming and give the backend time to error out
vtc.barrier_sync("${b1_sock}");
vtc.sleep(1s);
}
} -start
client c1 {
txreq
rxresphdrs
expect resp.http.Content-Length == "10"
recv 5
expect_close
} -run
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment