Commit 7d034f34 authored by Dag Erling Smørgrav's avatar Dag Erling Smørgrav

Merged revisions 1967-1968,1970,1984,1986-1989,1992-1993,1995-1998 via svnmerge from

svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache

........
  r1967 | phk | 2007-09-20 10:44:59 +0200 (Thu, 20 Sep 2007) | 2 lines
  
  Add a http_GetProto() function
........
  r1968 | phk | 2007-09-20 10:46:25 +0200 (Thu, 20 Sep 2007) | 8 lines
  
  After we moved pass to use the same code as fetch, we have run into
  a unnecessary connection timeout wait when the returned object does
  not have a body.
  
  Rework the "does this response have a body" logic to be more in line
  with the RFC.
........
  r1970 | phk | 2007-09-20 12:44:18 +0200 (Thu, 20 Sep 2007) | 4 lines
  
  Fix a brain-o in my last commit.  "cls" is a flag for closing the fd,
  not for generating Content-Length: header.
........
  r1997 | phk | 2007-09-23 15:46:43 +0200 (Sun, 23 Sep 2007) | 6 lines
  
  Fix another cornercase that fell out as part of the pass->fetch rewrite:
  
  If we pass a HEAD request, we should not rewrite it to GET and not expect
  a body either.
........
  r1998 | des | 2007-09-23 16:19:42 +0200 (Sun, 23 Sep 2007) | 2 lines
  
  Reverse the logic in r1997 from !is_get to is_head.
........


git-svn-id: http://www.varnish-cache.org/svn/branches/1.1@1999 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 619499f8
......@@ -427,6 +427,8 @@ 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);
const char *http_GetReq(struct http *hp);
const char *http_GetProto(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);
......
......@@ -259,11 +259,10 @@ Fetch(struct sess *sp)
struct worker *w;
char *b;
int cls;
int body = 1; /* XXX */
struct http *hp, *hp2;
struct storage *st;
struct bereq *bereq;
int len;
int len, mklen, is_head;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
......@@ -272,6 +271,7 @@ Fetch(struct sess *sp)
w = sp->wrk;
bereq = sp->bereq;
hp = bereq->http;
is_head = (strcasecmp(http_GetReq(hp), "head") == 0);
sp->obj->xid = sp->xid;
......@@ -282,7 +282,6 @@ Fetch(struct sess *sp)
http_Write(w, hp, 0);
if (WRK_Flush(w)) {
/* XXX: cleanup */
return (1);
}
......@@ -327,17 +326,37 @@ Fetch(struct sess *sp)
http_FilterFields(sp->wrk, sp->fd, hp2, hp, HTTPH_A_INS);
http_CopyHome(sp->wrk, sp->fd, hp2);
if (body) {
if (http_GetHdr(hp, H_Content_Length, &b))
cls = fetch_straight(sp, vc->fd, hp, b);
else if (http_HdrIs(hp, H_Transfer_Encoding, "chunked"))
cls = fetch_chunked(sp, vc->fd, hp);
else
cls = fetch_eof(sp, vc->fd, hp);
/* Determine if we have a body or not */
cls = 0;
mklen = 0;
if (is_head) {
/* nothing */
} else if (http_GetHdr(hp, H_Content_Length, &b)) {
cls = fetch_straight(sp, vc->fd, hp, b);
mklen = 1;
} else if (http_HdrIs(hp, H_Transfer_Encoding, "chunked")) {
cls = fetch_chunked(sp, vc->fd, hp);
mklen = 1;
} else if (http_GetHdr(hp, H_Transfer_Encoding, &b)) {
/* XXX: AUGH! */
VSL(SLT_Debug, vc->fd, "Invalid Transfer-Encoding");
VBE_ClosedFd(sp->wrk, vc);
return (-1);
} else if (strcmp(http_GetProto(hp), "HTTP/1.1")) {
switch (http_GetStatus(hp)) {
case 200:
cls = fetch_eof(sp, vc->fd, hp);
mklen = 1;
break;
default:
break;
}
}
if (mklen > 0)
http_PrintfHeader(sp->wrk, sp->fd, hp2,
"Content-Length: %u", sp->obj->len);
} else
cls = 0;
if (cls < 0) {
while (!TAILQ_EMPTY(&sp->obj->store)) {
......
......@@ -381,6 +381,20 @@ http_GetStatus(struct http *hp)
NULL /* XXX */, 10));
}
const char *
http_GetProto(struct http *hp)
{
AN(hp->hd[HTTP_HDR_PROTO].b);
return (hp->hd[HTTP_HDR_PROTO].b);
}
const char *
http_GetReq(struct http *hp)
{
AN(hp->hd[HTTP_HDR_REQ].b);
return (hp->hd[HTTP_HDR_REQ].b);
}
/*--------------------------------------------------------------------
* Dissect the headers of the HTTP protocol message.
* Detect conditionals (headers which start with '^[Ii][Ff]-')
......@@ -792,7 +806,8 @@ http_FilterHeader(struct sess *sp, unsigned how)
hp = bereq->http;
hp->logtag = HTTP_Tx;
http_copyreq(hp, sp->http, how != HTTPH_R_PIPE);
http_copyreq(hp, sp->http,
(how == HTTPH_R_PIPE) || (how == HTTPH_R_PASS));
http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how);
http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid);
http_PrintfHeader(sp->wrk, sp->fd, hp,
......
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