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
29 lines (25 loc) · 1.06 KB
/
RequestInfoPlugin.ts
File metadata and controls
29 lines (25 loc) · 1.06 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
import { IRequestInfo } from '../../models/IRequestInfo';
import { Utils } from '../../Utils';
import { EventPluginContext } from '../EventPluginContext';
import { IEventPlugin } from '../IEventPlugin';
export class RequestInfoPlugin implements IEventPlugin {
public priority: number = 70;
public name: string = 'RequestInfoPlugin';
public run(context: EventPluginContext, next?: () => void): 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: IRequestInfo = collector.getRequestInfo(context);
if (!!requestInfo) {
if (Utils.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;
}
}
}
next && next();
}
}