Skip to content

Commit 6470806

Browse files
author
Prabhu Ram
committed
MC-31987: Varnish graphql cache has to skip authenticated requests
- Modified vcl to not cache authorized requests for graphql
1 parent 6bcc25b commit 6470806

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

app/code/Magento/PageCache/etc/varnish4.vcl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ sub vcl_recv {
108108
#unset req.http.Cookie;
109109
}
110110

111+
if (req.method == "GET" && req.url ~ "/graphql" && req.url ~ "query=" && req.http.Authorization ~ "^Bearer") {
112+
# Authentificated customers should not be cached by default
113+
return (pass);
114+
}
115+
111116
return (hash);
112117
}
113118

@@ -123,7 +128,7 @@ sub vcl_hash {
123128
hash_data(server.ip);
124129
}
125130

126-
if (req.url ~ "/graphql") {
131+
if (req.method == "GET" && req.url ~ "/graphql" && req.url ~ "query=") {
127132
call process_graphql_headers;
128133
}
129134

app/code/Magento/PageCache/etc/varnish5.vcl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ sub vcl_recv {
109109
#unset req.http.Cookie;
110110
}
111111

112+
if (req.method == "GET" && req.url ~ "/graphql" && req.url ~ "query=" && req.http.Authorization ~ "^Bearer") {
113+
# Authentificated customers should not be cached by default
114+
return (pass);
115+
}
116+
112117
return (hash);
113118
}
114119

@@ -130,7 +135,7 @@ sub vcl_hash {
130135
}
131136
/* {{ design_exceptions_code }} */
132137

133-
if (req.url ~ "/graphql") {
138+
if (req.method == "GET" && req.url ~ "/graphql" && req.url ~ "query=" ) {
134139
call process_graphql_headers;
135140
}
136141
}

app/code/Magento/PageCache/etc/varnish6.vcl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ sub vcl_recv {
109109
#unset req.http.Cookie;
110110
}
111111

112+
if (req.method == "GET" && req.url ~ "/graphql" && req.url ~ "query=" && req.http.Authorization ~ "^Bearer") {
113+
# Authentificated customers should not be cached by default
114+
return (pass);
115+
}
116+
112117
return (hash);
113118
}
114119

@@ -130,7 +135,7 @@ sub vcl_hash {
130135
}
131136
/* {{ design_exceptions_code }} */
132137

133-
if (req.url ~ "/graphql") {
138+
if (req.method == "GET" && req.url ~ "/graphql" && req.url ~ "query=") {
134139
call process_graphql_headers;
135140
}
136141
}

0 commit comments

Comments
 (0)