Removing X-Cache, X-Served-By from HTTP Header


#1

Hi,
I tried to remove X-Cache, X-Served-By HTTP from the HTTP headers by adding the remove statements on the bottom of vcl_deliver but they are still showing up in the HTTP headers.

This is what I added.

sub vcl_deliver {

remove resp.http.X-Served-By;
remove resp.http.X-Cache;
}

It seems that fastly is modifying those HTTP headers internally after the “vcl_deliver” subroutine. Is there any way to prevent fastly from doing this or even remove those headers completely?


#2

Hi Alex,

Could you try using “unset” instead of “remove”. This should remove those headers from your response.

As far as preventing modification; that would require taking a look at what else is going on in your vcl, which we would be happy to do if you wanted to send a ticket to support@fastly.com.

Hope that helps!
Maksim


#3

Also, can you paste your entire vcl_deliver, from the generated VCL, not the custom VCL?

The reason I ask is that it’s possible there’s a return(deliver); in the flow before the remove/unset statements.


#4

Yes, there is a return(deliver); statement before the remove/unset statement. I’m sure this is adding the removed HTTP headers again. What happens when removing the return(deliver); statement?

Here is my current vcl_deliver

# Removes various HTTP header variables.
sub modify_http_headers {
  remove resp.http.X-Cache-Debug;
  remove resp.http.X-Backend-Key;
  remove resp.http.Server;  # gunicorn/0.14.3
  remove resp.http.Via;  # 1.1 vegur, 1.1 varnish
  remove resp.http.X-Served-By;  # cache-lcy1132-LCY
  remove resp.http.X-Cache;  # MISS
  remove resp.http.X-Cache-Hits;  # 0
  remove resp.http.X-Timer;
}

sub vcl_deliver {
  call modify_http_headers;
#FASTLY deliver
  return(deliver);
}

#5

Ah, so the #FASTLY deliver part is where those headers get added. So you’ll want to put the call between it and the return(deliver);. Like so:

sub vcl_deliver {
#FASTLY deliver
  call modify_http_headers;
  return(deliver);
}

Can you also check in the generated VCL (hit the VCL button at the top of the GUI to view) to see if there’s no return lines in there. The #FASTLY deliver get’s expanded to something like # FASTLY deliver START and # FASTLY deliver END.


#6

Perfect, that is working! Thank you