2020-08-13 03:35:22 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <includes.h>
|
|
|
|
|
|
|
|
namespace http {
|
|
|
|
|
|
|
|
inline void to_json(json& j, const Flow& flow) {}
|
|
|
|
|
|
|
|
inline void from_json(const json& j, Flow& flow) {
|
2020-08-21 18:40:37 +00:00
|
|
|
//std::cout << std::setw(4) << j << "\n\n";
|
|
|
|
json j_flow;
|
|
|
|
if(!json_get(j, j_flow, "flow")) {
|
2020-08-13 03:35:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-08-14 16:54:43 +00:00
|
|
|
|
2020-08-21 18:40:37 +00:00
|
|
|
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)));
|
|
|
|
}
|
2020-08-18 13:13:45 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-21 18:40:37 +00:00
|
|
|
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)));
|
|
|
|
}
|
2020-08-18 13:13:45 +00:00
|
|
|
}
|
2020-08-13 03:35:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(http::Flow)
|