Skip to content

Added support for headers #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/browser/src/plugins/BrowserRequestInfoPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export class BrowserRequestInfoPlugin implements IEventPlugin {
port: location.port && location.port !== ""
? parseInt(location.port, 10)
: 80,
path: location.pathname,
// client_ip_address: "TODO"
path: location.pathname
};

if (config.includeCookies) {
Expand All @@ -53,7 +52,7 @@ export class BrowserRequestInfoPlugin implements IEventPlugin {
if (config.includeQueryString) {
requestInfo.query_string = parseQueryString(
location.search.substring(1),
exclusions,
exclusions
);
}

Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/configuration/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class Configuration {
private _includeUserName = true;
private _includeMachineName = true;
private _includeIpAddress = true;
private _includeHeaders = true;
private _includeCookies = true;
private _includePostData = true;
private _includeQueryString = true;
Expand Down Expand Up @@ -212,6 +213,7 @@ export class Configuration {
this._includeUserName = val;
this._includeMachineName = val;
this._includeIpAddress = val;
this._includeHeaders = val;
this._includeCookies = val;
this._includePostData = val;
this._includeQueryString = val;
Expand Down Expand Up @@ -259,6 +261,22 @@ export class Configuration {
this._includeIpAddress = value === true;
}

/**
* Gets a value indicating whether to include Headers.
* NOTE: DataExclusions are applied to all Header keys when enabled.
*/
public get includeHeaders(): boolean {
return this._includeHeaders;
}

/**
* Sets a value indicating whether to include Headers.
* NOTE: DataExclusions are applied to all Headers keys when enabled.
*/
public set includeHeaders(value: boolean) {
this._includeHeaders = value === true;
}

/**
* Gets a value indicating whether to include Cookies.
* NOTE: DataExclusions are applied to all Cookie keys when enabled.
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/models/data/RequestInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface RequestInfo {
path?: string;
referrer?: string;
client_ip_address?: string;
headers?: Record<string, string[]>;
cookies?: Record<string, string>;
post_data?: Record<string, unknown>;
query_string?: Record<string, string>;
Expand Down
24 changes: 24 additions & 0 deletions packages/node/src/plugins/NodeRequestInfoPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ export class NodeRequestInfoPlugin implements IEventPlugin {
requestInfo.cookies = getCookies(request.headers.cookie, exclusions) as Record<string, string>;
}

if (config.includeHeaders) {
const ignoredHeaders = [
"Authorization",
"Cookie",
"Host",
"Method",
"Path",
"Proxy-Authorization",
"Referer",
"User-Agent"
];

const json = stringify(request.headers, [...ignoredHeaders, ...exclusions]);
if (!isEmpty(json)) {
const headers: Record<string, string[]> = {};
const parsedHeaders = JSON.parse(json) as Record<string, string>;
for (const key in parsedHeaders) {
headers[key] = parsedHeaders[key].split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/).map(value => value.trim());
}

requestInfo.headers = headers;
}
}

if (config.includeQueryString) {
const json = stringify(request.params, exclusions);
if (!isEmpty(json)) {
Expand Down