From 77e0562f5040f2621ecc6574c01e6cc601d7d6c3 Mon Sep 17 00:00:00 2001 From: Taka Cho Date: Fri, 2 Aug 2019 13:39:15 -0400 Subject: fix duplicate authorization header Authorization Basic YWRtaW46YWRtaW4= will not be duplicated and cached Issue-ID: APPC-1676 Change-Id: I9858e72c1b0158791d11c301d9c118a422b3e0b6 Signed-off-by: Taka Cho --- src/app/shared/services/httpUtil/http-util.service.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/app/shared/services/httpUtil/http-util.service.ts b/src/app/shared/services/httpUtil/http-util.service.ts index 688f3ea..fc9c327 100644 --- a/src/app/shared/services/httpUtil/http-util.service.ts +++ b/src/app/shared/services/httpUtil/http-util.service.ts @@ -26,23 +26,28 @@ import { Http, Response, Headers, RequestOptions } from '@angular/http'; @Injectable() export class HttpUtilService { - headers: Headers; + headersGET: Headers; + headersPOST: Headers; options: RequestOptions private username = require('../../../../cdt.application.properties.json').username; private password = require('../../../../cdt.application.properties.json').password; constructor(private http: Http) { - this.headers = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON + this.headersGET = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON + this.headersPOST = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON + this.headersPOST.append('Authorization', 'Basic ' + btoa(this.username + ':' + this.password)); } get(req) { + this.options = new RequestOptions({ headers: this.headersGET }); + return this .http .get(req.url, this.options) .map((res: Response) => res.json()) } post(req) { - this.headers.append('Authorization', 'Basic ' + btoa(this.username + ':' + this.password)); - this.options = new RequestOptions({ headers: this.headers }); + + this.options = new RequestOptions({ headers: this.headersPOST }); return this .http @@ -50,4 +55,4 @@ export class HttpUtilService { .map((res: Response) => res.json()) } -} \ No newline at end of file +} -- cgit 1.2.3-korg