Skip to content

Commit 444095c

Browse files
Stickier cookies to improve UX when origin is intermittently struggling to return a healthy response
1 parent 1325d40 commit 444095c

5 files changed

Lines changed: 37 additions & 14 deletions

File tree

dist/originOverride.zip

220 Bytes
Binary file not shown.

dist/viewerRequest.zip

215 Bytes
Binary file not shown.

dist/viewerResponse.zip

155 Bytes
Binary file not shown.

handlerViewerRequest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ module.exports.viewerRequest = async (event) => {
229229
case true: {
230230
// redirect
231231
console.log("redirecting...");
232-
return http_helpers.redirect302Response(redirectLocation);
232+
return http_helpers.redirect302Response(redirectLocation, result.token);
233233
break;
234234
}
235235
case false: {

helpers/http.js

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,42 @@ export const http200Response = function (content) {
135135
};
136136

137137
// Generic 302 Response
138-
export const redirect302Response = function (redirect_location) {
139-
const response = {
140-
status: "302",
141-
statusDescription: "Found",
142-
headers: {
143-
location: [
144-
{
145-
key: "Location",
146-
value: redirect_location,
147-
},
148-
],
149-
},
150-
};
138+
export const redirect302Response = function (redirect_location, token) {
139+
let response;
140+
141+
if (token) {
142+
response = {
143+
status: "302",
144+
statusDescription: "Found",
145+
headers: {
146+
location: [
147+
{
148+
key: "Location",
149+
value: redirect_location,
150+
},
151+
],
152+
"set-cookie": [
153+
{
154+
key: "Set-Cookie",
155+
value: `crowdhandler=${token}; path=/; Secure; HttpOnly`,
156+
},
157+
],
158+
},
159+
};
160+
} else {
161+
response = {
162+
status: "302",
163+
statusDescription: "Found",
164+
headers: {
165+
location: [
166+
{
167+
key: "Location",
168+
value: redirect_location,
169+
},
170+
],
171+
},
172+
};
173+
}
151174
return response;
152175
};
153176

0 commit comments

Comments
 (0)