Skip to content

Commit 2a6b0e6

Browse files
author
Thom van Kalkeren
committed
Allow partial requestinitopts
1 parent 6ae591b commit 2a6b0e6

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/processor/RequestInitGenerator.ts

+5-10
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@ export class RequestInitGenerator {
1313
public readonly mode: "same-origin" | "navigate" | "no-cors" | "cors" | undefined;
1414
public readonly xRequestedWith: string;
1515

16-
constructor(opts: RequestInitGeneratorOpts = {
17-
credentials: "include",
18-
csrfFieldName: "csrf-token",
19-
mode: "same-origin",
20-
xRequestedWith: "XMLHttpRequest",
21-
}) {
16+
constructor(opts: Partial<RequestInitGeneratorOpts> = {}) {
2217
this.baseHeaders = opts.headers || {};
23-
this.csrfFieldName = opts.csrfFieldName;
24-
this.credentials = opts.credentials;
25-
this.mode = opts.mode;
26-
this.xRequestedWith = opts.xRequestedWith;
18+
this.csrfFieldName = opts.csrfFieldName ?? "csrf-token";
19+
this.credentials = opts.credentials ?? "include";
20+
this.mode = opts.mode ?? "same-origin";
21+
this.xRequestedWith = opts.xRequestedWith ?? "XMLHttpRequest";
2722
}
2823

2924
public authenticityHeader(options = {}): Record<string, string> {

0 commit comments

Comments
 (0)