- Forgot to update snapshots

This commit is contained in:
Ferdi Koomen 2020-06-11 21:00:59 +02:00
parent 6565ed0f62
commit c051efaa30

View File

@ -71,6 +71,7 @@ interface Config {
BASE: string;
VERSION: string;
CLIENT: 'fetch' | 'xhr';
WITH_CREDENTIALS: boolean;
TOKEN: string;
}
@ -78,6 +79,7 @@ export const OpenAPI: Config = {
BASE: 'http://localhost:8080/api',
VERSION: '9.0',
CLIENT: 'fetch',
WITH_CREDENTIALS: false,
TOKEN: '',
};"
`;
@ -229,9 +231,15 @@ export async function request(options: Readonly<RequestOptions>): Promise<Result
const request: RequestInit = {
headers,
method: options.method,
credentials: 'same-origin',
};
// If we specified to send requests with credentials, then we
// set the request credentials options to include. This is only
// needed if you make cross-origin calls.
if (OpenAPI.WITH_CREDENTIALS) {
request.credentials = 'include';
}
// If we have a bearer token then we set the authentication header.
if (OpenAPI.TOKEN !== null && OpenAPI.TOKEN !== '') {
headers.append('Authorization', \`Bearer \${OpenAPI.TOKEN}\`);
@ -423,6 +431,11 @@ export async function requestUsingXHR(url: string, request: Readonly<RequestInit
// because the request needs to be initialized!
xhr.open(request.method!, url, true);
// When request credentials are set to include then this is
// the same behaviour as withCredentials = true in XHR:
// https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
xhr.withCredentials = request.credentials === 'include';
// Add the headers (required when dealing with JSON)
const headers = request.headers as Headers;
headers.forEach((value: string, key: string): void => {
@ -2706,6 +2719,7 @@ interface Config {
BASE: string;
VERSION: string;
CLIENT: 'fetch' | 'xhr';
WITH_CREDENTIALS: boolean;
TOKEN: string;
}
@ -2713,6 +2727,7 @@ export const OpenAPI: Config = {
BASE: '/api',
VERSION: '1',
CLIENT: 'fetch',
WITH_CREDENTIALS: false,
TOKEN: '',
};"
`;
@ -2864,9 +2879,15 @@ export async function request(options: Readonly<RequestOptions>): Promise<Result
const request: RequestInit = {
headers,
method: options.method,
credentials: 'same-origin',
};
// If we specified to send requests with credentials, then we
// set the request credentials options to include. This is only
// needed if you make cross-origin calls.
if (OpenAPI.WITH_CREDENTIALS) {
request.credentials = 'include';
}
// If we have a bearer token then we set the authentication header.
if (OpenAPI.TOKEN !== null && OpenAPI.TOKEN !== '') {
headers.append('Authorization', \`Bearer \${OpenAPI.TOKEN}\`);
@ -3058,6 +3079,11 @@ export async function requestUsingXHR(url: string, request: Readonly<RequestInit
// because the request needs to be initialized!
xhr.open(request.method!, url, true);
// When request credentials are set to include then this is
// the same behaviour as withCredentials = true in XHR:
// https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
xhr.withCredentials = request.credentials === 'include';
// Add the headers (required when dealing with JSON)
const headers = request.headers as Headers;
headers.forEach((value: string, key: string): void => {