src: fix json payload from inspector
Fix the `webSocketDebuggerUrl` and `devtoolsFrontendUrl` returned by v8_inspector in /json HTTP endpoint to work with 3rd party clients. Fixes: https://github.com/nodejs/node/issues/7227 PR-URL: https://github.com/nodejs/node/pull/7232 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
This commit is contained in:
parent
cbbdc298b0
commit
853b8456ac
@ -29,13 +29,15 @@ namespace node {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const char DEVTOOLS_PATH[] = "/node";
|
const char DEVTOOLS_PATH[] = "/node";
|
||||||
|
const char DEVTOOLS_HASH[] = "521e5b7e2b7cc66b4006a8a54cb9c4e57494a5ef";
|
||||||
|
|
||||||
void PrintDebuggerReadyMessage(int port) {
|
void PrintDebuggerReadyMessage(int port) {
|
||||||
fprintf(stderr, "Debugger listening on port %d.\n"
|
fprintf(stderr, "Debugger listening on port %d.\n"
|
||||||
"To start debugging, open the following URL in Chrome:\n"
|
"To start debugging, open the following URL in Chrome:\n"
|
||||||
" chrome-devtools://devtools/remote/serve_file/"
|
" chrome-devtools://devtools/remote/serve_file/"
|
||||||
"@521e5b7e2b7cc66b4006a8a54cb9c4e57494a5ef/inspector.html?"
|
"@%s/inspector.html?"
|
||||||
"experiments=true&v8only=true&ws=localhost:%d/node\n", port, port);
|
"experiments=true&v8only=true&ws=localhost:%d/node\n",
|
||||||
|
port, DEVTOOLS_HASH, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AcceptsConnection(inspector_socket_t* socket, const char* path) {
|
bool AcceptsConnection(inspector_socket_t* socket, const char* path) {
|
||||||
@ -89,18 +91,19 @@ void SendVersionResponse(inspector_socket_t* socket) {
|
|||||||
SendHttpResponse(socket, buffer, len);
|
SendHttpResponse(socket, buffer, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendTargentsListResponse(inspector_socket_t* socket) {
|
void SendTargentsListResponse(inspector_socket_t* socket, int port) {
|
||||||
const char LIST_RESPONSE_TEMPLATE[] =
|
const char LIST_RESPONSE_TEMPLATE[] =
|
||||||
"[ {"
|
"[ {"
|
||||||
" \"description\": \"node.js instance\","
|
" \"description\": \"node.js instance\","
|
||||||
" \"devtoolsFrontendUrl\": "
|
" \"devtoolsFrontendUrl\": "
|
||||||
"\"https://chrome-devtools-frontend.appspot.com/serve_file/"
|
"\"https://chrome-devtools-frontend.appspot.com/serve_file/"
|
||||||
"@4604d24a75168768584760ba56d175507941852f/inspector.html\","
|
"@%s/inspector.html?experiments=true&v8only=true"
|
||||||
|
"&ws=localhost:%d%s\","
|
||||||
" \"faviconUrl\": \"https://nodejs.org/static/favicon.ico\","
|
" \"faviconUrl\": \"https://nodejs.org/static/favicon.ico\","
|
||||||
" \"id\": \"%d\","
|
" \"id\": \"%d\","
|
||||||
" \"title\": \"%s\","
|
" \"title\": \"%s\","
|
||||||
" \"type\": \"node\","
|
" \"type\": \"node\","
|
||||||
" \"webSocketDebuggerUrl\": \"ws://%s\""
|
" \"webSocketDebuggerUrl\": \"ws://localhost:%d%s\""
|
||||||
"} ]";
|
"} ]";
|
||||||
char buffer[sizeof(LIST_RESPONSE_TEMPLATE) + 4096];
|
char buffer[sizeof(LIST_RESPONSE_TEMPLATE) + 4096];
|
||||||
char title[2048]; // uv_get_process_title trims the title if too long
|
char title[2048]; // uv_get_process_title trims the title if too long
|
||||||
@ -114,12 +117,13 @@ void SendTargentsListResponse(inspector_socket_t* socket) {
|
|||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
size_t len = snprintf(buffer, sizeof(buffer), LIST_RESPONSE_TEMPLATE,
|
size_t len = snprintf(buffer, sizeof(buffer), LIST_RESPONSE_TEMPLATE,
|
||||||
getpid(), title, DEVTOOLS_PATH);
|
DEVTOOLS_HASH, port, DEVTOOLS_PATH, getpid(),
|
||||||
|
title, port, DEVTOOLS_PATH);
|
||||||
ASSERT_LT(len, sizeof(buffer));
|
ASSERT_LT(len, sizeof(buffer));
|
||||||
SendHttpResponse(socket, buffer, len);
|
SendHttpResponse(socket, buffer, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RespondToGet(inspector_socket_t* socket, const char* path) {
|
bool RespondToGet(inspector_socket_t* socket, const char* path, int port) {
|
||||||
const char PATH[] = "/json";
|
const char PATH[] = "/json";
|
||||||
const char PATH_LIST[] = "/json/list";
|
const char PATH_LIST[] = "/json/list";
|
||||||
const char PATH_VERSION[] = "/json/version";
|
const char PATH_VERSION[] = "/json/version";
|
||||||
@ -128,7 +132,7 @@ bool RespondToGet(inspector_socket_t* socket, const char* path) {
|
|||||||
SendVersionResponse(socket);
|
SendVersionResponse(socket);
|
||||||
} else if (!strncmp(PATH_LIST, path, sizeof(PATH_LIST)) ||
|
} else if (!strncmp(PATH_LIST, path, sizeof(PATH_LIST)) ||
|
||||||
!strncmp(PATH, path, sizeof(PATH))) {
|
!strncmp(PATH, path, sizeof(PATH))) {
|
||||||
SendTargentsListResponse(socket);
|
SendTargentsListResponse(socket, port);
|
||||||
} else if (!strncmp(path, PATH_ACTIVATE, sizeof(PATH_ACTIVATE) - 1) &&
|
} else if (!strncmp(path, PATH_ACTIVATE, sizeof(PATH_ACTIVATE) - 1) &&
|
||||||
atoi(path + (sizeof(PATH_ACTIVATE) - 1)) == getpid()) {
|
atoi(path + (sizeof(PATH_ACTIVATE) - 1)) == getpid()) {
|
||||||
const char TARGET_ACTIVATED[] = "Target activated";
|
const char TARGET_ACTIVATED[] = "Target activated";
|
||||||
@ -348,7 +352,7 @@ bool Agent::OnInspectorHandshakeIO(inspector_socket_t* socket,
|
|||||||
Agent* agent = static_cast<Agent*>(socket->data);
|
Agent* agent = static_cast<Agent*>(socket->data);
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case kInspectorHandshakeHttpGet:
|
case kInspectorHandshakeHttpGet:
|
||||||
return RespondToGet(socket, path);
|
return RespondToGet(socket, path, agent->port_);
|
||||||
case kInspectorHandshakeUpgrading:
|
case kInspectorHandshakeUpgrading:
|
||||||
return AcceptsConnection(socket, path);
|
return AcceptsConnection(socket, path);
|
||||||
case kInspectorHandshakeUpgraded:
|
case kInspectorHandshakeUpgraded:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user