Commit 4c351bca authored by Artur Bergman's avatar Artur Bergman

Allows you to turn off esi processing for a specific request using set req.esi...

Allows you to turn off esi processing for a specific request using set req.esi = off even if the object has been esi processed -- this is useful if you have a cache heirarchy of varnish machines as well as debugging. Only change to processing is to store a copy of the attribute value instead of mangling to original. Committed from Oahu.

git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4066 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 490aca62
......@@ -345,6 +345,7 @@ struct sess {
int restarts;
int esis;
int disable_esi;
struct worker *wrk;
......
......@@ -978,6 +978,8 @@ cnt_recv(struct sess *sp)
sp->director = sp->vcl->director[0];
AN(sp->director);
sp->disable_esi = 0;
VCL_recv_method(sp);
if (sp->restarts >= params->max_restarts) {
if (sp->err_code == 0)
......
......@@ -304,8 +304,7 @@ esi_attrib(const struct esi_work *ew, txt *in, txt *attrib, txt *val)
in->b++;
if (isspace(*in->b)) {
val->e = val->b = in->b;;
*val->e = '\0';
val->e = val->b = in->b;
in->b++;
return (1);
}
......@@ -340,7 +339,6 @@ esi_attrib(const struct esi_work *ew, txt *in, txt *attrib, txt *val)
val->e = in->b;
in->b++;
}
*val->e = '\0';
return (1);
}
......@@ -352,11 +350,11 @@ static void
esi_handle_include(struct esi_work *ew)
{
struct esi_bit *eb;
char *p, *q;
char *p, *q, *c;
txt t = ew->tag;
txt tag;
txt val;
unsigned u, v;
unsigned u, v, s;
struct ws *ws;
if (ew->eb == NULL || ew->eb->include.b != NULL)
......@@ -375,6 +373,20 @@ esi_handle_include(struct esi_work *ew)
continue;
}
/* Wee are saving the original string */
ws = ew->sp->obj->ws_o;
WS_Assert(ws);
s = 0;
if ( val.b != val.e ) {
s = Tlen(val) + 1;
c = WS_Alloc(ws, s);
memcpy(c, val.b, Tlen(val));
val.b = c;
val.e = val.b + s;
*val.e = '\0';
}
if (Tlen(val) > 7 && !memcmp(val.b, "http://", 7)) {
/* Rewrite to Host: header inplace */
eb->host.b = val.b;
......@@ -405,8 +417,6 @@ esi_handle_include(struct esi_work *ew)
/* Use the objects WS to store the result */
CHECK_OBJ_NOTNULL(ew->sp->obj, OBJECT_MAGIC);
ws = ew->sp->obj->ws_o;
WS_Assert(ws);
/* Look for the last '/' before a '?' */
q = NULL;
......
......@@ -106,7 +106,7 @@ RES_BuildHttp(struct sess *sp)
HTTPH_A_DELIVER);
/* Only HTTP 1.1 can do Chunked encoding */
if (!VTAILQ_EMPTY(&sp->obj->esibits)) {
if (!sp->disable_esi && !VTAILQ_EMPTY(&sp->obj->esibits)) {
http_Unset(sp->wrk->resp, H_Content_Length);
if(sp->http->protover >= 1.1)
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Transfer-Encoding: chunked");
......@@ -142,10 +142,10 @@ RES_WriteObj(struct sess *sp)
WRW_Reserve(sp->wrk, &sp->fd);
if (sp->esis == 0)
if (!sp->disable_esi == 0 || sp->esis == 0)
sp->acct_req.hdrbytes += http_Write(sp->wrk, sp->wrk->resp, 1);
if (sp->wantbody && !VTAILQ_EMPTY(&sp->obj->esibits)) {
if (!sp->disable_esi && sp->wantbody && !VTAILQ_EMPTY(&sp->obj->esibits)) {
if (WRW_FlushRelease(sp->wrk)) {
vca_close_session(sp, "remote closed");
return;
......@@ -155,7 +155,8 @@ RES_WriteObj(struct sess *sp)
}
if (sp->wantbody) {
if (sp->esis > 0 &&
if (!sp->disable_esi &&
sp->esis > 0 &&
sp->http->protover >= 1.1 &&
sp->obj->len > 0) {
sprintf(lenbuf, "%x\r\n", sp->obj->len);
......@@ -186,7 +187,8 @@ RES_WriteObj(struct sess *sp)
(void)WRW_Write(sp->wrk, st->ptr, st->len);
}
assert(u == sp->obj->len);
if (sp->esis > 0 &&
if (!sp->disable_esi &&
sp->esis > 0 &&
sp->http->protover >= 1.1 &&
sp->obj->len > 0)
(void)WRW_Write(sp->wrk, "\r\n", -1);
......
......@@ -161,7 +161,8 @@ SES_New(const struct sockaddr *addr, unsigned len)
sp->t_resp = NAN;
sp->t_end = NAN;
sp->grace = NAN;
sp->disable_esi = 0;
assert(len <= sp->sockaddrlen);
if (addr != NULL) {
memcpy(sp->sockaddr, addr, len);
......
......@@ -554,6 +554,22 @@ VRT_r_req_backend(struct sess *sp)
/*--------------------------------------------------------------------*/
void
VRT_l_req_esi(struct sess *sp, unsigned process_esi)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
sp->disable_esi = !process_esi;
}
unsigned
VRT_r_req_esi(struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
return (!sp->disable_esi);
}
/*--------------------------------------------------------------------*/
int
VRT_r_req_restarts(const struct sess *sp)
{
......
# $Id: e00003.vtc 3573 2009-02-03 18:44:21Z phk $
test "ESI requests turned off"
server s1 {
rxreq
txresp -body {
<html>
Before include
<esi:include src="/body"/>
After include
}
rxreq
txresp -body {
<html>
Before include
<esi:include src="/body"/>
After include
}
rxreq
expect req.url == "/body"
txresp -body {
Included file
}
} -start
varnish v1 -vcl+backend {
sub vcl_fetch {
if(req.url == "/") {
set req.esi = false;
}
esi;
}
} -start
client c1 {
txreq
rxresp
expect resp.bodylen == 73
expect resp.status == 200
txreq -url "/esi"
rxresp
expect resp.bodylen == 65
expect resp.status == 200
}
client c1 -run
varnish v1 -expect esi_errors == 0
......@@ -24,6 +24,8 @@ int VRT_r_req_restarts(const struct sess *);
double VRT_r_req_grace(struct sess *);
void VRT_l_req_grace(struct sess *, double);
const char * VRT_r_req_xid(struct sess *);
unsigned VRT_r_req_esi(struct sess *);
void VRT_l_req_esi(struct sess *, unsigned);
const char * VRT_r_bereq_request(const struct sess *);
void VRT_l_bereq_request(const struct sess *, const char *, ...);
const char * VRT_r_bereq_url(const struct sess *);
......
......@@ -233,8 +233,8 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI");
vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT");
vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n");
vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3834 2009-02-27 12:");
vsb_cat(sb, "02:50Z phk $\n *\n * Runtime support for compiled VCL ");
vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 4025 2009-04-03 21:");
vsb_cat(sb, "52:44Z des $\n *\n * Runtime support for compiled VCL ");
vsb_cat(sb, "programs.\n *\n * XXX: When this file is changed, lib/");
vsb_cat(sb, "libvcl/vcc_gen_fixed_token.tcl\n");
vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n");
......@@ -343,6 +343,8 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, "uct sess *);\ndouble VRT_r_req_grace(struct sess *);\n");
vsb_cat(sb, "void VRT_l_req_grace(struct sess *, double);\n");
vsb_cat(sb, "const char * VRT_r_req_xid(struct sess *);\n");
vsb_cat(sb, "unsigned VRT_r_req_esi(struct sess *);\n");
vsb_cat(sb, "void VRT_l_req_esi(struct sess *, unsigned);\n");
vsb_cat(sb, "const char * VRT_r_bereq_request(const struct sess *);");
vsb_cat(sb, "\nvoid VRT_l_bereq_request(const struct sess *, const ");
vsb_cat(sb, "char *, ...);\nconst char * VRT_r_bereq_url(const stru");
......
......@@ -116,6 +116,12 @@ set spobj {
"struct sess *"
}
{ req.esi
RW BOOL
{recv fetch deliver error}
"struct sess *"
}
#######################################################################
# Request sent to backend
{ bereq.request
......
......@@ -107,6 +107,11 @@ struct var vcc_vars[] = {
| VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
| VCL_MET_ERROR
},
{ "req.esi", BOOL, 7,
"VRT_r_req_esi(sp)", "VRT_l_req_esi(sp, ",
V_RW, 0,
VCL_MET_RECV | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_ERROR
},
{ "bereq.request", STRING, 13,
"VRT_r_bereq_request(sp)", "VRT_l_bereq_request(sp, ",
V_RW, 0,
......
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