Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspector: /json/version returns object, not array #9762

Merged
merged 1 commit into from
Nov 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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