export function rawHeadersToHeaders ( rawHeaders ) { return rawHeaders . reduce ( ( result , next , i ) => { if ( i % 2 === 0 ) { const existingValue = result [ next ] ; if ( typeof existingValue === 'string' ) { result [ next ] = [ existingValue ] ; } } else { const key = rawHeaders [ i - 1 ] ; const existingValue = result [ key ] ; if ( Array . isArray ( existingValue ) ) { existingValue . push ( next ) ; } else { result [ key ] = next ; } } return result ; } , { } as { [ key ] : string | string [ ] | undefined ; } ) ; }