Skip to content

Commit

Permalink
feat: add dynamicHeaders, closes #151 (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
KiaraGrouwstra authored and emoralesb05 committed Nov 18, 2016
1 parent 5d87249 commit 3130186
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/platform/http/http-rest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface IRestTransform {

export interface IRestConfig {
baseHeaders?: Headers;
dynamicHeaders?: () => Headers;
baseUrl: string;
path?: string;
transform?: IRestTransform;
Expand All @@ -32,6 +33,7 @@ export abstract class RESTService<T> {
private _path: string;
private _base: string;
private _baseHeaders: Headers;
private _dynamicHeaders: () => Headers;

protected transform: IRestTransform;
protected http: IHttp;
Expand All @@ -41,6 +43,7 @@ export abstract class RESTService<T> {
this._base = config.baseUrl.replace(/\/$/, '');
this._path = config.path.replace(/^\//, '');
this._baseHeaders = config.baseHeaders ? config.baseHeaders : new Headers();
this._dynamicHeaders = config.dynamicHeaders ? config.dynamicHeaders : () => new Headers();
this.transform = config.transform ? config.transform : (response: Response): any => response.json();
}

Expand Down Expand Up @@ -138,6 +141,9 @@ export abstract class RESTService<T> {
this._baseHeaders.forEach((value: string[], key: string) => {
requestHeaders.set(key, value);
});
this._dynamicHeaders().forEach((value: string[], key: string) => {
requestHeaders.set(key, value);
});
let requestOptions: RequestOptionsArgs = {
headers: requestHeaders,
};
Expand Down

0 comments on commit 3130186

Please sign in to comment.