@@ -21,6 +21,7 @@ import { logger } from "../../core/Logger.js";
21
21
import { getRequestHeader , setResponseHeaders } from "../../utils/headers.js" ;
22
22
import { DEFAULT_CORS_CONFIG } from "../sse/types.js" ;
23
23
import { CORSConfig } from "../sse/types.js" ;
24
+ import { PING_SSE_MESSAGE } from "../utils/ping-message.js" ;
24
25
25
26
function isRequest ( msg : JsonRpcMessage ) : msg is JsonRpcRequest {
26
27
return msg &&
@@ -185,14 +186,15 @@ export class HttpStreamTransport extends AbstractTransport {
185
186
case "POST" : await this . handlePost ( req , res ) ; break ;
186
187
case "GET" : await this . handleGet ( req , res ) ; break ;
187
188
case "DELETE" : await this . handleDelete ( req , res ) ; break ;
188
- default :
189
- const allowHeader = this . _config . enableGetSse ?
190
- 'GET, POST, DELETE, OPTIONS' :
189
+ default : { // Add block scope for the default case
190
+ const allowHeader = this . _config . enableGetSse ?
191
+ 'GET, POST, DELETE, OPTIONS' :
191
192
'POST, DELETE, OPTIONS' ;
192
- res . writeHead ( 405 , { 'Content-Type' : 'text/plain' , 'Allow' : allowHeader } ) ;
193
+ res . writeHead ( 405 , { 'Content-Type' : 'text/plain' , 'Allow' : allowHeader } ) ;
193
194
res . end ( "Method Not Allowed" ) ;
194
- logger . warn ( `Unsupported method: ${ req . method } ` ) ;
195
+ logger . warn ( `Unsupported method: ${ req . method } ` ) ;
195
196
break ;
197
+ } // Close block scope
196
198
}
197
199
} catch ( error : any ) {
198
200
logger . error ( `Error processing ${ req . method } ${ url . pathname } : ${ error . message } ` ) ;
@@ -481,7 +483,6 @@ export class HttpStreamTransport extends AbstractTransport {
481
483
if ( res . socket ) { res . socket . setNoDelay ( true ) ; res . socket . setKeepAlive ( true ) ; res . socket . setTimeout ( 0 ) ; logger . debug ( `Optimized socket for SSE stream ${ streamId } ` ) ; }
482
484
else { logger . warn ( `Could not access socket for SSE stream ${ streamId } to optimize.` ) ; }
483
485
this . _activeSseConnections . add ( connection ) ;
484
- res . write ( ': stream opened\n\n' ) ;
485
486
connection . pingInterval = setInterval ( ( ) => this . sendPing ( connection ) , 15000 ) ;
486
487
if ( lastEventId && this . _config . resumability . enabled ) {
487
488
this . handleResumption ( connection , lastEventId , sessionId ) . catch ( err => { logger . error ( `Error during stream resumption for ${ streamId } : ${ err . message } ` ) ; this . cleanupConnection ( connection , `Resumption error: ${ err . message } ` ) ; } ) ;
@@ -646,7 +647,7 @@ export class HttpStreamTransport extends AbstractTransport {
646
647
private sendPing ( connection : ActiveSseConnection ) : void {
647
648
if ( ! connection || ! connection . res || connection . res . writableEnded ) return ;
648
649
try {
649
- connection . res . write ( ': keep-alive\n\n' ) ;
650
+ connection . res . write ( PING_SSE_MESSAGE ) ;
650
651
logger . debug ( `Sent keep-alive ping to stream ${ connection . streamId } ` ) ;
651
652
} catch ( error : any ) {
652
653
logger . error ( `Error sending ping to stream ${ connection . streamId } : ${ error . message } ` ) ;
0 commit comments