var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Injectable } from '@angular/core';
import { AbstractAppConfig } from '../../../app.config';
var HeadersSanitisingInterceptor = /** @class */ (function () {
    function HeadersSanitisingInterceptor(appConfig) {
        this.appConfig = appConfig;
    }
    HeadersSanitisingInterceptor_1 = HeadersSanitisingInterceptor;
    HeadersSanitisingInterceptor.prototype.intercept = function (request, next) {
        return next.handle(this.sanitise(request));
    };
    HeadersSanitisingInterceptor.prototype.sanitise = function (request) {
        var finalHeaders = request.headers;
        if (!finalHeaders.has(HeadersSanitisingInterceptor_1.HEADER_ACCEPT)) {
            finalHeaders = finalHeaders.set(HeadersSanitisingInterceptor_1.HEADER_ACCEPT, 'application/json');
        }
        if (this.doSetContentTypeHeader(finalHeaders, request)) {
            finalHeaders = finalHeaders.set(HeadersSanitisingInterceptor_1.HEADER_CONTENT_TYPE, 'application/json');
        }
        // Clone immutable request with sanitised headers
        return request.clone({
            headers: finalHeaders
        });
    };
    HeadersSanitisingInterceptor.prototype.doSetContentTypeHeader = function (finalHeaders, request) {
        return !(finalHeaders.has(HeadersSanitisingInterceptor_1.HEADER_CONTENT_TYPE) || this.isDocumentStorePut(request));
    };
    HeadersSanitisingInterceptor.prototype.isDocumentStorePut = function (request) {
        return request.url.startsWith(this.appConfig.getDocumentStoreUrl()) && request.method === 'PUT';
    };
    var HeadersSanitisingInterceptor_1;
    HeadersSanitisingInterceptor.HEADER_ACCEPT = 'Accept';
    HeadersSanitisingInterceptor.HEADER_CONTENT_TYPE = 'Content-Type';
    HeadersSanitisingInterceptor = HeadersSanitisingInterceptor_1 = __decorate([
        Injectable(),
        __metadata("design:paramtypes", [AbstractAppConfig])
    ], HeadersSanitisingInterceptor);
    return HeadersSanitisingInterceptor;
}());
export { HeadersSanitisingInterceptor };
//# sourceMappingURL=headers-sanitising.interceptor.js.map