-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inspector: add initial support for network inspection
- Loading branch information
Showing
10 changed files
with
554 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "network_agent.h" | ||
|
||
#include "inspector_agent.h" | ||
|
||
namespace node { | ||
namespace inspector { | ||
namespace protocol { | ||
|
||
std::unique_ptr<Network::Request> Request(const String& url, | ||
const String& method) { | ||
return Network::Request::create().setUrl(url).setMethod(method).build(); | ||
} | ||
|
||
NetworkAgent::NetworkAgent() {} | ||
|
||
void NetworkAgent::Wire(UberDispatcher* dispatcher) { | ||
frontend_ = std::make_unique<Network::Frontend>(dispatcher->channel()); | ||
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(const String& request_id, | ||
const String& url, | ||
const String& method, | ||
double timestamp, | ||
double wall_time) { | ||
frontend_->requestWillBeSent( | ||
request_id, Request(url, method), timestamp, wall_time); | ||
} | ||
|
||
void NetworkAgent::responseReceived(const String& request_id, | ||
double timestamp) { | ||
frontend_->responseReceived(request_id, timestamp); | ||
} | ||
|
||
void NetworkAgent::dataReceived(const String& request_id, | ||
double timestamp, | ||
int data_length) { | ||
frontend_->dataReceived(request_id, timestamp, data_length); | ||
} | ||
|
||
void NetworkAgent::loadingFinished(const String& request_id, | ||
const String& response, | ||
double timestamp, | ||
int encoded_data_length) { | ||
request_id_to_response_[request_id] = response; | ||
frontend_->loadingFinished(request_id, timestamp, encoded_data_length); | ||
} | ||
|
||
} // namespace protocol | ||
} // namespace inspector | ||
} // namespace node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef SRC_INSPECTOR_NETWORK_AGENT_H_ | ||
#define SRC_INSPECTOR_NETWORK_AGENT_H_ | ||
|
||
#include "node/inspector/protocol/Network.h" | ||
#include "v8.h" | ||
|
||
#include <unordered_map> | ||
|
||
namespace node { | ||
|
||
namespace inspector { | ||
namespace protocol { | ||
|
||
class NetworkAgent : public Network::Backend { | ||
public: | ||
NetworkAgent(); | ||
|
||
void Wire(UberDispatcher* dispatcher); | ||
|
||
DispatchResponse getResponseBody(const String& in_requestId, | ||
String* out_body) override; | ||
|
||
void requestWillBeSent(const String& request_id, | ||
const String& url, | ||
const String& method, | ||
double timestamp, | ||
double wall_time); | ||
|
||
void responseReceived(const String& request_id, double timestamp); | ||
|
||
void dataReceived(const String& request_id, | ||
double timestamp, | ||
int data_length); | ||
|
||
void loadingFinished(const String& request_id, | ||
const String& response, | ||
double timestamp, | ||
int encoded_data_length); | ||
|
||
private: | ||
std::shared_ptr<Network::Frontend> frontend_; | ||
std::unordered_map<String, String> request_id_to_response_; | ||
}; | ||
|
||
} // namespace protocol | ||
} // namespace inspector | ||
} // namespace node | ||
|
||
#endif // SRC_INSPECTOR_NETWORK_AGENT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.