#pragma once #include /* { "flow": { "client_conn": { "address": [ "::1", 37570, 0, 0 ], "alpn_proto_negotiated": "http/1.1", "cipher_name": "TLS_AES_256_GCM_SHA384", "clientcert": null, "id": "a1e82917-2d58-4b99-be9e-2b962bc499b2", "mitmcert": "mitmcertstring", "sni": "yolo.jetzt", "timestamp_end": null, "timestamp_start": 1597284668.6260498, "timestamp_tls_setup": 1597284669.8449724, "tls_established": true, "tls_extensions": [...], "tls_version": "TLSv1.3" }, "error": null, "id": "a6aa4e6e-ca31-4f58-bf47-2da7bfcf0000", "intercepted": false, "marked": false, "metadata": {}, "mode": "transparent", "request": { "content": "", "first_line_format": "relative", "headers": [ [ "Host", "yolo.jetzt" ], [ "User-Agent", "curl/7.68.0" ], [ "Accept", ] ], "host": "yolo.jetzt", "http_version": "HTTP/1.1", "is_replay": false, "method": "GET", "path": "/", "port": 443, "scheme": "https", "timestamp_end": 1597284669.92817, "timestamp_start": 1597284669.8761458 }, "response": null, "server_conn": { "address": [ "yolo.jetzt", 443 ], "alpn_proto_negotiated": "http/1.1", "cert": "certstring", "id": "50a3b79d-2912-45f3-991b-c03406a1018f", "ip_address": [ "95.156.226.69", 443 ], "sni": "yolo.jetzt", "source_address": [ "192.168.42.102", 44949 ], "timestamp_end": null, "timestamp_start": 1597284669.2133315, "timestamp_tcp_setup": 1597284669.2892282, "timestamp_tls_setup": 1597284669.584602, "tls_established": true, "tls_version": "TLSv1.2", "via": null }, "type": "http", "version": 7 }, "msg": "request" } */ namespace http { struct Request { std::string server_ip_address; bool tls; std::string content; std::string scheme; std::string method; std::string host; unsigned short port; std::string http_version; std::string path; double timestamp_start; double timestamp_end; std::vector> headers; std::string error; }; struct Response { int status_code; std::string http_version; std::string reason; std::string content; double timestamp_start; double timestamp_end; std::vector> headers; }; struct Flow { std::string uid; Request request; 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)