diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index 21fa2cf7c1..79bd71e24d 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -91,23 +91,30 @@ void OnBufferAlloc(uv_handle_t* handle, size_t len, uv_buf_t* buf) { buf->len = len; } -void SendHttpResponse(InspectorSocket* socket, const std::string& response) { +void SendHttpResponse(InspectorSocket* socket, const char* response, + size_t size) { const char HEADERS[] = "HTTP/1.0 200 OK\r\n" "Content-Type: application/json; charset=UTF-8\r\n" "Cache-Control: no-cache\r\n" "Content-Length: %zu\r\n" "\r\n"; char header[sizeof(HEADERS) + 20]; - int header_len = snprintf(header, sizeof(header), HEADERS, response.size()); + int header_len = snprintf(header, sizeof(header), HEADERS, size); inspector_write(socket, header, header_len); - inspector_write(socket, response.data(), response.size()); + inspector_write(socket, response, size); +} + +void SendHttpResponse(InspectorSocket* socket, const std::string& response) { + SendHttpResponse(socket, response.data(), response.size()); } void SendVersionResponse(InspectorSocket* socket) { - std::map response; - response["Browser"] = "node.js/" NODE_VERSION; - response["Protocol-Version"] = "1.1"; - SendHttpResponse(socket, MapToString(response)); + static const char response[] = + "{\n" + " \"Browser\": \"node.js/" NODE_VERSION "\",\n" + " \"Protocol-Version\": \"1.1\"\n" + "}\n"; + SendHttpResponse(socket, response, sizeof(response) - 1); } std::string GetProcessTitle() { diff --git a/test/inspector/test-inspector.js b/test/inspector/test-inspector.js index ccc8b1a058..46b3323b07 100644 --- a/test/inspector/test-inspector.js +++ b/test/inspector/test-inspector.js @@ -17,6 +17,12 @@ function checkListResponse(err, response) { function checkVersion(err, response) { assert.ifError(err); assert.ok(response); + const expected = { + 'Browser': 'node.js/' + process.version, + 'Protocol-Version': '1.1', + }; + assert.strictEqual(JSON.stringify(response), + JSON.stringify(expected)); } function checkBadPath(err, response) {