I am using the poco libraries, and I'm trying to wrap them into a nicer HTTPClient that I can use everywhere in a few lines, and also make them async. To that end, I am using std::future and a custom response struct. However, for some reason, it tells me it's trying to reference a deleted function. I'm not deleting anything, so I don't really know why it would be saying this.
httpclient.h
#include <Poco/Net/HTTPSClientSession.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/Exception.h>
#include <Poco/URI.h>
#include <future>
#include <map>
typedef struct response {
std::istream& is;
Poco::Net::HTTPResponse& response;
} RES;
class HttpClient {
public:
static std::future<RES> get(Poco::Net::HTTPSClientSession& session, Poco::URI url, std::map<std::string, std::string> headers = {});
};
httpclient.cpp
#include "httpclient.h"
std::future<RES> HttpClient::get(Poco::Net::HTTPSClientSession& session, Poco::URI url, std::map<std::string, std::string> headers) {
return std::async(std::launch::async, [&session, url, headers](){
try {
std::string path(url.getPathAndQuery());
if (path.empty()) path = "/";
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, path, Poco::Net::HTTPMessage::HTTP_1_1);
request.add("Content-Length", "0");
if (headers.size() > 0) {
for (std::map<std::string, std::string>::const_iterator itr = headers.begin(); itr != headers.end(); ++itr) {
request.add(itr->first, itr->second);
}
}
Poco::Net::HTTPResponse _res;
session.sendRequest(request);
std::istream& is = session.receiveResponse(_res);
return RES { is, _res };
}
catch (Poco::Exception & exc) {
OutputDebugStringA(exc.displayText().c_str());
}
});
}
main.cpp
Poco::Net::initializeSSL();
Poco::URI uri("https://www.google.com");
const Poco::Net::Context::Ptr context = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "", "", Poco::Net::Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort(), context);
std::future<RES> response = HttpClient::get(session, uri, {});
response.get();
This is the precise error I got:
C2280: response &response::operator =(const response &)': attempting to reference a deleted function future:line 332
.
Thank you!