import { MakeRequestResult } from '@tinkoff/request-core' ; import prop from '@tinkoff/utils/object/prop' ; import { PROTOCOL_HTTP } from './constants' ; const getSetCookieHeader = ( headers ) => { if ( typeof window === 'undefined' ) { return headers . raw ( ) [ 'set-cookie' ] ; } return [ ] ; } ; export const _getResponse = ( request ) : Response => { const meta = request . getInternalMeta ( PROTOCOL_HTTP ) ; return meta && meta . response ; } ; const _getHeaders = ( request ) => { return prop ( 'headers' , _getResponse ( request ) ) ; } ; export const getHeaders = ( request ) => { const headers = _getHeaders ( request ) ; const result = { } ; if ( headers ) { headers . forEach ( ( v , k ) => { if ( k === 'set-cookie' ) { result [ k ] = getSetCookieHeader ( headers ) ; } else { result [ k ] = v ; } } ) ; } return result ; } ; export const getHeader = ( request , header ) => { const headers = _getHeaders ( request ) ; if ( headers ) { if ( header === 'set-cookie' ) { return getSetCookieHeader ( headers ) ; } return headers . get ( header ) ; } } ; export const getStatus = ( request ) => { return prop ( 'status' , _getResponse ( request ) ) ; } ; export const abort = ( request ) => { const meta = request . getInternalMeta ( PROTOCOL_HTTP ) ; return meta && meta . requestAbort ( ) ; } ;