Skip to content

Instantly share code, notes, and snippets.

@derekclee
Last active July 15, 2022 09:52
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save derekclee/a19ebfd7d22679c82fda to your computer and use it in GitHub Desktop.
Save derekclee/a19ebfd7d22679c82fda to your computer and use it in GitHub Desktop.
Varnish Cache Set CORS headers
sub vcl_deliver {
if (req.url ~ "/fonts/") {
set resp.http.Access-Control-Allow-Origin = "*";
set resp.http.Access-Control-Allow-Methods = "GET, OPTIONS";
set resp.http.Access-Control-Allow-Headers = "Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token";
}
}
@joepreludian
Copy link

Very Useful! Thank You!

@oralunal
Copy link

oralunal commented Jan 9, 2017

Thanks a lot

@jozwikjp
Copy link

I think this worked for me also. Thank you!

@homerquan
Copy link

This seems not work for websocket. (Http works as expected)

The websocket traffic got:
The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.

@cshoe
Copy link

cshoe commented Mar 6, 2018

That error isn't related to the request coming from a WebSocket (WebSockets and SOP/CORS is another topic). The error is being reported by the browser because the CORS spec says all credentialed CORS reqeusts (i.e. those that include cookies) must specify an origin value in Access-Control-Allow-Origin -- wildcards are not allowed.

@sarabenelabbes
Copy link

Very Useful! Thank You!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment