[Varnish] #102: RES_WriteObj() does not send body for POST

Varnish varnish-bugs at projects.linpro.no
Fri May 4 14:18:51 CEST 2007


#102: RES_WriteObj() does not send body for POST
----------------------+-----------------------------------------------------
 Reporter:  des       |       Owner:  phk  
     Type:  defect    |      Status:  new  
 Priority:  normal    |   Milestone:       
Component:  varnishd  |     Version:  trunk
 Severity:  normal    |    Keywords:       
----------------------+-----------------------------------------------------
 When handling certain AJAX applications, it is sometimes desirable to
 cache objects requested with {{{POST}}}, because some AJAX code uses
 {{{POST}}} instead of {{{GET}}} to work around caching issues in MSIE (see
 [http://en.wikipedia.org/wiki/XMLHttpRequest#Microsoft_Internet_Explorer_cache_issues])

 This can be achieved with the following piece of VCL:

 {{{
 sub vcl_recv {
         if (req.request == "POST" &&
             (!req.http.content-length || req.http.content-length == "0"))
 {
                 lookup;
         }
 }
 }}}

 Unfortunately, this does not work, because {{{RES_WriteObj()}}} only
 writes out the contents of the object if {{{sp->wantbody}}} is non-zero,
 and {{{sp->wantbody}}} is set to 1 in only one place, in {{{cnt_recv()}}}:

 {{{
         sp->wantbody = !strcmp(sp->http->hd[HTTP_HDR_REQ].b, "GET");
 }}}

 A quick fix is to set {{{sp->wantbody}}} to 1 also for {{{POST}}}:

 {{{
         sp->wantbody = (!strcmp(sp->http->hd[HTTP_HDR_REQ].b, "GET") ||
             !strcmp(sp->http->hd[HTTP_HDR_REQ].b, "POST"));
 }}}

 A better long-term fix is to allow {{{sp->wantbody}}} to be manipulated
 from VCL code, and move this logic to the default configuration (where it
 can be overriden by the user).

-- 
Ticket URL: <http://varnish.projects.linpro.no/ticket/102>
Varnish <http://varnish.projects.linpro.no/>
The Varnish HTTP Accelerator


More information about the varnish-bugs mailing list