Skip to content

Commit 07cf478

Browse files
ThatTobMatekamilogorek
authored andcommitted
feat: Add cookies as an optional property in the request handler
1 parent 380a6ae commit 07cf478

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

packages/node/src/handlers.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function extractTransaction(req: { [key: string]: any }, type: boolean | Transac
2626
stack: [
2727
{
2828
name: string;
29-
}
29+
},
3030
];
3131
};
3232
};
@@ -51,7 +51,7 @@ function extractTransaction(req: { [key: string]: any }, type: boolean | Transac
5151
}
5252

5353
/** JSDoc */
54-
function extractRequestData(req: { [key: string]: any }): { [key: string]: string } {
54+
function extractRequestData(req: { [key: string]: any }, keys: boolean | string[]): { [key: string]: string } {
5555
// headers:
5656
// node, express: req.headers
5757
// koa: req.header
@@ -112,6 +112,17 @@ function extractRequestData(req: { [key: string]: any }): { [key: string]: strin
112112
url: absoluteUrl,
113113
};
114114

115+
const attributes = Array.isArray(keys) ? keys : [];
116+
117+
if (attributes.length) {
118+
Object.keys(request).forEach(key => {
119+
/** Remove any of the unspecified keys in the options from the request interface */
120+
if (!attributes.includes(key)) {
121+
delete request[key];
122+
}
123+
});
124+
}
125+
115126
return request;
116127
}
117128

@@ -161,7 +172,7 @@ export function parseRequest(
161172
[key: string]: any;
162173
},
163174
options?: {
164-
request?: boolean;
175+
request?: boolean | string[];
165176
serverName?: boolean;
166177
transaction?: boolean | TransactionTypes;
167178
user?: boolean | string[];
@@ -188,7 +199,7 @@ export function parseRequest(
188199
if (options.request) {
189200
event.request = {
190201
...event.request,
191-
...extractRequestData(req),
202+
...extractRequestData(req, options.request),
192203
};
193204
}
194205

0 commit comments

Comments
 (0)