http_FilterFields(sp->wrk, sp->fd, sp->http, sp->obj->http,
HTTPH_A_DELIVER);
+ /* Only HTTP 1.1 can do Chunked encoding */
+ if (sp->http->protover < 1.1 && !VTAILQ_EMPTY(&sp->obj->esibits))
+ http_Unset(sp->http, H_Transfer_Encoding);
+
TIM_format(TIM_real(), time_str);
http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Date: %s", time_str);
if (sp->wantbody && !VTAILQ_EMPTY(&sp->obj->esibits)) {
ESI_Deliver(sp);
} else if (sp->wantbody) {
- if (sp->esis > 0) {
+ if (sp->esis > 0 && sp->http->protover >= 1.1) {
sprintf(lenbuf, "%x\r\n", sp->obj->len);
sp->wrk->acct.hdrbytes +=
WRK_Write(sp->wrk, lenbuf, -1);
WRK_Write(sp->wrk, st->ptr, st->len);
}
assert(u == sp->obj->len);
- if (sp->esis > 0)
+ if (sp->esis > 0 && sp->http->protover >= 1.1)
WRK_Write(sp->wrk, "\r\n", -1);
}
if (WRK_Flush(sp->wrk))
VTAILQ_FOREACH(eb, &sp->obj->esibits, list) {
if (Tlen(eb->verbatim)) {
- WRK_Write(sp->wrk, eb->chunk_length, -1);
+ if (sp->http->protover >= 1.1)
+ WRK_Write(sp->wrk, eb->chunk_length, -1);
WRK_Write(sp->wrk, eb->verbatim.b, Tlen(eb->verbatim));
- WRK_Write(sp->wrk, "\r\n", -1);
+ if (sp->http->protover >= 1.1)
+ WRK_Write(sp->wrk, "\r\n", -1);
}
if (eb->include.b == NULL ||
sp->esis >= params->max_esi_includes)
sp->obj = obj;
}
- if (sp->esis == 0)
+ if (sp->esis == 0 && sp->http->protover >= 1.1)
WRK_Write(sp->wrk, "0\r\n\r\n", -1);
}
--- /dev/null
+# $Id$
+
+test "ESI includes for pre HTTP/1.1 cannot used chunked encoding"
+
+server s1 {
+ rxreq
+ expect req.url == "/foo/bar"
+ txresp -body {
+ <html>
+ Before include
+ <!--esi <esi:include src="body"/> -->
+ After include
+ }
+ rxreq
+ expect req.url == "/foo/body"
+ txresp -body {
+ Included file
+ }
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_fetch {
+ esi;
+ }
+} -start
+
+client c1 {
+ txreq -url /foo/bar -proto HTTP/1.1
+ rxresp
+ expect resp.status == 200
+ expect resp.bodylen == 151
+} -run
+
+client c1 {
+ txreq -url /foo/bar -proto HTTP/1.0
+ rxresp
+ expect resp.status == 200
+ expect resp.bodylen == 151
+} -run
+
+client c1 {
+ txreq -url /foo/bar -proto ""
+ rxresp
+ expect resp.status == 200
+ expect resp.bodylen == 151
+} -run