import { Observable } from 'rxjs' ; import { take } from 'rxjs/operators' ; import { OnPreResponseHandler } from '../../../../src/core/server' ; import { ILicense } from '../common/types' ; export function createOnPreResponseHandler ( refresh , license$ ) { return async ( req , res , t ) => { if ( res . statusCode >= 400 && res . statusCode !== 429 ) { await refresh ( ) ; } const license = await license$ . pipe ( take ( 1 ) ) . toPromise ( ) ; return t . next ( { headers : { 'kbn-license-sig' : license . signature , } , } ) ; } ; }