forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestInfoPlugin.ts
More file actions
31 lines (27 loc) · 1.09 KB
/
RequestInfoPlugin.ts
File metadata and controls
31 lines (27 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { RequestInfo } from "../../models/data/RequestInfo.js";
import { isMatch } from "../../Utils.js";
import { EventPluginContext } from "../EventPluginContext.js";
import { IEventPlugin } from "../IEventPlugin.js";
export class RequestInfoPlugin implements IEventPlugin {
public priority: number = 70;
public name: string = "RequestInfoPlugin";
public run(context: EventPluginContext): Promise<void> {
const REQUEST_KEY: string = "@request"; // optimization for minifier.
const config = context.client.config;
const collector = config.requestInfoCollector;
if (!context.event.data[REQUEST_KEY] && collector) {
const requestInfo: RequestInfo = collector.getRequestInfo(context);
if (requestInfo) {
if (isMatch(requestInfo.user_agent, config.userAgentBotPatterns)) {
context.log.info(
"Cancelling event as the request user agent matches a known bot pattern",
);
context.cancelled = true;
} else {
context.event.data[REQUEST_KEY] = requestInfo;
}
}
}
return Promise.resolve();
}
}