Question about designed solution with dynamic backend setup based on csv-file with backend Basic Authentication

Aleksandar Lazic al-varnishmisc at none.at
Sun Sep 21 20:58:26 CEST 2014


Hi.

Am 18-02-2014 11:10, schrieb Lasse Karstensen:
> On Thu, Feb 06, 2014 at 04:30:08PM +0100, Aleksandar Lazic wrote:

[..]

>> @2.) Write a script which create a $ID.vcl with the necessary
>> "backend $ID { ...}" files.
>>      This script add also a 'sub vcl_recv {...}' per backend with 
>> header
>> 
>>      set req.http.Authorization = "BASIC [base64 encoded
>> admin:adminpass]"
> 
> If this is for the backend connection/requests, you need to set it on 
> bereq in
> vcl_miss.

Sorry but I think I still not have fully understand varnish.

I need to change the request URL on the backend to another url and set 
the Authorization-Header.

#######

backend id37 {
   .host = "<MY-BACK-IP>";
   .port = "9004";
   .connect_timeout = 2s;
}

sub vcl_recv {
...
if (req.url == "37") {
     set req.http.Authorization = "Basic Z2FzdDpnYXN0";
     set req.http.url = "<NEW-URL>";
     set req.backend_hint =  id37;
   }
...
}
sub vcl_miss {

     if (req.url == "37") {
     set bereq.http.authorization = "Basic admin:adminpass";
     set bereq.url = "<NEW-URL>";
#    set req.backend_hint  =  id37;
     set bereq.backend =  id37;
   }
}

#######

Message from VCC-compiler:
'bereq.http.authorization': cannot be set in method 'vcl_miss'.
At: ('input' Line 41 Pos 9)
     set bereq.http.authorization = "Basic ...";
--------########################------------------------

Running VCC-compiler failed, exit 1

VCL compilation failed
#################

on

https://www.varnish-cache.org/docs/4.0/reference/vcl.html?highlight=include#bereq

is described that the bereq.http.authorization is only writeable in 
vcl_pipe

###################
bereq.http.

     Type: HEADER

     Readable from: vcl_pipe, backend

     Writable from: vcl_pipe, backend

     The corresponding HTTP header.

###################


varnishd -V
varnishd (varnish-4.0.1 revision 4354e5e)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2011 Varnish Software AS

Thanks for any help.

Aleks



More information about the varnish-misc mailing list