typescript-fetch: allow configuration of headers and credentials (#3586)

* Fix #3402 by giving the possibility to set additional headers and the credentials parameters to the fetch query.

* Fix #3402 : Changes from code review
This commit is contained in:
Jean-François Côté 2019-08-08 08:48:45 -04:00 committed by Esteban Gehring
parent 7f36f26422
commit b28ef78145
6 changed files with 84 additions and 6 deletions

View File

@ -52,10 +52,13 @@ export class BaseAPI {
const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
: JSON.stringify(context.body);
const headers = Object.assign({}, this.configuration.headers, context.headers);
const init = {
method: context.method,
headers: context.headers,
headers: headers,
body,
credentials: this.configuration.credentials
};
return { url, init };
}
@ -121,6 +124,8 @@ export interface ConfigurationParameters {
password?: string; // parameter for basic security
apiKey?: string | ((name: string) => string); // parameter for apiKey security
accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security
headers?: HTTPHeaders; //header params we want to use on every request
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
}
export class Configuration {
@ -165,6 +170,14 @@ export class Configuration {
}
return undefined;
}
get headers(): HTTPHeaders {
return this.configuration.headers;
}
get credentials(): RequestCredentials {
return this.configuration.credentials;
}
}
export type Json = any;

View File

@ -63,10 +63,13 @@ export class BaseAPI {
const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
: JSON.stringify(context.body);
const headers = Object.assign({}, this.configuration.headers, context.headers);
const init = {
method: context.method,
headers: context.headers,
headers: headers,
body,
credentials: this.configuration.credentials
};
return { url, init };
}
@ -132,6 +135,8 @@ export interface ConfigurationParameters {
password?: string; // parameter for basic security
apiKey?: string | ((name: string) => string); // parameter for apiKey security
accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security
headers?: HTTPHeaders; //header params we want to use on every request
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
}
export class Configuration {
@ -176,6 +181,14 @@ export class Configuration {
}
return undefined;
}
get headers(): HTTPHeaders {
return this.configuration.headers;
}
get credentials(): RequestCredentials {
return this.configuration.credentials;
}
}
export type Json = any;

View File

@ -63,10 +63,13 @@ export class BaseAPI {
const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
: JSON.stringify(context.body);
const headers = Object.assign({}, this.configuration.headers, context.headers);
const init = {
method: context.method,
headers: context.headers,
headers: headers,
body,
credentials: this.configuration.credentials
};
return { url, init };
}
@ -132,6 +135,8 @@ export interface ConfigurationParameters {
password?: string; // parameter for basic security
apiKey?: string | ((name: string) => string); // parameter for apiKey security
accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security
headers?: HTTPHeaders; //header params we want to use on every request
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
}
export class Configuration {
@ -176,6 +181,14 @@ export class Configuration {
}
return undefined;
}
get headers(): HTTPHeaders {
return this.configuration.headers;
}
get credentials(): RequestCredentials {
return this.configuration.credentials;
}
}
export type Json = any;

View File

@ -63,10 +63,13 @@ export class BaseAPI {
const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
: JSON.stringify(context.body);
const headers = Object.assign({}, this.configuration.headers, context.headers);
const init = {
method: context.method,
headers: context.headers,
headers: headers,
body,
credentials: this.configuration.credentials
};
return { url, init };
}
@ -132,6 +135,8 @@ export interface ConfigurationParameters {
password?: string; // parameter for basic security
apiKey?: string | ((name: string) => string); // parameter for apiKey security
accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security
headers?: HTTPHeaders; //header params we want to use on every request
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
}
export class Configuration {
@ -176,6 +181,14 @@ export class Configuration {
}
return undefined;
}
get headers(): HTTPHeaders {
return this.configuration.headers;
}
get credentials(): RequestCredentials {
return this.configuration.credentials;
}
}
export type Json = any;

View File

@ -63,10 +63,13 @@ export class BaseAPI {
const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
: JSON.stringify(context.body);
const headers = Object.assign({}, this.configuration.headers, context.headers);
const init = {
method: context.method,
headers: context.headers,
headers: headers,
body,
credentials: this.configuration.credentials
};
return { url, init };
}
@ -132,6 +135,8 @@ export interface ConfigurationParameters {
password?: string; // parameter for basic security
apiKey?: string | ((name: string) => string); // parameter for apiKey security
accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security
headers?: HTTPHeaders; //header params we want to use on every request
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
}
export class Configuration {
@ -176,6 +181,14 @@ export class Configuration {
}
return undefined;
}
get headers(): HTTPHeaders {
return this.configuration.headers;
}
get credentials(): RequestCredentials {
return this.configuration.credentials;
}
}
export type Json = any;

View File

@ -63,10 +63,13 @@ export class BaseAPI {
const body = (context.body instanceof FormData || isBlob(context.body))
? context.body
: JSON.stringify(context.body);
const headers = Object.assign({}, this.configuration.headers, context.headers);
const init = {
method: context.method,
headers: context.headers,
headers: headers,
body,
credentials: this.configuration.credentials
};
return { url, init };
}
@ -132,6 +135,8 @@ export interface ConfigurationParameters {
password?: string; // parameter for basic security
apiKey?: string | ((name: string) => string); // parameter for apiKey security
accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security
headers?: HTTPHeaders; //header params we want to use on every request
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
}
export class Configuration {
@ -176,6 +181,14 @@ export class Configuration {
}
return undefined;
}
get headers(): HTTPHeaders {
return this.configuration.headers;
}
get credentials(): RequestCredentials {
return this.configuration.credentials;
}
}
export type Json = any;