[squid-users] How to use request headers in external_acl_type

squid3 at treenet.co.nz squid3 at treenet.co.nz
Fri Jun 25 23:20:06 UTC 2021


On 2021-06-26 07:18, Yosi Greenfield wrote:
> Hello all,
> 
> I'm trying to use request headers in an external acl, and I'm probably
> doing it incorrectly, and it's not working.
> 

Looks like its working fine.


> Here's my acl definiton:
> 
> external_acl_type ext_acl_program  %SRC %>{Connection} %>{Accept}
> %>{Custom_header} %>{Host} /etc/squid/ext_acl_program.pl
> 
> The program ext_acl_program.pl simply prints out the input
> 
>    chomp ($line);
>    @fields          = split(' ', $line);
>    my $ip           = $fields[0];
>    my $connection   = $fields[1];
>    my $accept       = $fields[2];
>    my $custom       = $fields[3];
>    my $host         = $fields[4];
> 
>    print LOGFILE  "IP: $ip\n Conn: $connection\n Accept: $accept\n
> Custom: $custom\n Host: $host";
> 
> The output looks like this:
> 
> IP: 10.200.10.2
> Conn: keep-alive
> Accept: -
> Custom: -
> Host: www.wsws.com:443 [1]
> 
> As you see, it has values for %SRC, %>{Connection} and %>{Host}.  It
> does not have values for %>{Accept} and %>{Custom_header}
> 
> So the question is, are these %>{} substitutions coming from
> request_headers (as I thought)?

The Host header only exists in request messages so I would say they are.
It may not be the request message you are thinking about though. Request 
headers can come from clients, but they could also be generated by Squid 
or ICAP/eCAP services.

> 
> If yes, why does it only have Connection and Host, and not Accept or
> my custom header?
> 

Because those are the headers the message being printed contain.
You do not provide enough details about where the request came from. eg 
how it was created and/or changed between creation and the helper being 
called.


> If they are not coming from request headers, where are they coming
> from?
> 

You can use "debug_options 11,2" to see the HTTP messages Squid is 
processing.


> And mostly, how can I pass my custom header into the program?

Exactly as you configured above. Assuming that the header is actually 
"Custom_header: ..." with that underscore included.


Amos


More information about the squid-users mailing list