access to root response headers from within esi subrequest

John Skopis jspam at skopis.com
Thu Feb 16 04:38:22 CET 2012


Hello,

I am experimenting with ESI.

I am wondering how I can handle propagating status codes to the
parent(root) request?

The problem is that an esi subrequest might return a 4xx, 5xx status
however the status does not propagate to the root request.

I think what I would like is the ability to merge headers (overwrite)
between esi subrequest and a parent request.

Thanks,
John

Take this for example:

t.php:
<?php

header("Cache-Control: no-cache, must-revalidate\n");
header("x-do-esi: true\n");

print("<html><head></head><
body><p> t1");
print("<div style='outline:#00FF00 dotted thick; width:1024px;
height:80px'> <esi:include src='/t1.php' /></div>");

?>


t1.php:
<?php

header("Cache-Control: no-cache, must-revalidate\n");
header("x-esi-response: true\n");
header("HTTP/1.0 404 Not Found");

print("t1 sent a 404\n");

?>


vcl:
backend default {
    .host = "localhost";
    .port = "80";
}

backend test {
    .host = "localhost";
    .port = "80";
}

sub vcl_recv {
    remove req.http.Accept-Encoding;
    set req.http.x-saved-status = 1;

    if (req.request == "GET") {
        if (req.url == "/t1.php") {
            set req.backend = test;
        }
        return(pass);
    }

}


sub vcl_fetch {
    if (beresp.http.x-do-esi) {
        set beresp.do_esi = true;
        set req.http.x-saved-status = beresp.status;
    }

    if (beresp.http.x-esi-response) {
        if(beresp.status != 200 ) {
            set req.http.x-saved-status = beresp.status;
        }
    }

    if (  beresp.http.Pragma        ~ "no-cache"
       || beresp.http.Cache-Control ~ "no-cache"
       || beresp.http.Cache-Control ~ "private") {
       return(hit_for_pass);
    }

}

sub vcl_deliver {
    set resp.http.status = req.http.x-saved-status;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20120215/44416a0f/attachment.html>


More information about the varnish-misc mailing list