@@ -131,28 +131,21 @@ async function runTests() {
131131 buf = Buffer . concat ( [ buf , chunk ] )
132132
133133 while ( true ) {
134- const hdrEnd = buf . indexOf ( '\r\n\r\n' )
135- if ( hdrEnd === - 1 ) break
136- const hdr = buf . slice ( 0 , hdrEnd ) . toString ( 'ascii' )
137- const m = hdr . match ( / C o n t e n t - L e n g t h : \s * ( \d + ) / i)
138- if ( ! m ) { buf = buf . slice ( hdrEnd + 4 ) ; continue }
139- const len = parseInt ( m [ 1 ] , 10 )
140- const bodyStart = hdrEnd + 4
141- if ( buf . length < bodyStart + len ) break
142- const body = buf . slice ( bodyStart , bodyStart + len ) . toString ( 'utf8' )
143- buf = buf . slice ( bodyStart + len )
134+ const nl = buf . indexOf ( 0x0a )
135+ if ( nl === - 1 ) break
136+ const line = buf . slice ( 0 , nl ) . toString ( 'utf8' ) . trim ( )
137+ buf = buf . slice ( nl + 1 )
138+ if ( ! line ) continue
144139 try {
145- const obj = JSON . parse ( body )
140+ const obj = JSON . parse ( line )
146141 if ( obj . id != null ) responses . set ( obj . id , obj )
147142 } catch { /* skip */ }
148143 }
149144 } )
150145
151146 function sendMsg ( id : number , method : string , params ?: Record < string , unknown > ) {
152147 const obj = { jsonrpc : '2.0' , id, method, params : params || { } }
153- const body = Buffer . from ( JSON . stringify ( obj ) , 'utf8' )
154- const header = Buffer . from ( `Content-Length: ${ body . length } \r\n\r\n` , 'ascii' )
155- child . stdin . write ( Buffer . concat ( [ header , body ] ) )
148+ child . stdin . write ( JSON . stringify ( obj ) + '\n' )
156149 }
157150
158151 // Wait for server to start
0 commit comments