Browse Source

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 <cjihrig@gmail.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
v6.x
Ben Noordhuis 8 years ago
committed by Myles Borins
parent
commit
a3ba4ff49f
  1. 21
      src/inspector_agent.cc
  2. 6
      test/inspector/test-inspector.js

21
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<std::string, std::string> 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() {

6
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) {

Loading…
Cancel
Save