How to make squid add its own http header to the reply, based on ACL

squid

I have a Squid server at work doing Squid-ly things. I need to have Squid reply with a particular header based on matching an ACL.

The header is a custom one that will look something like

X-External-IP: 123.45.67.8

I already know about tcp_outbound_ip, and I'm using a similar method to sniff the request header to properly route through a given IP address, but if possible I need to add this reply as well. Searching through Google has given me results on how to block request headers from making it through — which is NOT what I am trying to do.

Best Answer

Have you taken a look at the request_header_add directive? It was only just added in release 3.3.

See the directive use here.

From the text;

One or more Squid ACLs may be specified to restrict header
injection to matching requests. As always in squid.conf, all
ACLs in an option ACL list must be satisfied for the insertion
to happen. The request_header_add option supports fast ACLs
only.

I'm not sure if that is what you're interested in, or if you want to append headers to the response and not the request. Squid did not previously have support for header addition with ACL, only modification or removal I believe.