void HttpClient::onRequest(Http::Client& client) { try { Pt::Http::MessageProgress progress = client.endSend(); if( ! progress.finished() ) { client.beginSend(false); return; } while( ! advanceMessage() ) { if(client.request().buffer().size() > 8192) { client.beginSend(false); return; } } finishMessage(); client.beginReceive(); } catch(const System::IOError&) // HttpError is also an IOError { // setError() makes finishResult() call onError() where we throw setError(); finishResult(); } }
void request(Settings settings, http::Headers headers, std::string body, http::RequestCallback &&callback) { http_client.request( settings, headers, body, [=](Error error, http::Response &&response) { YAML::Node rr; rr["request"]["headers"] = std::map<std::string, std::string>(headers); rr["request"]["body"] = body; rr["request"]["url"] = settings.at("url"); rr["request"]["http_version"] = settings.at("http_version"); rr["request"]["method"] = settings.at("method"); // XXX we should probably update the OONI data format to remove // this. rr["method"] = settings.at("method"); if (error == 0) { rr["response"]["headers"] = std::map<std::string, std::string>(response.headers); rr["response"]["body"] = response.body; rr["response"]["response_line"] = response.response_line; rr["response"]["code"] = response.status_code; } else { rr["failure"] = "unknown_failure measurement_kit_error"; rr["error_code"] = (int)error; } entry["requests"].push_back(rr); entry["agent"] = "agent"; entry["socksproxy"] = ""; callback(error, std::move(response)); }, &logger); };