UNPKG

fetch-addons

Version:

A collection of addons for the fetch API

16 lines (15 loc) 692 B
import { getRequest } from './request.js'; export 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); } } export function getHeaders(headersOrInput, init) { if (typeof headersOrInput === 'string' || headersOrInput instanceof URL || headersOrInput instanceof Request) { return getRequest(headersOrInput, init).headers; } return headersOrInput instanceof Headers ? headersOrInput : new Headers(headersOrInput); }