1

I've been looking into some examples of VCL files for Varnish 3.x and I stumbled upon this piece already some times, and it's been making me scratch my head:

sub vcl_recv {

...

  if (req.request != "GET" &&
      req.request != "HEAD" &&
      req.request != "PUT" &&
      req.request != "POST" &&
      req.request != "TRACE" &&
      req.request != "OPTIONS" &&
      req.request != "DELETE") {
    return (pipe);
  }

...
}

Basically, I don't see what would be the point on piping to the backend unknown requests? Is this just in case some weird web app/protocol so it'd work?

Why is it better to pipe this request than to 'pass' them?

I'd love if somebody could explain the usecase for this piece.

0

1 Answer 1

1

The pass instruction makes Varnish act like a classic layer 7 reverse proxy, forwarding traffic by reading and replaying each request one by one.

The pipe instruction makes Varnish act like a HTTP CONNECT proxy, streaming traffic byte-by-byte to and from the backend server.

If the request method is not known, Varnish might not know how to interpret and handle each request, in which case you might want to not touch it at all, thus the VCL examples you see.

WebSocket is a great example (from the docs):

sub vcl_pipe {
     if (req.http.upgrade) {
         set bereq.http.upgrade = req.http.upgrade;
     }
}
sub vcl_recv {
     if (req.http.Upgrade ~ "(?i)websocket") {
         return (pipe);
     }
}

vcl_pipe is called at the start of the transmission and ensures that the backend server receives the HTTP Upgrade header instruction and switches to WebSocket before continuing.

3
  • Ok, I understand that, but what would be a use case where my apache server would need to handle CONNECT request or other "Non-RFC2616" (as seen on one example)? Websockets? video streaming? Thanks for your answer
    – Julio J.
    Mar 24, 2014 at 22:38
  • Updated answer with Websockets example Mar 24, 2014 at 23:41
  • Alright, so websockets are an example of that. I guess the pipe is on the examples as fallback in case you have something like this and you didn't explicitly allowed it on the VCL. Thanks for the update and the great answer.
    – Julio J.
    Mar 25, 2014 at 0:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .