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
28 lines (25 loc) · 1.09 KB
/
RequestInfoPlugin.ts
File metadata and controls
28 lines (25 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
import { RequestInfo } from "../../models/data/RequestInfo.js";
import { KnownEventDataKeys } from "../../models/Event.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 config = context.client.config;
const collector = config.services.requestInfoCollector;
if (!context.event.data[KnownEventDataKeys.RequestInfo] && 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[KnownEventDataKeys.RequestInfo] = requestInfo;
}
}
}
return Promise.resolve();
}
}