diff --git a/test/http/stub.js b/test/http/stub.js index 8e134ecb..98709d6a 100644 --- a/test/http/stub.js +++ b/test/http/stub.js @@ -1,20 +1,17 @@ const http = require('http'); +const PORT = 9999; -const server = http.createServer((req, res) => { - // Set the response header to indicate JSON content - res.setHeader('Content-Type', 'application/json'); - - // Define a simple JSON response - const jsonResponse = { - message: 'Hello, JSON World!', - timestamp: new Date().toISOString(), - }; +http.createServer((request, response) => { + for (const [key, value] of Object.entries(request.headers)) { + response.setHeader(`X-${key}`, value); + } - // Send the JSON response - res.end(JSON.stringify(jsonResponse)); -}); + if (request.headers['x-code']) { + response.statusCode = parseInt(request.headers['x-code'], 10); + } -const PORT = 9999; -server.listen(PORT, () => { + response.setHeader('Content-Type', 'text/plain'); + response.end(`RECEIVED ${request.method} ${request.url}`); +}).listen(PORT, () => { console.log(`Server is listening on port ${PORT}`); });