@queue-it/fastly 2.0.3-beta.2 → 2.0.3-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/contextProvider.ts +4 -8
- package/src/helper.ts +11 -11
- package/src/requestResponseHandler.ts +58 -62
package/package.json
CHANGED
package/src/contextProvider.ts
CHANGED
|
@@ -30,6 +30,10 @@ export class FastlyHttpContextProvider implements IConnectorContextProvider {
|
|
|
30
30
|
getEnqueueTokenProvider(): null {
|
|
31
31
|
return null;
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
getResponseHeaders(): Headers {
|
|
35
|
+
return (this.res as FastlyHttpResponse).getHeaders();
|
|
36
|
+
}
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
export class FastlyHttpRequest implements IHttpRequest {
|
|
@@ -57,14 +61,6 @@ export class FastlyHttpRequest implements IHttpRequest {
|
|
|
57
61
|
return;
|
|
58
62
|
}
|
|
59
63
|
this.bodyFetched = true;
|
|
60
|
-
const rawBody: ArrayBuffer | null = null; // this.context.req.arrayBuffer();
|
|
61
|
-
if (rawBody == null) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (rawBody!.byteLength == 0) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
64
|
this.body = ''; // this.context.req.text()
|
|
69
65
|
}
|
|
70
66
|
|
package/src/helper.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export class QueueITHelper {
|
|
2
|
-
static readonly KUP_VERSION: string = "fastly-2.0.3-beta.
|
|
3
|
-
|
|
4
|
-
static addKUPlatformVersion(redirectQueueUrl: string): string {
|
|
5
|
-
return redirectQueueUrl + "&kupver=" + QueueITHelper.KUP_VERSION;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface RequestLogger {
|
|
10
|
-
log(message: string): void;
|
|
11
|
-
}
|
|
1
|
+
export class QueueITHelper {
|
|
2
|
+
static readonly KUP_VERSION: string = "fastly-2.0.3-beta.4";
|
|
3
|
+
|
|
4
|
+
static addKUPlatformVersion(redirectQueueUrl: string): string {
|
|
5
|
+
return redirectQueueUrl + "&kupver=" + QueueITHelper.KUP_VERSION;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface RequestLogger {
|
|
10
|
+
log(message: string): void;
|
|
11
|
+
}
|
|
@@ -63,70 +63,66 @@ export async function onQueueITRequest(
|
|
|
63
63
|
// The requestUrlWithoutToken is used to match Triggers and as the Target url (where to return the users to).
|
|
64
64
|
// It is therefor important that this is exactly the url of the users browsers. So, if your webserver is
|
|
65
65
|
// behind e.g. a load balancer that modifies the host name or port, reformat requestUrlWithoutToken before proceeding.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
try {
|
|
67
|
+
const validationResult = await KnownUser.validateRequestByIntegrationConfig(
|
|
68
|
+
requestUrlWithoutToken,
|
|
69
|
+
queueItToken,
|
|
70
|
+
integrationConfigJson,
|
|
71
|
+
conf.customerId,
|
|
72
|
+
conf.secretKey,
|
|
73
|
+
httpProvider!
|
|
74
|
+
);
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
QueueITHelper.addKUPlatformVersion(validationResult.redirectUrl)
|
|
105
|
-
);
|
|
106
|
-
addNoCacheHeaders(response);
|
|
107
|
-
return response;
|
|
108
|
-
}
|
|
109
|
-
} else if (validationResultPair.first != null) {
|
|
110
|
-
const validationResult = validationResultPair.first!;
|
|
111
|
-
// Request can continue - we remove queueittoken form querystring parameter to avoid sharing of user specific token
|
|
112
|
-
// Support mobile scenario adding the condition !validationResult.isAjaxResult
|
|
113
|
-
if (
|
|
114
|
-
queueItToken != "" &&
|
|
115
|
-
!validationResult.isAjaxResult &&
|
|
116
|
-
validationResult.actionType == "Queue"
|
|
117
|
-
) {
|
|
118
|
-
let response = new Response(null, {
|
|
119
|
-
status: 302,
|
|
120
|
-
headers: httpProvider!.getHttpResponse().getHeaders(),
|
|
121
|
-
});
|
|
122
|
-
response.headers.set("Location", requestUrlWithoutToken);
|
|
123
|
-
addNoCacheHeaders(response);
|
|
124
|
-
return response;
|
|
76
|
+
if (validationResult.doRedirect()) {
|
|
77
|
+
if (validationResult.isAjaxResult) {
|
|
78
|
+
let response = new Response(null, {
|
|
79
|
+
status: 200,
|
|
80
|
+
headers: httpProvider!.getResponseHeaders(),
|
|
81
|
+
});
|
|
82
|
+
// In case of ajax call send the user to the queue by sending a custom queue-it header and redirecting user to queue from javascript
|
|
83
|
+
response.headers.set("Access-Control-Expose-Headers", validationResult.getAjaxQueueRedirectHeaderKey());
|
|
84
|
+
response.headers.set(
|
|
85
|
+
validationResult.getAjaxQueueRedirectHeaderKey(),
|
|
86
|
+
QueueITHelper.addKUPlatformVersion(
|
|
87
|
+
validationResult.getAjaxRedirectUrl()
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
addNoCacheHeaders(response);
|
|
91
|
+
return response;
|
|
92
|
+
} else {
|
|
93
|
+
let response = new Response(null, {
|
|
94
|
+
status: 302,
|
|
95
|
+
headers: httpProvider!.getResponseHeaders(),
|
|
96
|
+
});
|
|
97
|
+
// Send the user to the queue - either because hash was missing or because is was invalid
|
|
98
|
+
response.headers.set(
|
|
99
|
+
"Location",
|
|
100
|
+
QueueITHelper.addKUPlatformVersion(validationResult.redirectUrl)
|
|
101
|
+
);
|
|
102
|
+
addNoCacheHeaders(response);
|
|
103
|
+
return response;
|
|
104
|
+
}
|
|
125
105
|
} else {
|
|
126
|
-
//
|
|
127
|
-
|
|
106
|
+
// Request can continue - we remove queueittoken from querystring parameter to avoid sharing of user specific token
|
|
107
|
+
// Support mobile scenario adding the condition !validationResult.isAjaxResult
|
|
108
|
+
if (
|
|
109
|
+
queueItToken != "" &&
|
|
110
|
+
!validationResult.isAjaxResult &&
|
|
111
|
+
validationResult.actionType == "Queue"
|
|
112
|
+
) {
|
|
113
|
+
let response = new Response(null, {
|
|
114
|
+
status: 302,
|
|
115
|
+
headers: httpProvider!.getResponseHeaders(),
|
|
116
|
+
});
|
|
117
|
+
response.headers.set("Location", requestUrlWithoutToken);
|
|
118
|
+
addNoCacheHeaders(response);
|
|
119
|
+
return response;
|
|
120
|
+
} else {
|
|
121
|
+
// lets caller decide the next step, or just serve the request normally
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
128
124
|
}
|
|
129
|
-
}
|
|
125
|
+
} catch {
|
|
130
126
|
httpProvider!.isError = true;
|
|
131
127
|
}
|
|
132
128
|
|
|
@@ -135,7 +131,7 @@ export async function onQueueITRequest(
|
|
|
135
131
|
|
|
136
132
|
//Fill in the Queue-it headers
|
|
137
133
|
export function onQueueITResponse(res: Response): void {
|
|
138
|
-
const contextHeaders = httpProvider!.
|
|
134
|
+
const contextHeaders = httpProvider!.getResponseHeaders();
|
|
139
135
|
|
|
140
136
|
if (httpProvider!.isError) {
|
|
141
137
|
res.headers.append(QUEUEIT_FAILED_HEADERNAME, "true");
|