From 135eacb07dbf7e1ca11af9cebf5390028b182e37 Mon Sep 17 00:00:00 2001 From: Bohdanko <32868658+77bo@users.noreply.github.com> Date: Sat, 9 Dec 2017 23:39:41 +0200 Subject: [PATCH] #400 exposed only response headers, instead of whole XMLHttpRequest object. --- src/ngx-uploader/classes/interfaces.ts | 2 +- src/ngx-uploader/classes/ngx-uploader.class.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ngx-uploader/classes/interfaces.ts b/src/ngx-uploader/classes/interfaces.ts index dccb48a4..bdf718ac 100644 --- a/src/ngx-uploader/classes/interfaces.ts +++ b/src/ngx-uploader/classes/interfaces.ts @@ -42,7 +42,7 @@ export interface UploadFile { responseStatus?: number; sub?: Subscription | any; nativeFile?: File; - rawRequest?: XMLHttpRequest; + headers?: { [key: string]: string }; } export interface UploadOutput { diff --git a/src/ngx-uploader/classes/ngx-uploader.class.ts b/src/ngx-uploader/classes/ngx-uploader.class.ts index 096ff438..1a77df1c 100644 --- a/src/ngx-uploader/classes/ngx-uploader.class.ts +++ b/src/ngx-uploader/classes/ngx-uploader.class.ts @@ -205,7 +205,7 @@ export class NgUploaderService { file.response = xhr.response; } - file.rawRequest = xhr; + file.headers = this.parseResponseHeaders(xhr.getAllResponseHeaders()); observer.next({ type: 'done', file: file }); @@ -297,4 +297,14 @@ export class NgUploaderService { nativeFile: file }; } + + private parseResponseHeaders(httpHeaders: ByteString) { + return httpHeaders.split('\n') + .map(x => x.split(/: */, 2)) + .filter(x => x[0]) + .reduce((ac, x) => { + ac[x[0]] = x[1]; + return ac; + }, {}); + } }