Skip to content

Commit

Permalink
refactor: Move away from Object.fromEntries
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed Feb 26, 2021
1 parent 54be1e9 commit e5dcb0d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/internal/ajax/AjaxResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ export class AjaxResponse<T> {
// other-header-here: some, other, values, or, whatever
const allHeaders = xhr.getAllResponseHeaders();
this.responseHeaders = allHeaders
? Object.fromEntries(
// Split the header text into lines
allHeaders.split('\n').map((line) => {
// Split the lines on the first ": ". The value could technically have a ": " in it.
const index = line.indexOf(': ');
return [line.slice(0, index), line.slice(index + 2)];
})
)
? // Split the header text into lines
allHeaders.split('\n').reduce((headers: Record<string, string>, line) => {
// Split the lines on the first ": " as
// "key: value". Note that the value could
// technically have a ": " in it.
const index = line.indexOf(': ');
headers[line.slice(0, index)] = line.slice(index + 2);
return headers;
}, {})
: {};

this.response = getXHRResponse(xhr);
Expand Down

0 comments on commit e5dcb0d

Please sign in to comment.