ng-jhipster
Version:
A Jhipster util library for Angular 2
64 lines (63 loc) • 2.91 kB
JavaScript
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
import { Injectable } from '@angular/core';
import { Http, ConnectionBackend, RequestOptions, Headers } from '@angular/http';
export var HttpInterceptor = (function (_super) {
__extends(HttpInterceptor, _super);
function HttpInterceptor(backend, defaultOptions, interceptors) {
_super.call(this, backend, defaultOptions);
/**
* building a responsibility chain of http interceptables, so when processXXXInterception is called on first interceptor,
* all http interceptables are called in a row
* Note: the array of interceptors are wired in customHttpProvider of the generated Jhipster app in file `http.provider.ts`
*
*/
if (interceptors.length > 0) {
interceptors.reduce(function (chain, current) {
chain.successor = current;
return current;
});
this.firstInterceptor = interceptors[0];
}
}
HttpInterceptor.prototype.request = function (url, options) {
return this.intercept(_super.prototype.request.call(this, url, this.getRequestOptionArgs(options)));
};
HttpInterceptor.prototype.get = function (url, options) {
return _super.prototype.get.call(this, url, this.getRequestOptionArgs(options));
};
HttpInterceptor.prototype.post = function (url, body, options) {
return _super.prototype.post.call(this, url, body, this.getRequestOptionArgs(options));
};
HttpInterceptor.prototype.put = function (url, body, options) {
return _super.prototype.put.call(this, url, body, this.getRequestOptionArgs(options));
};
HttpInterceptor.prototype.delete = function (url, options) {
return _super.prototype.delete.call(this, url, this.getRequestOptionArgs(options));
};
HttpInterceptor.prototype.getRequestOptionArgs = function (options) {
if (options == null) {
options = new RequestOptions();
}
if (options.headers == null) {
options.headers = new Headers();
}
return !this.firstInterceptor ? options : this.firstInterceptor.processRequestInterception(options);
};
HttpInterceptor.prototype.intercept = function (observable) {
return !this.firstInterceptor ? observable : this.firstInterceptor.processResponseInterception(observable);
};
HttpInterceptor.decorators = [
{ type: Injectable },
];
/** @nocollapse */
HttpInterceptor.ctorParameters = function () { return [
{ type: ConnectionBackend, },
{ type: RequestOptions, },
{ type: Array, },
]; };
return HttpInterceptor;
}(Http));