Skip to content

Commit

Permalink
inspector: drop support for response body inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
cola119 committed Jul 4, 2024
1 parent 48feeb3 commit fbf5a31
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 127 deletions.
24 changes: 5 additions & 19 deletions lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,28 +469,14 @@ function setupNetworkInspection() {
if (typeof request._inspectorRequestId !== 'string') {
return;
}
const timestamp = DateNow() / 1000;
emitProtocolEvent('NodeNetwork.responseReceived', {
requestId: request._inspectorRequestId,
timestamp: DateNow() / 1000,
timestamp,
});
let responseString = '';
const onData = (chunk) => {
emitProtocolEvent('NodeNetwork.dataReceived', {
requestId: request._inspectorRequestId,
timestamp: DateNow() / 1000,
dataLength: chunk.length,
});
responseString += chunk.toString();
};
response.on('data', onData);
response.on('end', () => {
emitProtocolEvent('NodeNetwork.loadingFinished', {
requestId: request._inspectorRequestId,
response: responseString,
timestamp: DateNow() / 1000,
encodedDataLength: responseString.length,
});
response.removeListener('data', onData);
emitProtocolEvent('NodeNetwork.loadingFinished', {
requestId: request._inspectorRequestId,
timestamp,
});
});
}
Expand Down
30 changes: 1 addition & 29 deletions src/inspector/network_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ std::unique_ptr<Network::Request> Request(const String& url,
NetworkAgent::NetworkAgent() {
event_notifier_map_["requestWillBeSent"] = &NetworkAgent::requestWillBeSent;
event_notifier_map_["responseReceived"] = &NetworkAgent::responseReceived;
event_notifier_map_["dataReceived"] = &NetworkAgent::dataReceived;
event_notifier_map_["loadingFinished"] = &NetworkAgent::loadingFinished;
}

Expand All @@ -29,16 +28,6 @@ void NetworkAgent::Wire(UberDispatcher* dispatcher) {
Network::Dispatcher::wire(dispatcher, this);
}

DispatchResponse NetworkAgent::getResponseBody(const String& in_requestId,
String* out_body) {
auto it = request_id_to_response_.find(in_requestId);
if (it != request_id_to_response_.end()) {
*out_body = it->second;
request_id_to_response_.erase(it);
}
return DispatchResponse::OK();
}

void NetworkAgent::requestWillBeSent(
std::unique_ptr<protocol::DictionaryValue> params) {
String request_id;
Expand Down Expand Up @@ -67,31 +56,14 @@ void NetworkAgent::responseReceived(
frontend_->responseReceived(request_id, timestamp);
}

void NetworkAgent::dataReceived(
std::unique_ptr<protocol::DictionaryValue> params) {
String request_id;
params->getString("requestId", &request_id);
double timestamp;
params->getDouble("timestamp", &timestamp);
int data_length;
params->getInteger("dataLength", &data_length);

frontend_->dataReceived(request_id, timestamp, data_length);
}

void NetworkAgent::loadingFinished(
std::unique_ptr<protocol::DictionaryValue> params) {
String request_id;
params->getString("requestId", &request_id);
double timestamp;
params->getDouble("timestamp", &timestamp);
int encoded_data_length;
params->getInteger("encodedDataLength", &encoded_data_length);
String response;
params->getString("response", &response);

request_id_to_response_[request_id] = response;
frontend_->loadingFinished(request_id, timestamp, encoded_data_length);
frontend_->loadingFinished(request_id, timestamp);
}

} // namespace protocol
Expand Down
6 changes: 0 additions & 6 deletions src/inspector/network_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,14 @@ class NetworkAgent : public Network::Backend {
void emitNotification(const String& event,
std::unique_ptr<protocol::DictionaryValue> params);

DispatchResponse getResponseBody(const String& in_requestId,
String* out_body) override;

void requestWillBeSent(std::unique_ptr<protocol::DictionaryValue> params);

void responseReceived(std::unique_ptr<protocol::DictionaryValue> params);

void dataReceived(std::unique_ptr<protocol::DictionaryValue> params);

void loadingFinished(std::unique_ptr<protocol::DictionaryValue> params);

private:
std::shared_ptr<Network::Frontend> frontend_;
std::unordered_map<String, String> request_id_to_response_;
using EventNotifier =
void (NetworkAgent::*)(std::unique_ptr<protocol::DictionaryValue>);
std::unordered_map<String, EventNotifier> event_notifier_map_;
Expand Down
21 changes: 1 addition & 20 deletions src/inspector/node_network_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ NodeNetworkAgent::NodeNetworkAgent(Environment* env) : env_(env) {
event_notifier_map_["requestWillBeSent"] =
&NodeNetworkAgent::requestWillBeSent;
event_notifier_map_["responseReceived"] = &NodeNetworkAgent::responseReceived;
event_notifier_map_["dataReceived"] = &NodeNetworkAgent::dataReceived;
event_notifier_map_["loadingFinished"] = &NodeNetworkAgent::loadingFinished;
}

Expand Down Expand Up @@ -62,32 +61,14 @@ void NodeNetworkAgent::responseReceived(
protocol::StringUtil::ToStringView(params->toJSONString()));
}

void NodeNetworkAgent::dataReceived(
std::unique_ptr<protocol::DictionaryValue> params) {
String request_id;
params->getString("requestId", &request_id);
double timestamp;
params->getDouble("timestamp", &timestamp);
int data_length;
params->getInteger("dataLength", &data_length);

frontend_->dataReceived(request_id, timestamp, data_length);

env_->inspector_agent()->EmitProtocolEvent(
protocol::StringUtil::ToStringView("Network.dataReceived"),
protocol::StringUtil::ToStringView(params->toJSONString()));
}

void NodeNetworkAgent::loadingFinished(
std::unique_ptr<protocol::DictionaryValue> params) {
String request_id;
params->getString("requestId", &request_id);
double timestamp;
params->getDouble("timestamp", &timestamp);
int encoded_data_length;
params->getInteger("encodedDataLength", &encoded_data_length);

frontend_->loadingFinished(request_id, timestamp, encoded_data_length);
frontend_->loadingFinished(request_id, timestamp);

env_->inspector_agent()->EmitProtocolEvent(
protocol::StringUtil::ToStringView("Network.loadingFinished"),
Expand Down
2 changes: 0 additions & 2 deletions src/inspector/node_network_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class NodeNetworkAgent : public NodeNetwork::Backend {

void responseReceived(std::unique_ptr<protocol::DictionaryValue> params);

void dataReceived(std::unique_ptr<protocol::DictionaryValue> params);

void loadingFinished(std::unique_ptr<protocol::DictionaryValue> params);

private:
Expand Down
31 changes: 0 additions & 31 deletions src/inspector/node_protocol.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,12 @@ experimental domain NodeNetwork
# Timestamp.
Network.MonotonicTime timestamp

event dataReceived
parameters
# Request identifier.
Network.RequestId requestId
# Timestamp.
Network.MonotonicTime timestamp
# Data chunk length.
integer dataLength

event loadingFinished
parameters
# Request identifier.
Network.RequestId requestId
# Timestamp.
Network.MonotonicTime timestamp
# Total number of bytes received for this request.
number encodedDataLength

# Partial support for Network domain of ChromeDevTools Protocol.
# https://chromedevtools.github.io/devtools-protocol/tot/Network
Expand All @@ -157,15 +146,6 @@ experimental domain Network
string url
string method

# Returns content served for the given request.
command getResponseBody
parameters
# Identifier of the network request to get content for.
RequestId requestId
returns
# Response body.
string body

# Fired when page is about to send HTTP request.
event requestWillBeSent
parameters
Expand All @@ -186,23 +166,12 @@ experimental domain Network
# Timestamp.
MonotonicTime timestamp

event dataReceived
parameters
# Request identifier.
RequestId requestId
# Timestamp.
MonotonicTime timestamp
# Data chunk length.
integer dataLength

event loadingFinished
parameters
# Request identifier.
RequestId requestId
# Timestamp.
MonotonicTime timestamp
# Total number of bytes received for this request.
number encodedDataLength

# Support for inspecting node process state.
experimental domain NodeRuntime
Expand Down
20 changes: 0 additions & 20 deletions test/parallel/test-inspector-network-domain.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ const testHttpGet = () => new Promise((resolve, reject) => {
assert.ok(params.requestId.startsWith('node-network-event-'));
assert.strictEqual(typeof params.timestamp, 'number');
}));
session.on('NodeNetwork.dataReceived', common.mustCall(({ params }) => {
assert.ok(params.requestId.startsWith('node-network-event-'));
assert.strictEqual(typeof params.timestamp, 'number');
assert.strictEqual(typeof params.dataLength, 'number');
}));
session.on('NodeNetwork.loadingFinished', common.mustCall(({ params }) => {
assert.ok(params.requestId.startsWith('node-network-event-'));
assert.strictEqual(typeof params.timestamp, 'number');
Expand All @@ -87,11 +82,6 @@ const testHttpGet = () => new Promise((resolve, reject) => {
assert.ok(params.requestId.startsWith('node-network-event-'));
assert.strictEqual(typeof params.timestamp, 'number');
}));
session.on('Network.dataReceived', common.mustCall(({ params }) => {
assert.ok(params.requestId.startsWith('node-network-event-'));
assert.strictEqual(typeof params.timestamp, 'number');
assert.strictEqual(typeof params.dataLength, 'number');
}));
session.on('Network.loadingFinished', common.mustCall(({ params }) => {
assert.ok(params.requestId.startsWith('node-network-event-'));
assert.strictEqual(typeof params.timestamp, 'number');
Expand Down Expand Up @@ -123,11 +113,6 @@ const testHttpsGet = () => new Promise((resolve, reject) => {
assert.ok(params.requestId.startsWith('node-network-event-'));
assert.strictEqual(typeof params.timestamp, 'number');
}));
session.on('NodeNetwork.dataReceived', common.mustCall(({ params }) => {
assert.ok(params.requestId.startsWith('node-network-event-'));
assert.strictEqual(typeof params.timestamp, 'number');
assert.strictEqual(typeof params.dataLength, 'number');
}));
session.on('NodeNetwork.loadingFinished', common.mustCall(({ params }) => {
assert.ok(params.requestId.startsWith('node-network-event-'));
assert.strictEqual(typeof params.timestamp, 'number');
Expand All @@ -148,11 +133,6 @@ const testHttpsGet = () => new Promise((resolve, reject) => {
assert.ok(params.requestId.startsWith('node-network-event-'));
assert.strictEqual(typeof params.timestamp, 'number');
}));
session.on('Network.dataReceived', common.mustCall(({ params }) => {
assert.ok(params.requestId.startsWith('node-network-event-'));
assert.strictEqual(typeof params.timestamp, 'number');
assert.strictEqual(typeof params.dataLength, 'number');
}));
session.on('Network.loadingFinished', common.mustCall(({ params }) => {
assert.ok(params.requestId.startsWith('node-network-event-'));
assert.strictEqual(typeof params.timestamp, 'number');
Expand Down

0 comments on commit fbf5a31

Please sign in to comment.