Status TLSTransport::sendRequest(const std::string& params) { if (destination_.find("https://") == std::string::npos) { return Status(1, "Cannot create TLS request for non-HTTPS protocol URI"); } auto client = getClient(); http::client::request r(destination_); decorateRequest(r); // Allow request calls to override the default HTTP POST verb. HTTPVerb verb = HTTP_POST; if (options_.count("verb") > 0) { verb = (HTTPVerb)options_.get<int>("verb", HTTP_POST); } try { VLOG(1) << "TLS/HTTPS " << ((verb == HTTP_POST) ? "POST" : "PUT") << " request to URI: " << destination_; if (verb == HTTP_POST) { response_ = client.post(r, params); } else { response_ = client.put(r, params); } response_status_ = serializer_->deserialize(body(response_), response_params_); } catch (const std::exception& e) { return Status((tlsFailure(e.what())) ? 2 : 1, std::string("Request error: ") + e.what()); } return response_status_; }
Status TLSTransport::sendRequest(const std::string& params, bool compress) { if (destination_.find("https://") == std::string::npos) { return Status(1, "Cannot create TLS request for non-HTTPS protocol URI"); } auto client = getClient(); http::client::request r(destination_); decorateRequest(r); if (compress) { // Later, when posting/putting, the data will be optionally compressed. r << boost::network::header("Content-Encoding", "gzip"); } // Allow request calls to override the default HTTP POST verb. HTTPVerb verb = HTTP_POST; if (options_.count("verb") > 0) { verb = (HTTPVerb)options_.get<int>("verb", HTTP_POST); } VLOG(1) << "TLS/HTTPS " << ((verb == HTTP_POST) ? "POST" : "PUT") << " request to URI: " << destination_; if (FLAGS_verbose && FLAGS_tls_dump) { fprintf(stdout, "%s\n", params.c_str()); } try { if (verb == HTTP_POST) { response_ = client.post(r, (compress) ? compressString(params) : params); } else { response_ = client.put(r, (compress) ? compressString(params) : params); } const auto& response_body = body(response_); if (FLAGS_verbose && FLAGS_tls_dump) { fprintf(stdout, "%s\n", std::string(response_body).c_str()); } response_status_ = serializer_->deserialize(response_body, response_params_); } catch (const std::exception& e) { return Status((tlsFailure(e.what())) ? 2 : 1, std::string("Request error: ") + e.what()); } return response_status_; }
Status TLSTransport::sendRequest() { if (destination_.find("https://") == std::string::npos) { return Status(1, "Cannot create TLS request for non-HTTPS protocol URI"); } auto client = getClient(); http::client::request r(destination_); decorateRequest(r); try { VLOG(1) << "TLS/HTTPS GET request to URI: " << destination_; response_ = client.get(r); response_status_ = serializer_->deserialize(body(response_), response_params_); } catch (const std::exception& e) { return Status((tlsFailure(e.what())) ? 2 : 1, std::string("Request error: ") + e.what()); } return response_status_; }