@queue-it/fastly 1.0.1 → 1.0.3
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/README.md +129 -129
- package/assembly/contextProvider.ts +122 -122
- package/assembly/helper.ts +10 -10
- package/assembly/index.ts +3 -3
- package/assembly/integrationConfigProvider.ts +122 -86
- package/assembly/requestResponseHandler.ts +136 -104
- package/assembly/sdk/HttpContextProvider.ts +24 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
# KnownUser.V3.Fastly
|
|
2
|
-
|
|
3
|
-
The Queue-it Security Framework ensures that end-users are not able to access your online application without first
|
|
4
|
-
going through the queue for any and all �protected� areas and paths on your sites. The queue system is implemented by
|
|
5
|
-
adding a server-side (request-level) integration that protects your online application by redirecting users to a waiting
|
|
6
|
-
room according to web traffic settings in the Queue-it GO Platform. After the integration is complete, queue system
|
|
7
|
-
behavior and operations are managed in Queue-it�s Go Platform and/or via the Queue-it Admin API.
|
|
8
|
-
|
|
9
|
-
This Fastly Queue-it Connector SDK (aka, Queue-it�s server-side KnownUser connector) uses a Compute@Edge service to
|
|
10
|
-
integrate Queue-it's functionality into Fastly's network.
|
|
11
|
-
|
|
12
|
-
A Wasm service is required to utilize this connector.
|
|
13
|
-
|
|
14
|
-
> You can find the latest released version [here](https://github.com/queueit/KnownUser.V3.Fastly/releases/latest).
|
|
15
|
-
|
|
16
|
-
## Introduction
|
|
17
|
-
|
|
18
|
-
When a user makes a request to your Fastly service our connector validates the request and if it is needed, it will
|
|
19
|
-
redirect the user to the waiting room. After waiting in the waiting room, the queue engine will redirect the user back
|
|
20
|
-
to your end attaching a query string parameter ( `queueittoken` ) containing some information about the user to the URL.
|
|
21
|
-
The most important fields of the `queueittoken` are:
|
|
22
|
-
|
|
23
|
-
- q - The user's unique queue identifier
|
|
24
|
-
- ts - A timestamp of how long this redirect is valid
|
|
25
|
-
- h - A hash of the token
|
|
26
|
-
|
|
27
|
-
After the user returns from the queue, the connector will let the user continue his request to your backend ( without
|
|
28
|
-
redirecting to the queue since the request has a valid queueittoken as query string) .
|
|
29
|
-
|
|
30
|
-
## Installation
|
|
31
|
-
|
|
32
|
-
There are two methods of installation:
|
|
33
|
-
|
|
34
|
-
### As a standalone service
|
|
35
|
-
|
|
36
|
-
- Go to the Fastly services page and create a new **Wasm** service.
|
|
37
|
-
- Go to Domains and fill in the domain that you want your service to be reachable at. You may need to register a CNAME
|
|
38
|
-
record if you have your own domain.
|
|
39
|
-
- Then click on *Origins* and add a new host that has the hostname of your origin server.
|
|
40
|
-
You need to edit the Host and name it **origin**.
|
|
41
|
-
- Create a second host that has the hostname of `{yourCustomerId}.queue-it.net` and name it **queue-it**.
|
|
42
|
-
Edit the host, go to advanced options and fill in the same hostname in **Override host**
|
|
43
|
-
- Go to **Dictionaries** and create a new dictionary named `IntegrationConfiguration`.
|
|
44
|
-
Add the following items in the dictionary:
|
|
45
|
-
- customerId: Your customer ID
|
|
46
|
-
- apiKey: The API key for your account
|
|
47
|
-
- secret: Your KnownUserV3 secret
|
|
48
|
-
- queueItOrigin: The name of the queue-it host, in this case it's `queue-it`
|
|
49
|
-
You can find these values in the Go Queue-It self-service platform.
|
|
50
|
-
- Download the latest package from the releases page and unarchive it.
|
|
51
|
-
- Edit the `fastly.toml` file and copy the ID of your service (you can see this by opening up the service in Fastly) and
|
|
52
|
-
replace __{YourServiceId}__ with it.
|
|
53
|
-
- Archive the directory in the same format (tar.gz).
|
|
54
|
-
- Go to `Package` in the Fastly service page and upload the package.
|
|
55
|
-
- To finish up and deploy your service click on the **Activate** button.
|
|
56
|
-
|
|
57
|
-
### Customizable service with the connector
|
|
58
|
-
|
|
59
|
-
- Go to the Fastly services page and create a new **Wasm** service and copy it's ID.
|
|
60
|
-
- Clone this repository and edit the fastly.toml file, make sure to set the `service_id` field to the ID you copied.
|
|
61
|
-
- Then click on *Origins* and add a new host that has the hostname of your origin server.
|
|
62
|
-
You can name the host **origin** or whatever you choose.
|
|
63
|
-
- Create a host that has the hostname of `{yourCustomerId}.queue-it.net` and name it **queue-it**.
|
|
64
|
-
Edit the host, go to advanced options and fill in the same hostname in **Override host**
|
|
65
|
-
- Open up the service in Fastly and go to **Dictionaries** and create a new dictionary named `IntegrationConfiguration`
|
|
66
|
-
.
|
|
67
|
-
Add the following items in the dictionary:
|
|
68
|
-
- customerId: Your customer ID
|
|
69
|
-
- apiKey: The API key for your account
|
|
70
|
-
- secret: Your KnownUserV3 secret
|
|
71
|
-
- queueItOrigin: The name of the queue-it origin, in this case it's `queue-it`
|
|
72
|
-
You can find these values in the Go Queue-It self-service platform.
|
|
73
|
-
- You need to add some code that uses this connector. Here is an example:
|
|
74
|
-
|
|
75
|
-
```ts
|
|
76
|
-
import {Fastly} from "@fastly/as-compute";
|
|
77
|
-
import {onQueueITRequest, IntegrationDetails, onQueueITResponse} from "@queue-it/fastly";
|
|
78
|
-
|
|
79
|
-
const req = Fastly.getClientRequest();
|
|
80
|
-
|
|
81
|
-
// This is optional and can be null if it's specified in your Dictionary
|
|
82
|
-
const integrationDetails = new IntegrationDetails(
|
|
83
|
-
"QueueItOriginName",
|
|
84
|
-
"CustomerId",
|
|
85
|
-
"SecretKey",
|
|
86
|
-
"ApiKey");
|
|
87
|
-
let res = onQueueITRequest(req, integrationDetails);
|
|
88
|
-
|
|
89
|
-
if (res != null) {
|
|
90
|
-
Fastly.respondWith(res!);
|
|
91
|
-
} else {
|
|
92
|
-
const myOrigin = 'Ticketania';
|
|
93
|
-
const cacheOverride = new Fastly.CacheOverride();
|
|
94
|
-
const res = Fastly.fetch(req, {
|
|
95
|
-
backend: myOrigin,
|
|
96
|
-
cacheOverride,
|
|
97
|
-
}).wait();
|
|
98
|
-
onQueueITResponse(res);
|
|
99
|
-
Fastly.respondWith(res);
|
|
100
|
-
}
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
- Build and deploy the package running `fastly compute build` and `fastly compute deploy` in the same directory.
|
|
104
|
-
- Create desired waiting room(s), triggers, and actions in the Go Queue-It self-service platform.
|
|
105
|
-
Then, save/publish the configuration.
|
|
106
|
-
|
|
107
|
-
## Providing the queue configuration
|
|
108
|
-
|
|
109
|
-
The recommended way is to use the Go Queue-it self-service portal to setup the configuration. The configuration
|
|
110
|
-
specifies a set of Triggers and Actions. A Trigger is an expression matching one, more or all URLs on your website. When
|
|
111
|
-
a user enter your website and the URL matches a Trigger-expression the corresponding Action will be triggered. The
|
|
112
|
-
Action specifies which waiting room the users should be send to. In this way you can specify which waiting room(s)
|
|
113
|
-
should protect which page(s) on the fly without changing the server-side integration.
|
|
114
|
-
|
|
115
|
-
## Protecting AJAX calls
|
|
116
|
-
|
|
117
|
-
If you need to protect AJAX calls beside page loads you need to add the below JavaScript tags to your pages:
|
|
118
|
-
|
|
119
|
-
```html
|
|
120
|
-
|
|
121
|
-
<script type="text/javascript" src="//static.queue-it.net/script/queueclient.min.js"></script>
|
|
122
|
-
<script
|
|
123
|
-
data-queueit-intercept-domain="{YOUR_CURRENT_DOMAIN}"
|
|
124
|
-
data-queueit-intercept="true"
|
|
125
|
-
data-queueit-c="{YOUR_CUSTOMER_ID}"
|
|
126
|
-
type="text/javascript"
|
|
127
|
-
src="//static.queue-it.net/script/queueconfigloader.min.js">
|
|
128
|
-
</script>
|
|
129
|
-
```
|
|
1
|
+
# KnownUser.V3.Fastly
|
|
2
|
+
|
|
3
|
+
The Queue-it Security Framework ensures that end-users are not able to access your online application without first
|
|
4
|
+
going through the queue for any and all �protected� areas and paths on your sites. The queue system is implemented by
|
|
5
|
+
adding a server-side (request-level) integration that protects your online application by redirecting users to a waiting
|
|
6
|
+
room according to web traffic settings in the Queue-it GO Platform. After the integration is complete, queue system
|
|
7
|
+
behavior and operations are managed in Queue-it�s Go Platform and/or via the Queue-it Admin API.
|
|
8
|
+
|
|
9
|
+
This Fastly Queue-it Connector SDK (aka, Queue-it�s server-side KnownUser connector) uses a Compute@Edge service to
|
|
10
|
+
integrate Queue-it's functionality into Fastly's network.
|
|
11
|
+
|
|
12
|
+
A Wasm service is required to utilize this connector.
|
|
13
|
+
|
|
14
|
+
> You can find the latest released version [here](https://github.com/queueit/KnownUser.V3.Fastly/releases/latest).
|
|
15
|
+
|
|
16
|
+
## Introduction
|
|
17
|
+
|
|
18
|
+
When a user makes a request to your Fastly service our connector validates the request and if it is needed, it will
|
|
19
|
+
redirect the user to the waiting room. After waiting in the waiting room, the queue engine will redirect the user back
|
|
20
|
+
to your end attaching a query string parameter ( `queueittoken` ) containing some information about the user to the URL.
|
|
21
|
+
The most important fields of the `queueittoken` are:
|
|
22
|
+
|
|
23
|
+
- q - The user's unique queue identifier
|
|
24
|
+
- ts - A timestamp of how long this redirect is valid
|
|
25
|
+
- h - A hash of the token
|
|
26
|
+
|
|
27
|
+
After the user returns from the queue, the connector will let the user continue his request to your backend ( without
|
|
28
|
+
redirecting to the queue since the request has a valid queueittoken as query string) .
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
There are two methods of installation:
|
|
33
|
+
|
|
34
|
+
### As a standalone service
|
|
35
|
+
|
|
36
|
+
- Go to the Fastly services page and create a new **Wasm** service.
|
|
37
|
+
- Go to Domains and fill in the domain that you want your service to be reachable at. You may need to register a CNAME
|
|
38
|
+
record if you have your own domain.
|
|
39
|
+
- Then click on *Origins* and add a new host that has the hostname of your origin server.
|
|
40
|
+
You need to edit the Host and name it **origin**.
|
|
41
|
+
- Create a second host that has the hostname of `{yourCustomerId}.queue-it.net` and name it **queue-it**.
|
|
42
|
+
Edit the host, go to advanced options and fill in the same hostname in **Override host**
|
|
43
|
+
- Go to **Dictionaries** and create a new dictionary named `IntegrationConfiguration`.
|
|
44
|
+
Add the following items in the dictionary:
|
|
45
|
+
- customerId: Your customer ID
|
|
46
|
+
- apiKey: The API key for your account
|
|
47
|
+
- secret: Your KnownUserV3 secret
|
|
48
|
+
- queueItOrigin: The name of the queue-it host, in this case it's `queue-it`
|
|
49
|
+
You can find these values in the Go Queue-It self-service platform.
|
|
50
|
+
- Download the latest package from the releases page and unarchive it.
|
|
51
|
+
- Edit the `fastly.toml` file and copy the ID of your service (you can see this by opening up the service in Fastly) and
|
|
52
|
+
replace __{YourServiceId}__ with it.
|
|
53
|
+
- Archive the directory in the same format (tar.gz).
|
|
54
|
+
- Go to `Package` in the Fastly service page and upload the package.
|
|
55
|
+
- To finish up and deploy your service click on the **Activate** button.
|
|
56
|
+
|
|
57
|
+
### Customizable service with the connector
|
|
58
|
+
|
|
59
|
+
- Go to the Fastly services page and create a new **Wasm** service and copy it's ID.
|
|
60
|
+
- Clone this repository and edit the fastly.toml file, make sure to set the `service_id` field to the ID you copied.
|
|
61
|
+
- Then click on *Origins* and add a new host that has the hostname of your origin server.
|
|
62
|
+
You can name the host **origin** or whatever you choose.
|
|
63
|
+
- Create a host that has the hostname of `{yourCustomerId}.queue-it.net` and name it **queue-it**.
|
|
64
|
+
Edit the host, go to advanced options and fill in the same hostname in **Override host**
|
|
65
|
+
- Open up the service in Fastly and go to **Dictionaries** and create a new dictionary named `IntegrationConfiguration`
|
|
66
|
+
.
|
|
67
|
+
Add the following items in the dictionary:
|
|
68
|
+
- customerId: Your customer ID
|
|
69
|
+
- apiKey: The API key for your account
|
|
70
|
+
- secret: Your KnownUserV3 secret
|
|
71
|
+
- queueItOrigin: The name of the queue-it origin, in this case it's `queue-it`
|
|
72
|
+
You can find these values in the Go Queue-It self-service platform.
|
|
73
|
+
- You need to add some code that uses this connector. Here is an example:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import {Fastly} from "@fastly/as-compute";
|
|
77
|
+
import {onQueueITRequest, IntegrationDetails, onQueueITResponse} from "@queue-it/fastly";
|
|
78
|
+
|
|
79
|
+
const req = Fastly.getClientRequest();
|
|
80
|
+
|
|
81
|
+
// This is optional and can be null if it's specified in your Dictionary
|
|
82
|
+
const integrationDetails = new IntegrationDetails(
|
|
83
|
+
"QueueItOriginName",
|
|
84
|
+
"CustomerId",
|
|
85
|
+
"SecretKey",
|
|
86
|
+
"ApiKey");
|
|
87
|
+
let res = onQueueITRequest(req, integrationDetails);
|
|
88
|
+
|
|
89
|
+
if (res != null) {
|
|
90
|
+
Fastly.respondWith(res!);
|
|
91
|
+
} else {
|
|
92
|
+
const myOrigin = 'Ticketania';
|
|
93
|
+
const cacheOverride = new Fastly.CacheOverride();
|
|
94
|
+
const res = Fastly.fetch(req, {
|
|
95
|
+
backend: myOrigin,
|
|
96
|
+
cacheOverride,
|
|
97
|
+
}).wait();
|
|
98
|
+
onQueueITResponse(res);
|
|
99
|
+
Fastly.respondWith(res);
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- Build and deploy the package running `fastly compute build` and `fastly compute deploy` in the same directory.
|
|
104
|
+
- Create desired waiting room(s), triggers, and actions in the Go Queue-It self-service platform.
|
|
105
|
+
Then, save/publish the configuration.
|
|
106
|
+
|
|
107
|
+
## Providing the queue configuration
|
|
108
|
+
|
|
109
|
+
The recommended way is to use the Go Queue-it self-service portal to setup the configuration. The configuration
|
|
110
|
+
specifies a set of Triggers and Actions. A Trigger is an expression matching one, more or all URLs on your website. When
|
|
111
|
+
a user enter your website and the URL matches a Trigger-expression the corresponding Action will be triggered. The
|
|
112
|
+
Action specifies which waiting room the users should be send to. In this way you can specify which waiting room(s)
|
|
113
|
+
should protect which page(s) on the fly without changing the server-side integration.
|
|
114
|
+
|
|
115
|
+
## Protecting AJAX calls
|
|
116
|
+
|
|
117
|
+
If you need to protect AJAX calls beside page loads you need to add the below JavaScript tags to your pages:
|
|
118
|
+
|
|
119
|
+
```html
|
|
120
|
+
|
|
121
|
+
<script type="text/javascript" src="//static.queue-it.net/script/queueclient.min.js"></script>
|
|
122
|
+
<script
|
|
123
|
+
data-queueit-intercept-domain="{YOUR_CURRENT_DOMAIN}"
|
|
124
|
+
data-queueit-intercept="true"
|
|
125
|
+
data-queueit-c="{YOUR_CUSTOMER_ID}"
|
|
126
|
+
type="text/javascript"
|
|
127
|
+
src="//static.queue-it.net/script/queueconfigloader.min.js">
|
|
128
|
+
</script>
|
|
129
|
+
```
|
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
import {IHttpContextProvider, IHttpRequest, IHttpResponse} from "./sdk/HttpContextProvider";
|
|
2
|
-
import {Request, Fastly, Headers} from "@fastly/as-compute";
|
|
3
|
-
import {decodeURIComponent, encodeURIComponent} from "./sdk/helpers/Uri";
|
|
4
|
-
|
|
5
|
-
export function getHttpHandler(req: Request): FastlyHttpContextProvider {
|
|
6
|
-
return new FastlyHttpContextProvider(req);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class FastlyHttpContextProvider implements IHttpContextProvider {
|
|
10
|
-
isError: bool = false;
|
|
11
|
-
private readonly req: FastlyHttpRequest;
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
private readonly res: FastlyHttpResponse;
|
|
14
|
-
|
|
15
|
-
constructor(fReq: Request) {
|
|
16
|
-
this.req = new FastlyHttpRequest(fReq);
|
|
17
|
-
this.res = new FastlyHttpResponse();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
getHttpRequest(): IHttpRequest {
|
|
21
|
-
return this.req;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getHttpResponse(): IHttpResponse {
|
|
25
|
-
return this.res;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class FastlyHttpRequest implements IHttpRequest {
|
|
30
|
-
private parsedCookieDic: Map<string, string>
|
|
31
|
-
private bodyFetched: bool = false;
|
|
32
|
-
private body: string = '';
|
|
33
|
-
|
|
34
|
-
constructor(private baseReq: Request) {
|
|
35
|
-
this.parsedCookieDic = new Map();
|
|
36
|
-
this.bodyFetched = false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
private parseCookies(cookieValue: string): void {
|
|
40
|
-
const cookies = cookieValue.split(';');
|
|
41
|
-
for (let i = 0; i < cookies.length; i++) {
|
|
42
|
-
let cookieKV = cookies[i].split('=', 2);
|
|
43
|
-
if (cookieKV.length >= 2) {
|
|
44
|
-
this.parsedCookieDic.set(cookieKV[0].trim(), cookieKV[1].trim())
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private handleBody(): void {
|
|
50
|
-
if (this.baseReq.bodyUsed || this.bodyFetched) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
this.bodyFetched = true;
|
|
54
|
-
const rawBody: ArrayBuffer | null = null; // this.context.req.arrayBuffer();
|
|
55
|
-
if (rawBody == null) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (rawBody!.byteLength == 0) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
this.body = ''; // this.context.req.text()
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
getAbsoluteUri(): string {
|
|
66
|
-
return this.baseReq.url;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
getCookieValue(cookieKey: string): string {
|
|
70
|
-
if (this.parsedCookieDic.keys().length == 0) {
|
|
71
|
-
this.parseCookies(this.getHeader('cookie'))
|
|
72
|
-
}
|
|
73
|
-
return this.parsedCookieDic.has(cookieKey) ? decodeURIComponent(this.parsedCookieDic.get(cookieKey)) : '';
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
getHeader(name: string): string {
|
|
77
|
-
if (name.length == 0) return "";
|
|
78
|
-
if (!this.baseReq.headers.has(name)) {
|
|
79
|
-
return '';
|
|
80
|
-
}
|
|
81
|
-
const value = this.baseReq.headers.get(name);
|
|
82
|
-
if (value == null) return '';
|
|
83
|
-
return value!;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
getRequestBodyAsString(): string {
|
|
87
|
-
if (!this.bodyFetched) {
|
|
88
|
-
this.handleBody();
|
|
89
|
-
}
|
|
90
|
-
return this.body;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
getUserAgent(): string {
|
|
94
|
-
return this.baseReq.headers.has('user-agent') ? this.baseReq.headers.get('user-agent')! : '';
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
getUserHostAddress(): string {
|
|
98
|
-
return Fastly.getClientIpAddressString();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export class FastlyHttpResponse implements IHttpResponse {
|
|
103
|
-
private readonly headers: Headers;
|
|
104
|
-
|
|
105
|
-
constructor() {
|
|
106
|
-
this.headers = new Headers();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
setCookie(cookieName: string, cookieValue: string, domain: string, expiration: i64): void {
|
|
110
|
-
const expirationDate = new Date(expiration * 1000);
|
|
111
|
-
let setCookieString = cookieName + "=" + encodeURIComponent(cookieValue) + "; expires=" + expirationDate.toUTCString() + ";";
|
|
112
|
-
if (domain != "") {
|
|
113
|
-
setCookieString += " domain=" + domain + ";";
|
|
114
|
-
}
|
|
115
|
-
setCookieString += " path=/;";
|
|
116
|
-
this.headers.set('set-cookie', setCookieString);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
getHeaders(): Headers {
|
|
120
|
-
return this.headers;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
1
|
+
import {IHttpContextProvider, IHttpRequest, IHttpResponse} from "./sdk/HttpContextProvider";
|
|
2
|
+
import {Request, Fastly, Headers} from "@fastly/as-compute";
|
|
3
|
+
import {decodeURIComponent, encodeURIComponent} from "./sdk/helpers/Uri";
|
|
4
|
+
|
|
5
|
+
export function getHttpHandler(req: Request): FastlyHttpContextProvider {
|
|
6
|
+
return new FastlyHttpContextProvider(req);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class FastlyHttpContextProvider implements IHttpContextProvider {
|
|
10
|
+
isError: bool = false;
|
|
11
|
+
private readonly req: FastlyHttpRequest;
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
private readonly res: FastlyHttpResponse;
|
|
14
|
+
|
|
15
|
+
constructor(fReq: Request) {
|
|
16
|
+
this.req = new FastlyHttpRequest(fReq);
|
|
17
|
+
this.res = new FastlyHttpResponse();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getHttpRequest(): IHttpRequest {
|
|
21
|
+
return this.req;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getHttpResponse(): IHttpResponse {
|
|
25
|
+
return this.res;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class FastlyHttpRequest implements IHttpRequest {
|
|
30
|
+
private parsedCookieDic: Map<string, string>
|
|
31
|
+
private bodyFetched: bool = false;
|
|
32
|
+
private body: string = '';
|
|
33
|
+
|
|
34
|
+
constructor(private baseReq: Request) {
|
|
35
|
+
this.parsedCookieDic = new Map();
|
|
36
|
+
this.bodyFetched = false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private parseCookies(cookieValue: string): void {
|
|
40
|
+
const cookies = cookieValue.split(';');
|
|
41
|
+
for (let i = 0; i < cookies.length; i++) {
|
|
42
|
+
let cookieKV = cookies[i].split('=', 2);
|
|
43
|
+
if (cookieKV.length >= 2) {
|
|
44
|
+
this.parsedCookieDic.set(cookieKV[0].trim(), cookieKV[1].trim())
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private handleBody(): void {
|
|
50
|
+
if (this.baseReq.bodyUsed || this.bodyFetched) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.bodyFetched = true;
|
|
54
|
+
const rawBody: ArrayBuffer | null = null; // this.context.req.arrayBuffer();
|
|
55
|
+
if (rawBody == null) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (rawBody!.byteLength == 0) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this.body = ''; // this.context.req.text()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getAbsoluteUri(): string {
|
|
66
|
+
return this.baseReq.url;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
getCookieValue(cookieKey: string): string {
|
|
70
|
+
if (this.parsedCookieDic.keys().length == 0) {
|
|
71
|
+
this.parseCookies(this.getHeader('cookie'))
|
|
72
|
+
}
|
|
73
|
+
return this.parsedCookieDic.has(cookieKey) ? decodeURIComponent(this.parsedCookieDic.get(cookieKey)) : '';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getHeader(name: string): string {
|
|
77
|
+
if (name.length == 0) return "";
|
|
78
|
+
if (!this.baseReq.headers.has(name)) {
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
const value = this.baseReq.headers.get(name);
|
|
82
|
+
if (value == null) return '';
|
|
83
|
+
return value!;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
getRequestBodyAsString(): string {
|
|
87
|
+
if (!this.bodyFetched) {
|
|
88
|
+
this.handleBody();
|
|
89
|
+
}
|
|
90
|
+
return this.body;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getUserAgent(): string {
|
|
94
|
+
return this.baseReq.headers.has('user-agent') ? this.baseReq.headers.get('user-agent')! : '';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getUserHostAddress(): string {
|
|
98
|
+
return Fastly.getClientIpAddressString();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export class FastlyHttpResponse implements IHttpResponse {
|
|
103
|
+
private readonly headers: Headers;
|
|
104
|
+
|
|
105
|
+
constructor() {
|
|
106
|
+
this.headers = new Headers();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
setCookie(cookieName: string, cookieValue: string, domain: string, expiration: i64): void {
|
|
110
|
+
const expirationDate = new Date(expiration * 1000);
|
|
111
|
+
let setCookieString = cookieName + "=" + encodeURIComponent(cookieValue) + "; expires=" + expirationDate.toUTCString() + ";";
|
|
112
|
+
if (domain != "") {
|
|
113
|
+
setCookieString += " domain=" + domain + ";";
|
|
114
|
+
}
|
|
115
|
+
setCookieString += " path=/;";
|
|
116
|
+
this.headers.set('set-cookie', setCookieString);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getHeaders(): Headers {
|
|
120
|
+
return this.headers;
|
|
121
|
+
}
|
|
122
|
+
}
|
package/assembly/helper.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {Utils} from "./sdk/QueueITHelpers";
|
|
2
|
-
import {hmacString} from "./sdk/helpers/crypto";
|
|
1
|
+
import { Utils } from "./sdk/QueueITHelpers";
|
|
2
|
+
import { hmacString } from "./sdk/helpers/crypto";
|
|
3
3
|
|
|
4
4
|
export class QueueITHelper {
|
|
5
|
-
|
|
5
|
+
static readonly KUP_VERSION: string = "fastly-1.0.3";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
static configureKnownUserHashing(): void {
|
|
8
|
+
Utils.generateSHA256Hash = hmacString;
|
|
9
|
+
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
static addKUPlatformVersion(redirectQueueUrl: string): string {
|
|
12
|
+
return redirectQueueUrl + "&kupver=" + QueueITHelper.KUP_VERSION;
|
|
13
|
+
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export interface RequestLogger {
|
|
17
|
-
|
|
17
|
+
log(message: string): void;
|
|
18
18
|
}
|
package/assembly/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {IntegrationDetails, IntegrationEndpointProvider, IntegrationEndpointCacheConfig} from "./integrationConfigProvider"
|
|
2
|
-
export {onQueueITRequest, onQueueITResponse} from "./requestResponseHandler";
|
|
3
|
-
export {RequestLogger} from "./helper";
|
|
1
|
+
export {IntegrationDetails, IntegrationEndpointProvider, IntegrationEndpointCacheConfig} from "./integrationConfigProvider"
|
|
2
|
+
export {onQueueITRequest, onQueueITResponse} from "./requestResponseHandler";
|
|
3
|
+
export {RequestLogger} from "./helper";
|
|
@@ -1,110 +1,146 @@
|
|
|
1
|
-
import {Fastly, Headers, Request} from "@fastly/as-compute";
|
|
2
|
-
import {RequestLogger} from "./helper";
|
|
3
|
-
|
|
4
|
-
export function getIntegrationConfig(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { Fastly, Headers, Request } from "@fastly/as-compute";
|
|
2
|
+
import { RequestLogger } from "./helper";
|
|
3
|
+
|
|
4
|
+
export function getIntegrationConfig(
|
|
5
|
+
details: IntegrationDetails,
|
|
6
|
+
endpointProvider: IntegrationEndpointProvider
|
|
7
|
+
): string {
|
|
8
|
+
const headers = new Headers();
|
|
9
|
+
headers.set("api-key", details.apiKey);
|
|
10
|
+
headers.set("host", endpointProvider.getHostname(details.customerId));
|
|
11
|
+
const request = new Request(
|
|
12
|
+
endpointProvider.getEndpoint(details.customerId),
|
|
13
|
+
{
|
|
14
|
+
method: "GET",
|
|
15
|
+
body: null,
|
|
16
|
+
headers: headers,
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
);
|
|
19
|
+
let cacheOverride = new Fastly.CacheOverride();
|
|
20
|
+
let cacheConf = endpointProvider.getCacheConfig();
|
|
21
|
+
if (cacheConf.maxAge != -1) {
|
|
22
|
+
cacheOverride.setTTL(cacheConf.maxAge);
|
|
23
|
+
}
|
|
24
|
+
if (cacheConf.staleWhileRevalidate != -1) {
|
|
25
|
+
cacheOverride.setSWR(cacheConf.staleWhileRevalidate);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let beresp = Fastly.fetch(request, {
|
|
29
|
+
backend: details.queueItOrigin,
|
|
30
|
+
cacheOverride: cacheOverride,
|
|
31
|
+
}).wait();
|
|
32
|
+
|
|
33
|
+
if (!(details.logger instanceof MockLogger)) {
|
|
34
|
+
let cacheState = beresp.headers.get("x-cache");
|
|
35
|
+
let hits = beresp.headers.get("x-cache-hits");
|
|
36
|
+
if (hits == null) hits = "-1";
|
|
37
|
+
if (cacheState == null) cacheState = "n";
|
|
38
|
+
details.logger.log("IgnFetch:" + cacheState! + ":" + hits!);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (beresp.status != 200) {
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
return beresp.text();
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
const integrationCustomerId = "customerId",
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
integrationApiKey = "apiKey",
|
|
49
|
+
integrationSecret = "secret",
|
|
50
|
+
integrationQueueItOrigin = "queueItOrigin",
|
|
51
|
+
integrationDictionary = "IntegrationConfiguration",
|
|
52
|
+
workerHost = "workerHost";
|
|
44
53
|
|
|
45
54
|
export function resolveIntegrationDetails(): IntegrationDetails | null {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
const dict = new Fastly.Dictionary(integrationDictionary);
|
|
56
|
+
if (
|
|
57
|
+
!dict.contains(integrationCustomerId) ||
|
|
58
|
+
!dict.contains(integrationApiKey) ||
|
|
59
|
+
!dict.contains(integrationSecret) ||
|
|
60
|
+
!dict.contains(integrationQueueItOrigin)
|
|
61
|
+
) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let workerHostValue = "";
|
|
66
|
+
if (dict.contains(workerHost)) {
|
|
67
|
+
workerHostValue = dict.get(workerHost)!;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return new IntegrationDetails(
|
|
71
|
+
dict.get(integrationQueueItOrigin)!,
|
|
72
|
+
dict.get(integrationCustomerId)!,
|
|
73
|
+
dict.get(integrationSecret)!,
|
|
74
|
+
dict.get(integrationApiKey)!,
|
|
75
|
+
workerHostValue
|
|
76
|
+
);
|
|
59
77
|
}
|
|
60
78
|
|
|
61
79
|
export class IntegrationEndpointCacheConfig {
|
|
62
|
-
|
|
63
|
-
|
|
80
|
+
maxAge: i16 = -1;
|
|
81
|
+
staleWhileRevalidate: i16 = -1;
|
|
64
82
|
}
|
|
65
83
|
|
|
66
84
|
export interface IntegrationEndpointProvider {
|
|
67
|
-
|
|
85
|
+
getHostname(customerId: string): string;
|
|
68
86
|
|
|
69
|
-
|
|
87
|
+
getEndpoint(customerId: string): string;
|
|
70
88
|
|
|
71
|
-
|
|
89
|
+
getCacheConfig(): IntegrationEndpointCacheConfig;
|
|
72
90
|
}
|
|
73
91
|
|
|
74
|
-
export class QueueItIntegrationEndpointProvider
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
export class QueueItIntegrationEndpointProvider
|
|
93
|
+
implements IntegrationEndpointProvider
|
|
94
|
+
{
|
|
95
|
+
private readonly cacheConfig: IntegrationEndpointCacheConfig;
|
|
96
|
+
|
|
97
|
+
constructor() {
|
|
98
|
+
this.cacheConfig = new IntegrationEndpointCacheConfig();
|
|
99
|
+
this.cacheConfig.maxAge = 60 * 5;
|
|
100
|
+
this.cacheConfig.staleWhileRevalidate = 60 * 5;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getCacheConfig(): IntegrationEndpointCacheConfig {
|
|
104
|
+
return this.cacheConfig;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getHostname(customerId: string): string {
|
|
108
|
+
return customerId + ".queue-it.net";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getEndpoint(customerId: string): string {
|
|
112
|
+
const host = this.getHostname(customerId);
|
|
113
|
+
return "https://" + host + "/status/integrationconfig/secure/" + customerId;
|
|
114
|
+
}
|
|
95
115
|
}
|
|
96
116
|
|
|
97
117
|
class MockLogger implements RequestLogger {
|
|
98
|
-
|
|
99
|
-
}
|
|
118
|
+
log(message: string): void {}
|
|
100
119
|
}
|
|
101
120
|
|
|
102
121
|
export class IntegrationDetails {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
122
|
+
constructor(
|
|
123
|
+
public queueItOrigin: string,
|
|
124
|
+
public customerId: string,
|
|
125
|
+
public secretKey: string,
|
|
126
|
+
public apiKey: string,
|
|
127
|
+
public workerHost: string,
|
|
128
|
+
public provider: IntegrationEndpointProvider = new QueueItIntegrationEndpointProvider(),
|
|
129
|
+
public logger: RequestLogger = new MockLogger()
|
|
130
|
+
) {}
|
|
131
|
+
|
|
132
|
+
resolveWorkerRequestUrl(pureUrl: string): string {
|
|
133
|
+
if (this.workerHost == "") {
|
|
134
|
+
return pureUrl;
|
|
109
135
|
}
|
|
136
|
+
const protoEnding = pureUrl.indexOf("://") + 3;
|
|
137
|
+
const protocol = pureUrl.substr(0, protoEnding);
|
|
138
|
+
const urlWithoutProto = pureUrl.substr(protoEnding);
|
|
139
|
+
const pathAndQuery =
|
|
140
|
+
urlWithoutProto.indexOf("/") != -1
|
|
141
|
+
? urlWithoutProto.substr(urlWithoutProto.indexOf("/"))
|
|
142
|
+
: "";
|
|
143
|
+
const rewrittenUrl = protocol + this.workerHost + pathAndQuery;
|
|
144
|
+
return rewrittenUrl;
|
|
145
|
+
}
|
|
110
146
|
}
|
|
@@ -1,104 +1,136 @@
|
|
|
1
|
-
import {Request, Response, Headers} from "@fastly/as-compute";
|
|
2
|
-
import {KnownUser} from "./sdk/KnownUser";
|
|
3
|
-
import {QueueITHelper} from "./helper";
|
|
4
|
-
import {FastlyHttpContextProvider, getHttpHandler} from "./contextProvider";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from "./integrationConfigProvider"
|
|
11
|
-
import {Utils} from "./sdk/QueueITHelpers";
|
|
12
|
-
|
|
13
|
-
const QUEUEIT_FAILED_HEADERNAME =
|
|
14
|
-
let httpProvider: FastlyHttpContextProvider | null = null;
|
|
15
|
-
|
|
16
|
-
export function onQueueITRequest(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
1
|
+
import { Request, Response, Headers } from "@fastly/as-compute";
|
|
2
|
+
import { KnownUser } from "./sdk/KnownUser";
|
|
3
|
+
import { QueueITHelper } from "./helper";
|
|
4
|
+
import { FastlyHttpContextProvider, getHttpHandler } from "./contextProvider";
|
|
5
|
+
import {
|
|
6
|
+
getIntegrationConfig,
|
|
7
|
+
resolveIntegrationDetails,
|
|
8
|
+
IntegrationDetails,
|
|
9
|
+
QueueItIntegrationEndpointProvider,
|
|
10
|
+
} from "./integrationConfigProvider";
|
|
11
|
+
import { Utils } from "./sdk/QueueITHelpers";
|
|
12
|
+
|
|
13
|
+
const QUEUEIT_FAILED_HEADERNAME = "x-queueit-failed";
|
|
14
|
+
let httpProvider: FastlyHttpContextProvider | null = null;
|
|
15
|
+
|
|
16
|
+
export function onQueueITRequest(
|
|
17
|
+
req: Request,
|
|
18
|
+
conf: IntegrationDetails | null = null
|
|
19
|
+
): Response | null {
|
|
20
|
+
if (conf == null) {
|
|
21
|
+
conf = resolveIntegrationDetails();
|
|
22
|
+
}
|
|
23
|
+
if (conf == null) {
|
|
24
|
+
return new Response(String.UTF8.encode("No integration details found."), {
|
|
25
|
+
headers: new Headers(),
|
|
26
|
+
status: 404,
|
|
27
|
+
url: "",
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const integrationProvider =
|
|
32
|
+
conf.provider == null
|
|
33
|
+
? new QueueItIntegrationEndpointProvider()
|
|
34
|
+
: conf.provider;
|
|
35
|
+
QueueITHelper.configureKnownUserHashing();
|
|
36
|
+
httpProvider = getHttpHandler(req);
|
|
37
|
+
|
|
38
|
+
let integrationConfigJson = getIntegrationConfig(conf, integrationProvider);
|
|
39
|
+
const requestUrl: string = conf.resolveWorkerRequestUrl(req.url);
|
|
40
|
+
|
|
41
|
+
const queueItToken = Utils.getParameterByName(
|
|
42
|
+
requestUrl,
|
|
43
|
+
KnownUser.QueueITTokenKey
|
|
44
|
+
);
|
|
45
|
+
const requestUrlWithoutToken: string = Utils.removeQueueItToken(requestUrl);
|
|
46
|
+
|
|
47
|
+
// The requestUrlWithoutToken is used to match Triggers and as the Target url (where to return the users to).
|
|
48
|
+
// It is therefor important that this is exactly the url of the users browsers. So, if your webserver is
|
|
49
|
+
// behind e.g. a load balancer that modifies the host name or port, reformat requestUrlWithoutToken before proceeding.
|
|
50
|
+
const validationResultPair = KnownUser.validateRequestByIntegrationConfig(
|
|
51
|
+
requestUrlWithoutToken,
|
|
52
|
+
queueItToken,
|
|
53
|
+
integrationConfigJson,
|
|
54
|
+
conf.customerId,
|
|
55
|
+
conf.secretKey,
|
|
56
|
+
httpProvider!
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
if (
|
|
60
|
+
validationResultPair.first != null &&
|
|
61
|
+
validationResultPair.first!.doRedirect()
|
|
62
|
+
) {
|
|
63
|
+
const validationResult = validationResultPair.first!;
|
|
64
|
+
|
|
65
|
+
if (validationResult.isAjaxResult) {
|
|
66
|
+
let response = new Response(null, {
|
|
67
|
+
status: 200,
|
|
68
|
+
headers: httpProvider!.getHttpResponse().getHeaders(),
|
|
69
|
+
url: "",
|
|
70
|
+
});
|
|
71
|
+
// 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
|
|
72
|
+
response.headers.set(
|
|
73
|
+
validationResult.getAjaxQueueRedirectHeaderKey(),
|
|
74
|
+
QueueITHelper.addKUPlatformVersion(
|
|
75
|
+
validationResult.getAjaxRedirectUrl()
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
Utils.addNoCacheHeaders(response);
|
|
79
|
+
return response;
|
|
80
|
+
} else {
|
|
81
|
+
let response = new Response(null, {
|
|
82
|
+
status: 302,
|
|
83
|
+
headers: httpProvider!.getHttpResponse().getHeaders(),
|
|
84
|
+
url: "",
|
|
85
|
+
});
|
|
86
|
+
// Send the user to the queue - either because hash was missing or because is was invalid
|
|
87
|
+
response.headers.set(
|
|
88
|
+
"Location",
|
|
89
|
+
QueueITHelper.addKUPlatformVersion(validationResult.redirectUrl)
|
|
90
|
+
);
|
|
91
|
+
Utils.addNoCacheHeaders(response);
|
|
92
|
+
return response;
|
|
93
|
+
}
|
|
94
|
+
} else if (validationResultPair.first != null) {
|
|
95
|
+
const validationResult = validationResultPair.first!;
|
|
96
|
+
// Request can continue - we remove queueittoken form querystring parameter to avoid sharing of user specific token
|
|
97
|
+
// Support mobile scenario adding the condition !validationResult.isAjaxResult
|
|
98
|
+
if (
|
|
99
|
+
queueItToken != "" &&
|
|
100
|
+
!validationResult.isAjaxResult &&
|
|
101
|
+
validationResult.actionType == "Queue"
|
|
102
|
+
) {
|
|
103
|
+
let response = new Response(null, {
|
|
104
|
+
status: 302,
|
|
105
|
+
headers: httpProvider!.getHttpResponse().getHeaders(),
|
|
106
|
+
url: requestUrlWithoutToken,
|
|
107
|
+
});
|
|
108
|
+
response.headers.set("Location", requestUrlWithoutToken);
|
|
109
|
+
Utils.addNoCacheHeaders(response);
|
|
110
|
+
return response;
|
|
111
|
+
} else {
|
|
112
|
+
// lets caller decide the next step, or just serve the request normally
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
} else if (validationResultPair.second != null) {
|
|
116
|
+
httpProvider!.isError = true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//Fill in the Queue-it headers
|
|
123
|
+
export function onQueueITResponse(res: Response): void {
|
|
124
|
+
const contextHeaders = httpProvider!.getHttpResponse().getHeaders();
|
|
125
|
+
const contextHeaderKeys = contextHeaders.keys();
|
|
126
|
+
|
|
127
|
+
if (httpProvider!.isError) {
|
|
128
|
+
res.headers.append(QUEUEIT_FAILED_HEADERNAME, "true");
|
|
129
|
+
}
|
|
130
|
+
for (let i = 0; i < contextHeaderKeys.length; i++) {
|
|
131
|
+
if (contextHeaderKeys[i].length == 0) continue;
|
|
132
|
+
let value = contextHeaders.get(contextHeaderKeys[i]);
|
|
133
|
+
if (value != null && value!.length > 0)
|
|
134
|
+
res.headers.append(contextHeaderKeys[i], value!);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { Headers } from "@fastly/as-compute";
|
|
2
|
-
|
|
3
|
-
export interface IHttpRequest {
|
|
4
|
-
getUserAgent(): string;
|
|
5
|
-
getHeader(name: string): string;
|
|
6
|
-
getAbsoluteUri(): string;
|
|
7
|
-
getUserHostAddress(): string;
|
|
8
|
-
getCookieValue(cookieKey: string): string;
|
|
9
|
-
getRequestBodyAsString(): string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface IHttpResponse {
|
|
13
|
-
setCookie(cookieName: string, cookieValue: string, domain: string, expiration: i64): void;
|
|
14
|
-
getHeaders(): Headers;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface IHttpContextProvider {
|
|
18
|
-
getHttpRequest(): IHttpRequest;
|
|
19
|
-
getHttpResponse(): IHttpResponse;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface IDateTimeProvider {
|
|
23
|
-
getCurrentTime(): Date
|
|
24
|
-
}
|
|
1
|
+
import { Headers } from "@fastly/as-compute";
|
|
2
|
+
|
|
3
|
+
export interface IHttpRequest {
|
|
4
|
+
getUserAgent(): string;
|
|
5
|
+
getHeader(name: string): string;
|
|
6
|
+
getAbsoluteUri(): string;
|
|
7
|
+
getUserHostAddress(): string;
|
|
8
|
+
getCookieValue(cookieKey: string): string;
|
|
9
|
+
getRequestBodyAsString(): string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IHttpResponse {
|
|
13
|
+
setCookie(cookieName: string, cookieValue: string, domain: string, expiration: i64): void;
|
|
14
|
+
getHeaders(): Headers;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface IHttpContextProvider {
|
|
18
|
+
getHttpRequest(): IHttpRequest;
|
|
19
|
+
getHttpResponse(): IHttpResponse;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface IDateTimeProvider {
|
|
23
|
+
getCurrentTime(): Date
|
|
24
|
+
}
|