How to cache responses to POST requests

enridaga enridaga at apache.org
Thu Jun 19 18:33:15 CEST 2014


Hi all,
I have found something about it on SO [1] but unfortunately I can't
translate the requests to GET.
My use case is about caching time consuming calls to a remote REST
service going through a corporate proxy.
With the following vcl script I was able to use the corporate proxy
and make POST requests work fine.
However, the responses are not cached.

Does anybody know the magic words?

Thank you!

Enrico

# This is my script
backend default {
  .host = "my-remote-service.org ";
  .port = "80";
}

backend ouproxy {
  .host = "my-corporate-proxy.org ";
  .port = "80";
}

sub vcl_recv {
  set req.url = "http://my-remote-service.org " + req.url;
  set req.backend = ouproxy;

  if(req.request=="POST"){
     return (lookup);
  }else{
     return (lookup);
  }
}

sub vcl_pass {
  if(req.request=="POST"){
    set bereq.request = "POST";
  }
}


[1] http://stackoverflow.com/questions/9023590/varnish-caching-of-post-requests


Enrico Daga


------------------------------------------------------------------------------
enridaga



More information about the varnish-misc mailing list