This commit is contained in:
Tim Blume 2021-03-19 17:40:33 +01:00
parent a0ce50b7cd
commit f99ee2abde
11 changed files with 100 additions and 72 deletions

View file

@ -105,4 +105,53 @@ struct Flow {
Response response;
};
inline void to_json(json& j, const Flow& flow) {}
inline void from_json(const json& j, Flow& flow) {
//std::cout << std::setw(4) << j << "\n\n";
json j_flow;
if(!json_get(j, j_flow, "flow")) {
return;
}
json_get(j_flow, flow.uid, "id");
if(json j_request; json_get(j_flow, j_request, "request")) {
json_get(j_request, flow.request.tls, "server_conn", "tls_established");
json_get(j_request, flow.request.port, "port");
json_get(j_request, flow.request.host, "host");
json_get(j_request, flow.request.scheme, "scheme");
json_get(j_request, flow.request.path, "path");
json_get(j_request, flow.request.content, "content");
json_get(j_request, flow.request.method, "method");
json_get(j_request, flow.request.http_version, "http_version");
json_get(j_request, flow.request.timestamp_start, "timestamp_start");
json_get(j_request, flow.request.timestamp_end, "timestamp_end");
json j_headers;
if(json_get(j_request, j_headers, "headers")) {
for(auto& [k,v] : j_headers.items()) {
flow.request.headers.push_back(std::make_tuple(v.at(0), v.at(1)));
}
}
}
if(json j_response; json_get(j_flow, j_response, "response")) {
json_get(j_response, flow.response.status_code, "status_code");
json_get(j_response, flow.response.http_version, "http_version");
json_get(j_response, flow.response.reason, "reason");
json_get(j_response, flow.response.content, "content");
json_get(j_response, flow.response.timestamp_start, "timestamp_start");
json_get(j_response, flow.response.timestamp_end, "timestamp_end");
json j_headers;
if(json_get(j_response, j_headers, "headers")) {
for(auto& [k,v] : j_headers.items()) {
flow.response.headers.push_back(std::make_tuple(v.at(0), v.at(1)));
}
}
}
}
}
Q_DECLARE_METATYPE(http::Flow)

View file

@ -10,9 +10,11 @@ namespace http {
//! Interface for implementing proxies
/*!
Interface for implementing proxies
There are no signals, because apparently Qt Plugins do not support interfaces, which inherit from QObject.
(it will fail upon loading the plugin)
*/
class ProxyInterface : public QObject {
Q_OBJECT
class ProxyInterface {
public:
virtual ~ProxyInterface() = default;
//! called in a custom thread, may block.
@ -22,10 +24,9 @@ public:
//! disconnects the handle
virtual void disconnect() = 0;
// options/settings
signals:
virtual void finished();
virtual void error(QString err);
virtual void message(http::Flow flow);
std::function<void()> finished;
std::function<void(QString)> error;
std::function<void(http::Flow flow)> message;
};
}