Skip to content

Instantly share code, notes, and snippets.

@jmara
Last active April 23, 2019 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmara/2dc04073d4f1970ae6e20fe6a9b90eef to your computer and use it in GitHub Desktop.
Save jmara/2dc04073d4f1970ae6e20fe6a9b90eef to your computer and use it in GitHub Desktop.
varnishtest "Long vcl/backend names"
server s1 {
rxreq
txresp -status 301 -hdr "Location: http://bar.example.com/bar"
expect req.http.host == "foo.example.com"
expect req.url == "/foo"
} -start
varnish v1 -vcl+backend {
import std;
sub vcl_backend_response {
if (beresp.status == 301 && beresp.http.location ~ "^http://") {
set bereq.http.host = regsuball(beresp.http.location, "^http://([^/]+)/.*", "\1");
set bereq.url = regsuball(beresp.http.location, "^http://([^/]+)", "");
set beresp.http.location = "https://" + bereq.http.host + bereq.url;
}
}
} -start
client c1 {
txreq -url "/foo" -hdr "host: foo.example.com"
rxresp
expect resp.status == 301
expect resp.http.location ~ "^https://"
} -run
@jmara
Copy link
Author

jmara commented Apr 23, 2019

Redirect all http:// responses from backend to https:// in varnish

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