From e27f14f0b4ab8bb02d1b2ccc1d2e0d517b1248ea Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 23 Nov 2016 14:14:20 +0100 Subject: [PATCH] inspector: /json/version returns object, not array Make /json/version return an object instead of an object wrapped in an array. Fixes: https://github.com/nodejs/node/issues/9760 PR-URL: https://github.com/nodejs/node/pull/9762 Reviewed-By: Colin Ihrig Reviewed-By: Eugene Ostroukhov Reviewed-By: Santiago Gimeno --- src/inspector_agent.cc | 21 ++++++++++++++------- test/inspector/test-inspector.js | 6 ++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index a01ec0c2f5e2c0..fd7968ff68ced1 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -89,23 +89,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 75c645bb222781..7e53eaa55fffb7 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) {