Commit 8e01d1a9 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

More ESI work, now full URL srcs (http://...) work in addition to

absolute src ("/...").  Relative src's coming up next, once I find
out where to store the edited string.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2171 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 654a323c
...@@ -737,6 +737,12 @@ cnt_recv(struct sess *sp) ...@@ -737,6 +737,12 @@ cnt_recv(struct sess *sp)
sp->step = STP_LOOKUP; sp->step = STP_LOOKUP;
return (0); return (0);
case VCL_RET_PIPE: case VCL_RET_PIPE:
if (sp->esis > 0) {
/* XXX: VSL something */
INCOMPL();
sp->step = STP_DONE;
return (1);
}
sp->step = STP_PIPE; sp->step = STP_PIPE;
return (0); return (0);
case VCL_RET_PASS: case VCL_RET_PASS:
......
...@@ -41,12 +41,14 @@ ...@@ -41,12 +41,14 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include "shmlog.h" #include "shmlog.h"
#include "heritage.h"
#include "vrt.h" #include "vrt.h"
#include "vcl.h" #include "vcl.h"
#include "cache.h" #include "cache.h"
...@@ -59,6 +61,7 @@ struct esi_bit { ...@@ -59,6 +61,7 @@ struct esi_bit {
VTAILQ_ENTRY(esi_bit) list; VTAILQ_ENTRY(esi_bit) list;
char chunk_length[20]; char chunk_length[20];
txt verbatim; txt verbatim;
txt host;
txt include; txt include;
int free_this; int free_this;
}; };
...@@ -146,8 +149,6 @@ esi_addbit(struct esi_work *ew) ...@@ -146,8 +149,6 @@ esi_addbit(struct esi_work *ew)
ew->ebl++; ew->ebl++;
ew->neb--; ew->neb--;
printf("FIRST: %p\n", VTAILQ_FIRST(&ew->sp->obj->esibits));
printf("ADD %p->%p\n", ew->sp->obj, ew->eb);
VTAILQ_INSERT_TAIL(&ew->sp->obj->esibits, ew->eb, list); VTAILQ_INSERT_TAIL(&ew->sp->obj->esibits, ew->eb, list);
ew->eb->verbatim = ew->dst; ew->eb->verbatim = ew->dst;
...@@ -244,6 +245,7 @@ esi_attrib(const struct esi_work *ew, txt *in, txt *attrib, txt *val) ...@@ -244,6 +245,7 @@ esi_attrib(const struct esi_work *ew, txt *in, txt *attrib, txt *val)
in->b++; in->b++;
val->e = in->b; val->e = in->b;
} }
*val->e = '\0';
return (1); return (1);
} }
...@@ -255,6 +257,7 @@ static void ...@@ -255,6 +257,7 @@ static void
esi_addinclude(struct esi_work *ew, txt t) esi_addinclude(struct esi_work *ew, txt t)
{ {
struct esi_bit *eb; struct esi_bit *eb;
char *p, *q;
txt tag; txt tag;
txt val; txt val;
...@@ -266,7 +269,32 @@ esi_addinclude(struct esi_work *ew, txt t) ...@@ -266,7 +269,32 @@ esi_addinclude(struct esi_work *ew, txt t)
val.e - val.b, val.b); val.e - val.b, val.b);
if (Tlen(tag) != 3 && memcmp(tag.b, "src", 3)) if (Tlen(tag) != 3 && memcmp(tag.b, "src", 3))
continue; continue;
assert(Tlen(val) > 0); /* XXX */
if (Tlen(val) > 7 && !memcmp(val.b, "http://", 7)) {
/* Rewrite to Host: header inplace */
eb->host.b = val.b;
memcpy(eb->host.b, "Host: ", 6);
q = eb->host.b + 6;
for (p = eb->host.b + 7; p < val.e && *p != '/'; p++)
*q++ = *p;
*q++ = '\0';
eb->host.e = q;
assert(*p == '/'); /* XXX */
/* The rest is the URL */
eb->include.b = p;
eb->include.e = val.e;
} else if (Tlen(val) > 0 && *val.b == '/') {
/* Absolute on this host */
eb->include = val; eb->include = val;
} else {
/* Relative to current URL */
/* XXX: search forward to '?' use previous / */
/* XXX: where to store edited result ? */
eb->include = val;
INCOMPL();
}
} }
} }
...@@ -506,6 +534,8 @@ VRT_ESI(struct sess *sp) ...@@ -506,6 +534,8 @@ VRT_ESI(struct sess *sp)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
/* XXX: only if GET ? */
ew = eww; ew = eww;
memset(eww, 0, sizeof eww); memset(eww, 0, sizeof eww);
ew->sp = sp; ew->sp = sp;
...@@ -515,14 +545,11 @@ VRT_ESI(struct sess *sp) ...@@ -515,14 +545,11 @@ VRT_ESI(struct sess *sp)
ew->st = st; ew->st = st;
i = esi_parse(ew); i = esi_parse(ew);
ew->off += st->len; ew->off += st->len;
printf("VXML(%p+%d) = %d", st->ptr, st->len, i);
if (i < st->len) { if (i < st->len) {
/* XXX: Handle complications */ /* XXX: Handle complications */
printf(" \"%.*s\"", st->len - i, st->ptr + i);
if (VTAILQ_NEXT(st, list)) if (VTAILQ_NEXT(st, list))
INCOMPL(); INCOMPL();
} }
printf("\n");
i = Tlen(ew->dst); i = Tlen(ew->dst);
} }
if (Tlen(ew->dst)) if (Tlen(ew->dst))
...@@ -551,33 +578,34 @@ ESI_Deliver(struct sess *sp) ...@@ -551,33 +578,34 @@ ESI_Deliver(struct sess *sp)
WRK_Write(sp->wrk, eb->chunk_length, -1); WRK_Write(sp->wrk, eb->chunk_length, -1);
WRK_Write(sp->wrk, eb->verbatim.b, Tlen(eb->verbatim)); WRK_Write(sp->wrk, eb->verbatim.b, Tlen(eb->verbatim));
WRK_Write(sp->wrk, "\r\n", -1); WRK_Write(sp->wrk, "\r\n", -1);
if (eb->include.b != NULL) { if (eb->include.b == NULL ||
sp->esis >= params->max_esi_includes)
continue;
/* /*
* We flush here, because the next transaction is * We flush here, because the next transaction is
* quite likely to take some time, so we should get * quite likely to take some time, so we should get
* as many bits to the client as we can already * as many bits to the client as we can already
*/ */
WRK_Flush(sp->wrk); WRK_Flush(sp->wrk);
/*
* XXX: Must edit url relative to the one we have
* XXX: at this point, and not the http0 url.
*/
printf("INCL: %.*s\n",
Tlen(eb->include), eb->include.b);
*eb->include.e = '\0'; /* XXX ! */
sp->esis++; sp->esis++;
obj = sp->obj; obj = sp->obj;
sp->obj = NULL; sp->obj = NULL;
*sp->http = *sp->http0; *sp->http = *sp->http0;
/* XXX: reset sp->ws */
http_SetH(sp->http, HTTP_HDR_URL, eb->include.b); http_SetH(sp->http, HTTP_HDR_URL, eb->include.b);
if (eb->host.b != NULL) {
http_Unset(sp->http, H_Host);
http_SetHeader(sp->wrk, sp->fd, sp->http, eb->host.b);
}
sp->step = STP_RECV; sp->step = STP_RECV;
CNT_Session(sp); CNT_Session(sp);
sp->esis--; sp->esis--;
sp->obj = obj; sp->obj = obj;
} }
if (!VTAILQ_NEXT(eb, list))
WRK_Write(sp->wrk, "0\r\n", -1); WRK_Write(sp->wrk, "0\r\n", -1);
}
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
......
...@@ -128,6 +128,9 @@ struct params { ...@@ -128,6 +128,9 @@ struct params {
/* Maximum restarts allowed */ /* Maximum restarts allowed */
unsigned max_restarts; unsigned max_restarts;
/* Maximum esi:include depth allowed */
unsigned max_esi_includes;
}; };
extern volatile struct params *params; extern volatile struct params *params;
......
...@@ -563,6 +563,14 @@ tweak_max_restarts(struct cli *cli, struct parspec *par, const char *arg) ...@@ -563,6 +563,14 @@ tweak_max_restarts(struct cli *cli, struct parspec *par, const char *arg)
tweak_generic_uint(cli, &master.max_restarts, arg, 0, UINT_MAX); tweak_generic_uint(cli, &master.max_restarts, arg, 0, UINT_MAX);
} }
static void
tweak_max_esi_includes(struct cli *cli, struct parspec *par, const char *arg)
{
(void)par;
tweak_generic_uint(cli, &master.max_esi_includes, arg, 0, UINT_MAX);
}
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
/* /*
...@@ -770,12 +778,14 @@ static struct parspec parspec[] = { ...@@ -770,12 +778,14 @@ static struct parspec parspec[] = {
, NULL }, , NULL },
{ "max_restarts", tweak_max_restarts, { "max_restarts", tweak_max_restarts,
"Upper limit on how many times a request can restart." "Upper limit on how many times a request can restart."
#ifdef NOT_YET
" ESI:include counts as a restart in this context."
#endif
"\nBe aware that restarts are likely to cause a hit against " "\nBe aware that restarts are likely to cause a hit against "
"the backend, so don't increase thoughtlessly.\n", "the backend, so don't increase thoughtlessly.\n",
"4", "restarts" }, "4", "restarts" },
{ "max_esi_includes", tweak_max_esi_includes,
"Maximum depth of esi:include processing."
"\nBe aware that restarts are likely to cause a hit against "
"the backend, so don't increase thoughtlessly.\n",
"5", "restarts" },
{ NULL, NULL, NULL } { NULL, NULL, NULL }
}; };
......
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