Skip to content

Commit

Permalink
#400 exposed only response headers, instead of whole XMLHttpRequest o…
Browse files Browse the repository at this point in the history
…bject.
  • Loading branch information
77bo committed Dec 9, 2017
1 parent b62d570 commit 135eacb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ngx-uploader/classes/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface UploadFile {
responseStatus?: number;
sub?: Subscription | any;
nativeFile?: File;
rawRequest?: XMLHttpRequest;
headers?: { [key: string]: string };
}

export interface UploadOutput {
Expand Down
12 changes: 11 additions & 1 deletion src/ngx-uploader/classes/ngx-uploader.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down Expand Up @@ -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;
}, {});
}
}

0 comments on commit 135eacb

Please sign in to comment.