Allow to cancel asynchronous HTTP requests (#332)

Usage:

	auto args = this->httpClient.createRequest(url, method);
	httpClient.performRequest(args, ...);
	[...]
	// Oops, we don't actually want to complete the request!
	args->cancel = true;
This commit is contained in:
Martin Natano
2021-12-21 08:01:55 +01:00
committed by GitHub
parent 688f85fda6
commit 66cd29e747
4 changed files with 81 additions and 11 deletions

View File

@ -8,6 +8,7 @@
#include "IXProgressCallback.h"
#include "IXWebSocketHttpHeaders.h"
#include <atomic>
#include <tuple>
#include <unordered_map>
@ -30,6 +31,7 @@ namespace ix
TooManyRedirects = 12,
ChunkReadError = 13,
CannotReadBody = 14,
Cancelled = 15,
Invalid = 100
};
@ -87,6 +89,7 @@ namespace ix
bool compressRequest = false;
Logger logger;
OnProgressCallback onProgressCallback;
std::atomic<bool> cancel;
};
using HttpRequestArgsPtr = std::shared_ptr<HttpRequestArgs>;