0

I'm afraid I am fairly new to varnish but I have a problem whch I cannot find a solution to anywhere (yet): Varnish is set up to cache GET requests. We have some requests which have so many parameters that we decided to pass them in the body of the request. This works fine when we bypass Varnish but when we go through Varnish (for caching), the request is passed on without the body, so the service behind Varnish fails.

I know we could use POST, but we want to GET data. I also know that Varnish CAN pass the request body on if we use pass mode but as far as I can see, requests made in pass mode aren't cached. I've already put a hash into the url so that when things work, we will actually get the correct data from cache (as far as the url goes the calls would otherwise all look to be the same).

The problem now is "just" how to rewrite vcl_fetch to pass on the request body to the webserver? Any hints and tips welcome!

Thanks in advance

Jon

Jon Gilbert
  • 816
  • 8
  • 4
  • So you want HTTP GET requests with a request body? I didn't think it was possible until I found a question on this site: http://stackoverflow.com/questions/978061/http-get-with-request-body . It is possible, but not recommended. I can imagine varnish doesn't implement this case.... – ivy Sep 12 '11 at 15:48
  • I know it's not recommended, but it's allowed... and helps get round url length constraints. varnish supports it in pass mode but doesn't cache the results. it seems they don't support it (yet?) in fetch mode... and in fetch mode the response could be cached. :(( – Jon Gilbert Sep 12 '11 at 17:42

2 Answers2

0

I don't think you can, but, even if you can, it's very dangerous : Varnish won't store request body into cache or hash table, so it won't be able to see any difference between 2 requests with same URI and different body.

I haven't heard about a VCL key to read request body but, if it exists, you can pass it to req.hash to differenciate requests.

Anyway, request body should only be used with POST or PUT...and POST/PUT requests should not be cached.

Request body is supposed to send data to the server. A cache is used to get data...

I don't know the details, but I think there's a design issue in your process...

0

I am not sure I got your question right but if you try to interact with the request body in some way this is not possible with VCL. You do not have any VCL variable/subroutine to do this.

You can find the list of variables available in VCL here (or in man vcl) :

I agree with Gauthier, you seem to have a design issue in your system.

'Hope that helps.

Jérôme R
  • 1,147
  • 2
  • 10
  • 22