2 #include "oxygine-include.h" 10 DECLARE_SMART(HttpRequestTask, spHttpRequestTask);
14 static spHttpRequestTask create();
16 typedef std::function< bool(int) > responseCodeChecker;
17 static void setCustomRequests(createHttpRequestCallback);
19 static void release();
25 ERROR = AsyncTask::ERROR,
26 PROGRESS = AsyncTask::PROGRESS,
27 COMPLETE = AsyncTask::COMPLETE,
33 enum {EVENT = PROGRESS};
34 ProgressEvent(
size_t Delta,
size_t Loaded,
size_t Total,
bool First) :
Event(PROGRESS), delta(Delta), loaded(Loaded), total(Total), first(First) {};
45 const std::vector<unsigned char>& getResponse()
const;
46 const std::vector<unsigned char>& getPostData()
const;
47 const std::string& getFileName()
const;
48 const std::string& getUrl()
const;
49 size_t getReceivedSize()
const;
50 size_t getExpectedSize()
const;
54 int getResponseCode()
const {
return _responseCode; }
55 const responseCodeChecker& getResponseCodeChecker()
const {
return _responseCodeChecker;}
56 void addHeader(
const std::string& key,
const std::string& value);
58 void setPostData(
const std::vector<unsigned char>& data);
59 void setUrl(
const std::string& url);
60 void setFileName(
const std::string& name,
bool continueDownload =
false);
61 void setCacheEnabled(
bool enabled);
64 void setResponseCodeChecker(
const responseCodeChecker& f) {_responseCodeChecker = f;}
65 void setSuccessOnAnyResponseCode(
bool en);
66 void setExpectedSize(
size_t size) { _expectedContentSize = size; }
69 bool _prerun()
override;
70 void _onError()
override;
71 void _onComplete()
override;
72 void _dispatchComplete()
override;
73 void _finalize(
bool error)
override;
75 std::string _getRunInfo()
const override {
return _url; }
78 void write(
const void* data,
size_t size);
81 void asyncProgress(
size_t delta,
size_t loaded,
size_t total);
83 void dispatchProgress(
size_t delta,
size_t loaded,
size_t total);
85 virtual void _setFileName(
const std::string& name) {}
86 virtual void _setUrl(
const std::string& url) {}
87 virtual void _setPostData(
const std::vector<unsigned char>& data) {}
88 virtual void _setCacheEnabled(
bool enabled) {}
89 virtual void _addHeader(
const std::string& key,
const std::string& value) {}
93 file::handle _fhandle;
96 bool _firstTimeProgressDispatched;
97 bool _progressOnWrite;
99 bool _progressDispatched;
100 unsigned int _progressDeltaDelayed;
102 std::vector<unsigned char> _response;
103 std::vector<unsigned char> _postData;
105 responseCodeChecker _responseCodeChecker;
107 bool _suitableResponse;
110 size_t _expectedContentSize;
111 size_t _receivedContentSize;
113 bool _continueDownload;
115 typedef std::vector< std::pair<std::string, std::string> > headers;
Definition: HttpRequestTask.h:30
Definition: HttpRequestTask.h:11
–oxgl-end–!
Definition: Actor.h:14
void getResponseSwap(std::vector< unsigned char > &)
Definition: AsyncTask.h:23