Filter undefined headers before creating the headers

This commit is contained in:
Ronald van der Horst 2021-06-23 09:09:04 +02:00
parent 411aeac828
commit 9e6528bc39
6 changed files with 59 additions and 12 deletions

View File

@ -1,6 +1,7 @@
import camelCase from 'camelcase';
const reservedWords = /^(arguments|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|eval|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)$/g;
const reservedWords =
/^(arguments|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|eval|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)$/g;
/**
* Replaces any invalid characters from a parameter name.

View File

@ -1,6 +1,7 @@
import camelCase from 'camelcase';
const reservedWords = /^(arguments|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|eval|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)$/g;
const reservedWords =
/^(arguments|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|eval|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)$/g;
/**
* Replaces any invalid characters from a parameter name.

View File

@ -4,11 +4,20 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
const password = await resolve(options, OpenAPI.PASSWORD);
const defaultHeaders = await resolve(options, OpenAPI.HEADERS);
const headers = new Headers({
const filteredHeaders = Object.entries({
Accept: 'application/json',
...defaultHeaders,
...options.headers,
});
}).reduce((acc, [headerKey, headerValue]) => {
if (typeof headerValue !== 'undefined') {
return {
...acc,
[headerKey]: headerValue,
};
}
return acc;
}, {});
const headers = new Headers(filteredHeaders);
if (isStringWithValue(token)) {
headers.append('Authorization', `Bearer ${token}`);

View File

@ -4,11 +4,20 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
const password = await resolve(options, OpenAPI.PASSWORD);
const defaultHeaders = await resolve(options, OpenAPI.HEADERS);
const headers = new Headers({
const filteredHeaders = Object.entries({
Accept: 'application/json',
...defaultHeaders,
...options.headers,
});
}).reduce((acc, [headerKey, headerValue]) => {
if (typeof headerValue !== 'undefined') {
return {
...acc,
[headerKey]: headerValue,
};
}
return acc;
}, {});
const headers = new Headers(filteredHeaders);
if (isStringWithValue(token)) {
headers.append('Authorization', `Bearer ${token}`);

View File

@ -4,11 +4,20 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
const password = await resolve(options, OpenAPI.PASSWORD);
const defaultHeaders = await resolve(options, OpenAPI.HEADERS);
const headers = new Headers({
const filteredHeaders = Object.entries({
Accept: 'application/json',
...defaultHeaders,
...options.headers,
});
}).reduce((acc, [headerKey, headerValue]) => {
if (typeof headerValue !== 'undefined') {
return {
...acc,
[headerKey]: headerValue,
};
}
return acc;
}, {});
const headers = new Headers(filteredHeaders);
if (isStringWithValue(token)) {
headers.append('Authorization', `Bearer ${token}`);

View File

@ -165,11 +165,20 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
const password = await resolve(options, OpenAPI.PASSWORD);
const defaultHeaders = await resolve(options, OpenAPI.HEADERS);
const headers = new Headers({
const filteredHeaders = Object.entries({
Accept: 'application/json',
...defaultHeaders,
...options.headers,
});
}).reduce((acc, [headerKey, headerValue]) => {
if (typeof headerValue !== 'undefined') {
return {
...acc,
[headerKey]: headerValue,
};
}
return acc;
}, {});
const headers = new Headers(filteredHeaders);
if (isStringWithValue(token)) {
headers.append('Authorization', \`Bearer \${token}\`);
@ -2518,11 +2527,20 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
const password = await resolve(options, OpenAPI.PASSWORD);
const defaultHeaders = await resolve(options, OpenAPI.HEADERS);
const headers = new Headers({
const filteredHeaders = Object.entries({
Accept: 'application/json',
...defaultHeaders,
...options.headers,
});
}).reduce((acc, [headerKey, headerValue]) => {
if (typeof headerValue !== 'undefined') {
return {
...acc,
[headerKey]: headerValue,
};
}
return acc;
}, {});
const headers = new Headers(filteredHeaders);
if (isStringWithValue(token)) {
headers.append('Authorization', \`Bearer \${token}\`);