angular-interceptors
Version:
Useful interceptors for [Angular](https://github.com/angular/angular)
3 lines (2 loc) • 2.66 kB
JavaScript
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@angular/common/http"),require("@angular/core"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("angular-interceptors",["exports","@angular/common/http","@angular/core","rxjs","rxjs/operators"],r):r(e["angular-interceptors"]={},e.ng.common.http,e.ng.core,null,e.Rx.Observable.prototype)}(this,function(e,r,t,n,o){"use strict";var u=new t.InjectionToken("maxAgeMs"),i=function(){function e(e){this.maxAgeMs=e,this.cache=new Map}return e.prototype.intercept=function(e,r){var t=this;if(!this.isCachable(e))return r.handle(e);var u=this.cache.get(e.urlWithParams);if(u)return u;var i=r.handle(e).pipe(o.finalize(function(){return n.interval(t.maxAgeMs).pipe(o.take(1)).subscribe(function(){return t.cache["delete"](e.urlWithParams)})}),o.publishReplay(),o.refCount(),o.catchError(function(e){return n.throwError(e)}));return this.cache.set(e.urlWithParams,i),i},e.prototype.isCachable=function(e){return"GET"===e.method&&!e.headers.get("disable-cache")},e}();i.decorators=[{type:t.Injectable}],i.ctorParameters=function(){return[{type:undefined,decorators:[{type:t.Inject,args:[u]},{type:t.Optional}]}]};var a={provide:r.HTTP_INTERCEPTORS,useClass:i,multi:!0},c=function(){function e(){}return e.forRoot=function(r){return void 0===r&&(r=5e3),{ngModule:e,providers:[a,{provide:u,useValue:r}]}},e}();c.decorators=[{type:t.NgModule}];var s=function(){function e(){this.cache=new Map}return e.prototype.intercept=function(e,r){return r.handle(e.clone({url:e.url.replace("http://","https://")}))},e}();s.decorators=[{type:t.Injectable}],s.ctorParameters=function(){return[]};var p={provide:r.HTTP_INTERCEPTORS,useClass:s,multi:!0},l=function(){function e(){}return e.forRoot=function(){return{ngModule:e,providers:[p]}},e}();l.decorators=[{type:t.NgModule}];var f=new t.InjectionToken("prefix"),d=function(){function e(e){this.prefix=e}return e.prototype.intercept=function(e,r){return r.handle(e.clone({url:this.prefix+e.url}))},e}();d.decorators=[{type:t.Injectable}],d.ctorParameters=function(){return[{type:undefined,decorators:[{type:t.Inject,args:[f]}]}]};var h={provide:r.HTTP_INTERCEPTORS,useClass:d,multi:!0},g=function(){function e(){}return e.forRoot=function(r){return{ngModule:e,providers:[h,{provide:f,useValue:r}]}},e}();g.decorators=[{type:t.NgModule}],e.CacheInterceptorModule=c,e.MAX_AGE_MS=u,e.EnsureHttpsInterceptorModule=l,e.PREFIX=f,e.PrefixUrlInterceptorModule=g,e.ɵb=a,e.ɵa=i,e.ɵf=p,e.ɵe=s,e.ɵd=h,e.ɵc=d,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=angular-interceptors.umd.min.js.map