@@ -205,23 +205,27 @@ describe('maskRequestHost option', () => {
205205 sandboxTest . skipIf ( isDebug ) (
206206 'verify maskRequestHost modifies Host header correctly' ,
207207 async ( { sandbox } ) => {
208- // Install netcat for testing
209- await sandbox . commands . run ( 'apt-get update' , { user : 'root' } )
210- await sandbox . commands . run ( 'apt-get install -y netcat-traditional' , {
211- user : 'root' ,
212- } )
213-
214208 const port = 8080
215- const outputFile = '/tmp/nc_output.txt'
216-
217- // Start netcat listener in background to capture request headers
218- sandbox . commands . run ( `nc -l -p ${ port } > ${ outputFile } ` , {
219- background : true ,
220- user : 'root' ,
221- } )
209+ const outputFile = '/tmp/headers.txt'
210+
211+ // Start a Python HTTP server that captures request headers and writes them to a file
212+ sandbox . commands . run (
213+ `python3 -c "
214+ import http.server
215+ class H(http.server.BaseHTTPRequestHandler):
216+ def do_GET(self):
217+ with open('${ outputFile } ', 'w') as f:
218+ for k, v in self.headers.items():
219+ f.write(k + ': ' + v + chr(10))
220+ self.send_response(200)
221+ self.end_headers()
222+ def log_message(self, *a): pass
223+ http.server.HTTPServer(('', ${ port } ), H).handle_request()
224+ "` ,
225+ { background : true }
226+ )
222227
223- // Wait for netcat to start
224- await new Promise ( ( resolve ) => setTimeout ( resolve , 3000 ) )
228+ await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) )
225229
226230 // Get the public URL for the sandbox
227231 const sandboxUrl = `https://${ sandbox . getHost ( port ) } `
@@ -231,13 +235,13 @@ describe('maskRequestHost option', () => {
231235 try {
232236 await fetch ( sandboxUrl , { signal : AbortSignal . timeout ( 5000 ) } )
233237 } catch ( error ) {
234- // Request may fail since netcat doesn't respond properly , but headers are captured
238+ // Request may timeout , but headers are captured by the server
235239 }
236240
237- // Read the captured output from inside the sandbox
238- const result = await sandbox . commands . run ( `cat ${ outputFile } ` , {
239- user : 'root' ,
240- } )
241+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) )
242+
243+ // Read the captured headers from inside the sandbox
244+ const result = await sandbox . commands . run ( `cat ${ outputFile } ` )
241245
242246 // Verify the Host header was modified according to maskRequestHost
243247 assert . include ( result . stdout , 'Host:' )
0 commit comments