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
53 lines (43 loc) · 1.47 KB
/
RequestInfoPlugin.ts
File metadata and controls
53 lines (43 loc) · 1.47 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { IEventPlugin } from '../IEventPlugin';
import { EventPluginContext } from '../EventPluginContext';
import { IRequestInfo } from '../../models/IRequestInfo';
import { Utils } from '../../Utils';
export class RequestInfoPlugin implements IEventPlugin {
public priority:number = 60;
public name:string = 'RequestInfoPlugin';
run(context:EventPluginContext):Promise<any> {
if (!!context.event.data && !!context.event.data['@request']) {
return Promise.resolve();
}
if (!context.event.data) {
context.event.data = {};
}
var requestInfo:IRequestInfo = {
user_agent: navigator.userAgent,
is_secure: location.protocol === 'https:',
host: location.hostname,
port: location.port && location.port !== '' ? parseInt(location.port) : 80,
path: location.pathname,
//client_ip_address: 'TODO',
cookies: this.getCookies(),
query_string: Utils.parseQueryString(location.search.substring(1))
};
if (document.referrer && document.referrer !== '') {
requestInfo.referrer = document.referrer;
}
context.event.data['@request'] = requestInfo;
return Promise.resolve();
}
private getCookies(): any {
if (!document.cookie) {
return null;
}
var result = {};
var cookies = document.cookie.split(', ');
for (var index = 0; index < cookies.length; index++) {
var cookie = cookies[index].split('=');
result[cookie[0]] = cookie[1];
}
return result;
}
}