mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-05 10:59:47 -05:00
Report failure for http requests with response code different from 200
This commit is contained in:
@@ -39,16 +39,27 @@
|
||||
namespace openspace {
|
||||
|
||||
namespace curlfunctions {
|
||||
size_t writeCallback(char *ptr,
|
||||
size_t size,
|
||||
size_t nmemb,
|
||||
void *userdata);
|
||||
size_t writeCallback(
|
||||
char *ptr,
|
||||
size_t size,
|
||||
size_t nmemb,
|
||||
void *userdata
|
||||
);
|
||||
|
||||
int progressCallback(void *clientp,
|
||||
int64_t dltotal,
|
||||
int64_t dlnow,
|
||||
int64_t ultotal,
|
||||
int64_t ulnow);
|
||||
int progressCallback(
|
||||
void *clientp,
|
||||
int64_t dltotal,
|
||||
int64_t dlnow,
|
||||
int64_t ultotal,
|
||||
int64_t ulnow
|
||||
);
|
||||
|
||||
size_t headerCallback(
|
||||
char* ptr,
|
||||
size_t size,
|
||||
size_t nmemb,
|
||||
void* userData
|
||||
);
|
||||
}
|
||||
|
||||
// Synchronous http request
|
||||
@@ -57,7 +68,7 @@ public:
|
||||
enum class ReadyState : unsigned int {
|
||||
Unsent,
|
||||
Loading,
|
||||
ReceivedHeaders,
|
||||
ReceivedHeader,
|
||||
Fail,
|
||||
Success
|
||||
};
|
||||
@@ -73,6 +84,11 @@ public:
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct Header {
|
||||
char* buffer;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
using ReadyStateChangeCallback = std::function<void(ReadyState)>;
|
||||
|
||||
// ProgressCallback: Return non-zero value to cancel download.
|
||||
@@ -83,6 +99,11 @@ public:
|
||||
// the request will fail.
|
||||
using DataCallback = std::function<size_t(Data)>;
|
||||
|
||||
// HeaderCallback: Return number of bytes successfully stored.
|
||||
// If this does not match the data buffer sice reported in Header,
|
||||
// the request will fail.
|
||||
using HeaderCallback = std::function<size_t(Header)>;
|
||||
|
||||
struct RequestOptions {
|
||||
int requestTimeoutSeconds; // 0 for no timeout
|
||||
};
|
||||
@@ -90,6 +111,7 @@ public:
|
||||
HttpRequest(std::string url);
|
||||
|
||||
void onReadyStateChange(ReadyStateChangeCallback cb);
|
||||
void onHeader(HeaderCallback cb);
|
||||
void onProgress(ProgressCallback cb);
|
||||
void onData(DataCallback cb);
|
||||
|
||||
@@ -103,6 +125,7 @@ private:
|
||||
ReadyStateChangeCallback _onReadyStateChange;
|
||||
ProgressCallback _onProgress;
|
||||
DataCallback _onData;
|
||||
HeaderCallback _onHeader;
|
||||
|
||||
ReadyState _readyState;
|
||||
Progress _progress;
|
||||
@@ -120,16 +143,24 @@ private:
|
||||
int64_t dlnow,
|
||||
int64_t ultotal,
|
||||
int64_t ulnow);
|
||||
|
||||
friend size_t curlfunctions::headerCallback(
|
||||
char *ptr,
|
||||
size_t size,
|
||||
size_t nmemb,
|
||||
void *userdata);
|
||||
};
|
||||
|
||||
class HttpDownload {
|
||||
public:
|
||||
using ProgressCallback = std::function<bool(HttpRequest::Progress)>;
|
||||
using HeaderCallback = std::function<bool(HttpRequest::Header)>;
|
||||
|
||||
HttpDownload();
|
||||
HttpDownload(HttpDownload&& d) = default;
|
||||
virtual ~HttpDownload() = default;
|
||||
void onProgress(ProgressCallback progressCallback);
|
||||
void onHeader(HeaderCallback headerCallback);
|
||||
bool hasStarted();
|
||||
bool hasFailed();
|
||||
bool hasSucceeded();
|
||||
|
||||
Reference in New Issue
Block a user