Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reduce the size of the compiled output
Browse files Browse the repository at this point in the history
jkalis-rm committed Feb 19, 2020
1 parent 6030c87 commit 673f183
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/index.mjs
Original file line number Diff line number Diff line change
@@ -10,13 +10,13 @@ export default function(url, options) {
request.open(options.method || 'get', url, true);

request.onload = () => {
const head = { all: [], keys: [], raw: {} };
const all = [], keys = [], raw = {};
request.getAllResponseHeaders().replace(regex, (m, key, value) => {
head.all.push([key, value]);
head.keys.push(key = key.toLowerCase());
head.raw[key] = head.raw[key] ? `${head.raw[key]},${value}` : value;
all.push([key, value]);
keys.push(key = key.toLowerCase());
raw[key] = raw[key] ? `${raw[key]},${value}` : value;
});
resolve(response(request, head));
resolve(response(request, all, keys, raw));
};

request.onerror = reject;
12 changes: 6 additions & 6 deletions src/lib/response.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function response (request, headers) {
export default function response (request, all, keys, raw) {
return {
ok: (request.status/100|0) == 2, // 200-299
statusText: request.statusText,
@@ -7,12 +7,12 @@ export default function response (request, headers) {
text: () => Promise.resolve(request.responseText),
json: () => Promise.resolve(request.responseText).then(JSON.parse),
blob: () => Promise.resolve(new Blob([request.response])),
clone: () => response(request, headers),
clone: () => response(request, all, keys, raw),
headers: {
keys: () => headers.keys,
entries: () => headers.all,
get: n => headers.raw[n.toLowerCase()],
has: n => n.toLowerCase() in headers.raw
keys: () => keys,
entries: () => all,
get: n => raw[n.toLowerCase()],
has: n => n.toLowerCase() in raw
}
};
}

0 comments on commit 673f183

Please sign in to comment.