Skip to content

Commit

Permalink
inspector: /json/version returns object, not array
Browse files Browse the repository at this point in the history
Make /json/version return an object instead of an object wrapped in an
array.

Fixes: #9760
PR-URL: #9762
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
  • Loading branch information
bnoordhuis authored and addaleax committed Dec 5, 2016
1 parent 2b7ecb5 commit 80a3934
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<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() {
Expand Down
6 changes: 6 additions & 0 deletions test/inspector/test-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 80a3934

Please sign in to comment.