Skip to content

Commit d719b34

Browse files
authored
Added script for headers (#133)
I'm not sure about any differences between node headers vs express headers https://nodejs.org/api/http.html#requestgetheaders
1 parent a48b7d4 commit d719b34

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

packages/browser/src/plugins/BrowserRequestInfoPlugin.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ export class BrowserRequestInfoPlugin implements IEventPlugin {
4242
port: location.port && location.port !== ""
4343
? parseInt(location.port, 10)
4444
: 80,
45-
path: location.pathname,
46-
// client_ip_address: "TODO"
45+
path: location.pathname
4746
};
4847

4948
if (config.includeCookies) {
@@ -53,7 +52,7 @@ export class BrowserRequestInfoPlugin implements IEventPlugin {
5352
if (config.includeQueryString) {
5453
requestInfo.query_string = parseQueryString(
5554
location.search.substring(1),
56-
exclusions,
55+
exclusions
5756
);
5857
}
5958

packages/core/src/configuration/Configuration.ts

+18
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class Configuration {
102102
private _includeUserName = true;
103103
private _includeMachineName = true;
104104
private _includeIpAddress = true;
105+
private _includeHeaders = true;
105106
private _includeCookies = true;
106107
private _includePostData = true;
107108
private _includeQueryString = true;
@@ -212,6 +213,7 @@ export class Configuration {
212213
this._includeUserName = val;
213214
this._includeMachineName = val;
214215
this._includeIpAddress = val;
216+
this._includeHeaders = val;
215217
this._includeCookies = val;
216218
this._includePostData = val;
217219
this._includeQueryString = val;
@@ -259,6 +261,22 @@ export class Configuration {
259261
this._includeIpAddress = value === true;
260262
}
261263

264+
/**
265+
* Gets a value indicating whether to include Headers.
266+
* NOTE: DataExclusions are applied to all Header keys when enabled.
267+
*/
268+
public get includeHeaders(): boolean {
269+
return this._includeHeaders;
270+
}
271+
272+
/**
273+
* Sets a value indicating whether to include Headers.
274+
* NOTE: DataExclusions are applied to all Headers keys when enabled.
275+
*/
276+
public set includeHeaders(value: boolean) {
277+
this._includeHeaders = value === true;
278+
}
279+
262280
/**
263281
* Gets a value indicating whether to include Cookies.
264282
* NOTE: DataExclusions are applied to all Cookie keys when enabled.

packages/core/src/models/data/RequestInfo.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface RequestInfo {
77
path?: string;
88
referrer?: string;
99
client_ip_address?: string;
10+
headers?: Record<string, string[]>;
1011
cookies?: Record<string, string>;
1112
post_data?: Record<string, unknown>;
1213
query_string?: Record<string, string>;

packages/node/src/plugins/NodeRequestInfoPlugin.ts

+24
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,30 @@ export class NodeRequestInfoPlugin implements IEventPlugin {
7474
requestInfo.cookies = getCookies(request.headers.cookie, exclusions) as Record<string, string>;
7575
}
7676

77+
if (config.includeHeaders) {
78+
const ignoredHeaders = [
79+
"Authorization",
80+
"Cookie",
81+
"Host",
82+
"Method",
83+
"Path",
84+
"Proxy-Authorization",
85+
"Referer",
86+
"User-Agent"
87+
];
88+
89+
const json = stringify(request.headers, [...ignoredHeaders, ...exclusions]);
90+
if (!isEmpty(json)) {
91+
const headers: Record<string, string[]> = {};
92+
const parsedHeaders = JSON.parse(json) as Record<string, string>;
93+
for (const key in parsedHeaders) {
94+
headers[key] = parsedHeaders[key].split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/).map(value => value.trim());
95+
}
96+
97+
requestInfo.headers = headers;
98+
}
99+
}
100+
77101
if (config.includeQueryString) {
78102
const json = stringify(request.params, exclusions);
79103
if (!isEmpty(json)) {

0 commit comments

Comments
 (0)