Varnish and MaxCdn not caching, how to solve it

At work we’ve started using MaxCDN service because they’re offering 1TB of data transfer for free (nice offer tbh) for serving images. The problem was that after one week of usage there was no cache hit, all requests was still going straight to our servers.

After some investigation I’ve found that sending a Cache-Control header makes that request not cacheable by their servers, to solve this you’ve to add these lines to your Varnish config:

sub vcl_deliver {
	remove resp.http.Cache-Control;

and after that your requests should be cached, to check, use curl in this way:

curl -I your_url_here

and you should see this header: X-Cache: HIT after a few requests that means that the file is in cache.