Skip to content

Commit e27f14f

Browse files
committed
inspector: /json/version returns object, not array
Make /json/version return an object instead of an object wrapped in an array. Fixes: #9760 PR-URL: #9762 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Eugene Ostroukhov <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]>
1 parent d214959 commit e27f14f

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/inspector_agent.cc

+14-7
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,30 @@ void OnBufferAlloc(uv_handle_t* handle, size_t len, uv_buf_t* buf) {
8989
buf->len = len;
9090
}
9191

92-
void SendHttpResponse(InspectorSocket* socket, const std::string& response) {
92+
void SendHttpResponse(InspectorSocket* socket, const char* response,
93+
size_t size) {
9394
const char HEADERS[] = "HTTP/1.0 200 OK\r\n"
9495
"Content-Type: application/json; charset=UTF-8\r\n"
9596
"Cache-Control: no-cache\r\n"
9697
"Content-Length: %zu\r\n"
9798
"\r\n";
9899
char header[sizeof(HEADERS) + 20];
99-
int header_len = snprintf(header, sizeof(header), HEADERS, response.size());
100+
int header_len = snprintf(header, sizeof(header), HEADERS, size);
100101
inspector_write(socket, header, header_len);
101-
inspector_write(socket, response.data(), response.size());
102+
inspector_write(socket, response, size);
103+
}
104+
105+
void SendHttpResponse(InspectorSocket* socket, const std::string& response) {
106+
SendHttpResponse(socket, response.data(), response.size());
102107
}
103108

104109
void SendVersionResponse(InspectorSocket* socket) {
105-
std::map<std::string, std::string> response;
106-
response["Browser"] = "node.js/" NODE_VERSION;
107-
response["Protocol-Version"] = "1.1";
108-
SendHttpResponse(socket, MapToString(response));
110+
static const char response[] =
111+
"{\n"
112+
" \"Browser\": \"node.js/" NODE_VERSION "\",\n"
113+
" \"Protocol-Version\": \"1.1\"\n"
114+
"}\n";
115+
SendHttpResponse(socket, response, sizeof(response) - 1);
109116
}
110117

111118
std::string GetProcessTitle() {

test/inspector/test-inspector.js

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ function checkListResponse(err, response) {
1717
function checkVersion(err, response) {
1818
assert.ifError(err);
1919
assert.ok(response);
20+
const expected = {
21+
'Browser': 'node.js/' + process.version,
22+
'Protocol-Version': '1.1',
23+
};
24+
assert.strictEqual(JSON.stringify(response),
25+
JSON.stringify(expected));
2026
}
2127

2228
function checkBadPath(err, response) {

0 commit comments

Comments
 (0)