import { Plugin , CoreSetup } from 'opensearch-dashboards/server' ; import { schema } from '@osd/config-schema' ; export interface PluginARequestContext { ping : ( ) => Promise < string > ; } declare module 'opensearch-dashboards/server' { interface RequestHandlerContext { pluginA ? : PluginARequestContext ; } } export class CorePluginRouteTimeoutsPlugin implements Plugin { public setup ( core , deps ) { const { http } = core ; const router = http . createRouter ( ) ; router . post ( { options : { body : { accepts : [ 'application/json' ] , } , timeout : { payload : 100 } , } , path : '/short_payload_timeout' , validate : false , } , async ( context , req , res ) => { return res . ok ( { } ) ; } ) ; router . post ( { options : { body : { accepts : [ 'application/json' ] , } , timeout : { payload : 10000 } , } , path : '/longer_payload_timeout' , validate : false , } , async ( context , req , res ) => { return res . ok ( { } ) ; } ) ; router . post ( { options : { body : { accepts : [ 'application/json' ] , } , timeout : { idleSocket : 10 } , } , path : '/short_idle_socket_timeout' , validate : { body : schema . maybe ( schema . object ( { responseDelay : schema . maybe ( schema . number ( ) ) , } ) ) , } , } , async ( context , req , res ) => { if ( req . body ?. responseDelay ) { await new Promise ( ( resolve ) => setTimeout ( resolve , req . body ! . responseDelay ) ) ; } return res . ok ( { } ) ; } ) ; router . post ( { options : { body : { accepts : [ 'application/json' ] , } , timeout : { idleSocket : 5000 } , } , path : '/longer_idle_socket_timeout' , validate : { body : schema . maybe ( schema . object ( { responseDelay : schema . maybe ( schema . number ( ) ) , } ) ) , } , } , async ( context , req , res ) => { if ( req . body ?. responseDelay ) { await new Promise ( ( resolve ) => setTimeout ( resolve , req . body ! . responseDelay ) ) ; } return res . ok ( { } ) ; } ) ; } public start ( ) { } public stop ( ) { } }