Skip to content

Commit

Permalink
Move GOV.UK Chat URL regex to a variable
Browse files Browse the repository at this point in the history
This regex is repeated multiple times so it makes sense to move it to a
variable.
  • Loading branch information
jackbot committed Nov 21, 2024
1 parent 35f196b commit 4204163
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions www/service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ locals {
ssl_ciphers = "ECDHE-RSA-AES256-GCM-SHA384"
basic_authentication = null
disable_chat = false
chat_path_regex = "^/chat(/.*)?$" # matches /chat and /chat/*

s3_static_assets_port = 443
s3_static_assets_hostname = null
Expand Down
10 changes: 5 additions & 5 deletions www/www.vcl.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ sub vcl_recv {

${indent(2, ab_tests_rendered)}

# Strip cookies for requests to /chat or /chat/* that lack a session cookie,
# Strip cookies for requests to GOV.UK Chat URLs that lack a session cookie,
# otherwise pass through
if (req.url.path ~ "^/chat(/.*)?$") {
if (req.url.path ~ chat_path_regex) {
if (req.http.cookie:_govuk_chat_session) {
return(pass);
# These endpoints make use of HEAD requests and we don't want these
Expand All @@ -389,7 +389,7 @@ sub vcl_recv {

%{ if disable_chat == true ~}
# Chat app is disabled
if (req.url.path ~ "^/chat(/.*)?$") {
if (req.url.path ~ chat_path_regex) {
error 503 "Service unavailable";
}
%{ endif ~}
Expand Down Expand Up @@ -510,8 +510,8 @@ sub vcl_fetch {
}
}

# We don't want to cache any /chat or /chat/* responses that set a cookie
if (req.url.path ~ "^/chat(/.*)?$" && beresp.http.Set-Cookie) {
# We don't want to cache any GOV.UK Chat responses that set a cookie
if (req.url.path ~ chat_path_regex && beresp.http.Set-Cookie) {
return (pass);
}

Expand Down

0 comments on commit 4204163

Please sign in to comment.