Commit 9c9a9904 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make up our mind: Any req.* we receive from the client with fundamental

trouble gets failed back without VCL involvement.

Fixes	#1367
parent 6be44e1e
......@@ -270,7 +270,9 @@ static enum req_fsm_nxt
http1_dissect(struct worker *wrk, struct req *req)
{
const char *r_100 = "HTTP/1.1 100 Continue\r\n\r\n";
const char *r_400 = "HTTP/1.1 400 Bad Request\r\n\r\n";
const char *r_411 = "HTTP/1.1 411 Length Required\r\n\r\n";
const char *r_417 = "HTTP/1.1 417 Expectation Failed\r\n\r\n";
char *p;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
......@@ -299,8 +301,9 @@ http1_dissect(struct worker *wrk, struct req *req)
req->err_code = HTTP1_DissectRequest(req);
/* If we could not even parse the request, just close */
if (req->err_code == 400) {
if (req->err_code != 0) {
wrk->stats.client_req_400++;
(void)write(req->sp->fd, r_400, strlen(r_400));
SES_Close(req->sp, SC_RX_JUNK);
return (REQ_FSM_DONE);
}
......@@ -317,25 +320,27 @@ http1_dissect(struct worker *wrk, struct req *req)
return (REQ_FSM_DONE);
}
req->acct_req.req++;
req->ws_req = WS_Snapshot(req->ws);
req->doclose = http_DoConnection(req->http);
/* XXX: Expect headers are a mess */
if (req->err_code == 0 && http_GetHdr(req->http, H_Expect, &p)) {
if (http_GetHdr(req->http, H_Expect, &p)) {
if (strcasecmp(p, "100-continue")) {
wrk->stats.client_req_417++;
req->err_code = 417;
} else if (strlen(r_100) !=
write(req->sp->fd, r_100, strlen(r_100))) {
(void)write(req->sp->fd, r_417, strlen(r_417));
SES_Close(req->sp, SC_RX_JUNK);
return (REQ_FSM_DONE);
}
if (strlen(r_100) != write(req->sp->fd, r_100, strlen(r_100))) {
// XXX: stats counter ?
SES_Close(req->sp, SC_REM_CLOSE);
return (REQ_FSM_DONE);
}
} else if (req->err_code == 413)
wrk->stats.client_req_413++;
else
wrk->stats.client_req++;
}
wrk->stats.client_req++;
AZ(req->err_code);
req->acct_req.req++;
req->ws_req = WS_Snapshot(req->ws);
req->doclose = http_DoConnection(req->http);
http_Unset(req->http, H_Expect);
......
......@@ -251,9 +251,9 @@ htc_dissect_hdrs(struct http *hp, char *p, const struct http_conn *htc)
}
if (q - p > htc->maxhdr) {
VSLb(hp->vsl, SLT_BogoHeader, "%.*s",
VSLb(hp->vsl, SLT_BogoHeader, "Header too long: %.*s",
(int)(q - p > 20 ? 20 : q - p), p);
return (413);
return (400);
}
/* Empty header = end of headers */
......@@ -276,9 +276,9 @@ htc_dissect_hdrs(struct http *hp, char *p, const struct http_conn *htc)
http_VSLH(hp, hp->nhd);
hp->nhd++;
} else {
VSLb(hp->vsl, SLT_BogoHeader, "%.*s",
VSLb(hp->vsl, SLT_BogoHeader, "Too many headers: %.*s",
(int)(q - p > 20 ? 20 : q - p), p);
return (413);
return (400);
}
}
return (0);
......@@ -339,7 +339,7 @@ htc_splitline(struct http *hp, const struct http_conn *htc, int req)
hp->hd[h2].e = p;
if (!Tlen(hp->hd[h2]))
return (413);
return (400);
/* Skip SP */
for (; vct_issp(*p); p++) {
......
......@@ -23,7 +23,7 @@ client c1 {
expect resp.status == 200
txreq -url "/1" -hdr "1...5....0....5....0....5....0....5....0."
rxresp
expect resp.status == 413
expect resp.status == 400
} -run
client c1 {
......@@ -32,7 +32,7 @@ client c1 {
expect resp.status == 200
txreq -url "/2" -hdr "1...5....0....5\n ..0....5....0....5....0."
rxresp
expect resp.status == 413
expect resp.status == 400
} -run
client c1 {
......
varnishtest "blank GET"
server s1 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {
sub vcl_error {
return (restart);
}
} -start
client c1 {
send "GET \nHost: example.com\n\n"
rxresp
expect resp.status == 400
} -run
client c1 {
txreq -hdr "Expect: Santa-Claus"
rxresp
expect resp.status == 417
} -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