Commit ea6090b2 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Munge the esi:include src attribute as required, to produce URL and

Host: header.

Correctly unpack Host: header in esi delivery.

Now e00008.vtc is the first case to fail.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5730 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 4f8110fa
......@@ -72,7 +72,7 @@ ESI_Include(struct sess *sp, const char *src, const char *host)
ws_wm = WS_Snapshot(sp->ws);
http_SetH(sp->http, HTTP_HDR_URL, src);
if (host != NULL) {
if (host != NULL && *host != '\0') {
http_Unset(sp->http, H_Host);
http_Unset(sp->http, H_If_Modified_Since);
http_SetHeader(w, sp->fd, sp->http, host);
......@@ -125,7 +125,7 @@ void
ESI_Deliver(struct sess *sp)
{
struct storage *st;
uint8_t *p, *e, *q;
uint8_t *p, *e, *q, *r;
unsigned off;
size_t l;
......@@ -140,6 +140,8 @@ printf("DELIV\n");
off = 0;
while (p < e) {
//usleep(10000);
//WRW_Flush(sp->wrk);
switch (*p) {
case VEC_V1:
l = p[1];
......@@ -179,9 +181,14 @@ printf("DELIV\n");
case VEC_INCL:
p++;
q = (void*)strchr((const char*)p, '\0');
printf("INCL [%s]\n", p);
ESI_Include(sp, (const char*)p, NULL);
p = q + 1;
AN(q);
q++;
r = (void*)strchr((const char*)q, '\0');
AN(r);
printf("INCL [%s][%s] BEGIN\n", p, q);
ESI_Include(sp, (const char*)p, (const char*)q);
printf("INCL [%s] END\n", p);
p = r + 1;
break;
default:
printf("XXXX %02x [%c]\n", *p, *p);
......@@ -189,6 +196,7 @@ printf("DELIV\n");
return;
}
}
printf("DONE\n");
WRW_Flush(sp->wrk);
}
......
......@@ -59,6 +59,8 @@ struct vep_state {
vfp_bytes_f *bytes;
struct vsb *vsb;
struct sess *sp;
/* parser state */
const char *state;
......@@ -324,6 +326,9 @@ vep_do_nothing(struct vep_state *vep, enum dowhat what)
static void
vep_do_include(struct vep_state *vep, enum dowhat what)
{
char *p, *q, *h;
ssize_t l;
txt url;
printf("DO_INCLUDE(%d)\n", what);
if (what == DO_ATTR) {
......@@ -338,9 +343,38 @@ vep_do_include(struct vep_state *vep, enum dowhat what)
if (vep->o_verbatim > 0)
vep_emit_verbatim(vep);
/* XXX: what if it contains NUL bytes ?? */
vsb_printf(vep->vsb, "%c%s%c",
VEC_INCL,
vsb_data(vep->include_src), 0);
p = vsb_data(vep->include_src);
l = vsb_len(vep->include_src);
h = 0;
if (l > 7 && !memcmp(p, "http://", 7)) {
h = p + 7;
p = strchr(h, '/');
AN(p);
printf("HOST <%.*s> PATH <%s>\n", (int)(p-h),h, p);
vsb_printf(vep->vsb, "%c%s%cHost: %.*s%c",
VEC_INCL, p, 0,
(int)(p-h), h, 0);
} else if (*p == '/') {
vsb_printf(vep->vsb, "%c%s%c%c",
VEC_INCL, p, 0, 0);
} else {
url = vep->sp->wrk->bereq->hd[HTTP_HDR_URL];
/* Look for the last / before a '?' */
h = NULL;
for (q = url.b; q < url.e && *q != '?'; q++)
if (*q == '/')
h = q;
if (h == NULL)
h = q + 1;
printf("INCL:: %.*s/%s\n",
(int)(h - url.b), url.b, p);
vsb_printf(vep->vsb, "%c%.*s/%s%c%c",
VEC_INCL,
(int)(h - url.b), url.b,
p, 0, 0);
}
vsb_delete(vep->include_src);
vep->include_src = NULL;
......@@ -373,12 +407,15 @@ vep_parse(struct vep_state *vep, const char *b, size_t l)
p = b;
while (p < e) {
AN(vep->state);
i = e - p;
if (i > 10)
i = 10;
printf("EP %s %d %d (%.*s) [%.*s]\n",
vep->state,
vep->skip,
vep->remove,
vep->tag_i, vep->tag,
(int)(e - p), p);
i, p);
fflush(stdout);
usleep(10);
......@@ -415,13 +452,13 @@ vep_parse(struct vep_state *vep, const char *b, size_t l)
} else if (vep->state == VEP_NOTMYTAG) {
vep->tag_i = 0;
while (p < e) {
if (!vep->remove)
vep_mark_verbatim(vep, p + 1);
if (*p++ == '>') {
vep->state = VEP_NEXTTAG;
break;
}
}
if (!vep->remove)
vep_mark_verbatim(vep, p + 1);
} else if (vep->state == VEP_NEXTTAG) {
/*
* Hunt for start of next tag and keep an eye
......@@ -447,11 +484,10 @@ vep_parse(struct vep_state *vep, const char *b, size_t l)
} else {
p++;
vep->esicmt_p = vep->esicmt;
if (vep->esicmt_p == NULL &&
!vep->remove)
vep_mark_verbatim(vep, p);
}
}
if (vep->esicmt_p == NULL && !vep->remove)
vep_mark_verbatim(vep, p);
if (p < e)
vep->state = VEP_STARTTAG;
......@@ -507,13 +543,13 @@ vep_parse(struct vep_state *vep, const char *b, size_t l)
if (vep->remove) {
VSC_main->esi_errors++;
vep->state = VEP_NOTMYTAG;
break;
} else {
vep->skip = 1;
vep_mark_skip(vep, p);
vep->match = vep_match_esi;
vep->match_l = vep_match_esi_len;
vep->state = VEP_MATCH;
}
vep->skip = 1;
vep_mark_skip(vep, p);
vep->match = vep_match_esi;
vep->match_l = vep_match_esi_len;
vep->state = VEP_MATCH;
} else if (vep->state == VEP_ESIETAG) {
vep->tag_i = 0;
vep->endtag = 1;
......@@ -528,6 +564,7 @@ vep_parse(struct vep_state *vep, const char *b, size_t l)
} else if (vep->state == VEP_ESIREMOVE) {
vep->dostuff = vep_do_nothing;
vep->remove = !vep->endtag;
printf(">>> REMOVE %d\n", vep->remove);
vep->state = VEP_INTAG;
/******************************************************
......@@ -754,6 +791,7 @@ vfp_esi_begin(struct sess *sp, size_t estimate)
memset(vep, 0, sizeof *vep);
vep->magic = VEP_MAGIC;
vep->sp = sp;
vep->bytes = vfp_esi_bytes_uu;
vep->vsb = vsb_newauto();
vep->state = VEP_START;
......
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