fetch-addons
Version:
A collection of addons for the fetch API
20 lines (19 loc) • 858 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.deleteEmptyHeaders = deleteEmptyHeaders;
exports.getHeaders = getHeaders;
const request_js_1 = require("./request.js");
function deleteEmptyHeaders(headers) {
// Can't do it in the headers.forEach loop, see https://twitter.com/meijer_s/status/1676506116736397312
for (const [key, value] of [...headers]) {
if (value && value !== 'undefined' && value !== 'null')
continue;
headers.delete(key);
}
}
function getHeaders(headersOrInput, init) {
if (typeof headersOrInput === 'string' || headersOrInput instanceof URL || headersOrInput instanceof Request) {
return (0, request_js_1.getRequest)(headersOrInput, init).headers;
}
return headersOrInput instanceof Headers ? headersOrInput : new Headers(headersOrInput);
}
;