From: des Date: Thu, 5 Oct 2006 11:57:35 +0000 (+0000) Subject: RFC 2616 says "All 1xx (informational), 204 (no content), and 304 (not X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6454b1b6fb1658df9587eb3f9be82c6fa880869;p=varnish RFC 2616 says "All 1xx (informational), 204 (no content), and 304 (not modified) responses MUST NOT include a message-body," so Content-Length: is not needed in these cases (and Apache does indeed not include it). This causes PassBody() to call pass_straight() with a NULL length argument, which waits until the connection is closed by the server. PassBody() should not call pass_*() at all for responses that are known to be bodyless. Submitted by: Dagfinn Ilmari Mannsåker git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1138 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index e4ecc22b..2828a607 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -371,6 +371,7 @@ void http_Setup(struct http *ht, void *space, unsigned len); int http_GetHdr(struct http *hp, const char *hdr, char **ptr); int http_GetHdrField(struct http *hp, const char *hdr, const char *field, char **ptr); int http_GetStatus(struct http *hp); +int http_IsBodyless(struct http *hp); int http_HdrIs(struct http *hp, const char *hdr, const char *val); int http_GetTail(struct http *hp, unsigned len, char **b, char **e); int http_Read(struct http *hp, int fd, void *b, unsigned len); diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 678dbe29..56f22f1d 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -316,6 +316,21 @@ http_GetStatus(struct http *hp) NULL /* XXX */, 10)); } +/*--------------------------------------------------------------------- + * All 1xx (informational), 204 (no content), and 304 (not modified) + * responses MUST NOT include a message-body. + */ + +int +http_IsBodyless(struct http *hp) +{ + int status; + + status = http_GetStatus(hp); + return (status >= 100 && status < 200) + || status == 204 || status == 304; +} + /*-------------------------------------------------------------------- * Dissect the headers of the HTTP protocol message. * Detect conditionals (headers which start with '^[Ii][Ff]-') diff --git a/varnish-cache/bin/varnishd/cache_pass.c b/varnish-cache/bin/varnishd/cache_pass.c index 694e6fa2..7df39b47 100644 --- a/varnish-cache/bin/varnishd/cache_pass.c +++ b/varnish-cache/bin/varnishd/cache_pass.c @@ -201,6 +201,8 @@ PassBody(struct sess *sp) cls = pass_straight(sp, vc->fd, vc->http, NULL); else if (http_HdrIs(vc->http, H_Transfer_Encoding, "chunked")) cls = pass_chunked(sp, vc->fd, vc->http); + else if (http_IsBodyless(vc->http)) + cls = 0; else { cls = pass_straight(sp, vc->fd, vc->http, NULL); }