NIM Tools API  5.5.0
nim_tools_http_cpp.h
Go to the documentation of this file.
1 
8 #ifndef _NIM_TOOLS_SDK_CPP_HTTP_H_
9 #define _NIM_TOOLS_SDK_CPP_HTTP_H_
10 
11 #include <windows.h>
12 #include <string>
13 #include <functional>
14 #include <map>
15 #include "..\..\nim_tools_c_sdk\http\nim_tools_http_def.h"
16 
21 namespace nim_http
22 {
23 
28 typedef std::function<void(bool, int)> CompletedCallback;
29 
35 typedef std::function<void(bool, int, const std::string&)> ResponseCallback;
36 
43 typedef std::function<void(double, double, double, double)> ProgressCallback;
44 
49 typedef std::function<void(double, double)> SpeedCallback;
50 
57 typedef std::function<void(double, double, double, double)> TransferCallback;
58 
60 
66 void Init(const std::wstring &dll_path = L"");
67 
72 void Uninit();
73 
79 void InitLog(const std::string& log_file_path);
80 
85 bool IsInitLog();
86 
96 void SetGlobalProxy(NIMProxyType type, const std::string& host, short port, const std::string& user, const std::string& pass);
97 
103 HttpRequestID PostRequest(const HttpRequest& http_request);
104 
110 void RemoveRequest(HttpRequestID http_request_id);
111 
117 std::string GetResponseHead(HttpRequestID http_request_id);
118 
123 {
124 public:
135  HttpRequest(const std::string& url, const std::string& download_file_path,
136  const CompletedCallback& complete_cb, const ProgressCallback& progress_cb = ProgressCallback(),
137  const SpeedCallback& speed_cb = SpeedCallback(), const TransferCallback& transfer_cb = TransferCallback());
138 
150  HttpRequest(const std::string& url, const std::string& download_file_path,
151  __int64 range_start, const CompletedCallback& complete_cb, const ProgressCallback& progress_cb = ProgressCallback(),
152  const SpeedCallback& speed_cb = SpeedCallback(), const TransferCallback& transfer_cb = TransferCallback());
153 
165  HttpRequest(const std::string& url, const char* post_body, size_t post_body_size,
166  const ResponseCallback& response_cb, const ProgressCallback& progress_cb = ProgressCallback(),
167  const SpeedCallback& speed_cb = SpeedCallback(), const TransferCallback& transfer_cb = TransferCallback());
168 
175  void AddHeader(const std::string& key, const std::string& value);
176 
182  void AddHeader(const std::map<std::string, std::string>& headers_map);
183 
188  void SetMethodAsPost();
189 
195  void SetTimeout(int timeout_ms);
196 
203  void SetLowSpeed(int low_speed_limit, int low_speed_time);
204 
214  void SetProxy(NIMProxyType type, const std::string& host, short port, const std::string& user, const std::string& pass);
215 
216 private:
217  static void CompletedCallbackWrapper(const void* user_data, bool is_ok, int response_code);
218  static void ResponseCallbackWrapper(const void* user_data, bool is_ok, int response_code, const char* content);
219  static void ProgressCallbackWrapper(const void* user_data, double upload_size, double uploaded_size, double download_size, double downloaded_size);
220  static void SpeedCallbackWrapper(const void* user_data, double upload_speed, double download_speed);
221  static void TransferCallbackWrapper(const void* user_data, double actual_upload_size, double upload_speed, double actual_download_size, double download_speed);
222 private:
223  friend int PostRequest(const HttpRequest& http_request);
224  HttpRequestHandle http_reuqest_handle_;
225 };
226 
227 }
228 
229 
230 #endif // _NIM_TOOLS_SDK_CPP_HTTP_H_
void * HttpRequestHandle
Definition: nim_tools_http_def.h:27
HttpRequestID PostRequest(const HttpRequest &http_request)
std::function< void(double, double, double, double)> TransferCallback
Definition: nim_tools_http_cpp.h:57
void SetProxy(NIMProxyType type, const std::string &host, short port, const std::string &user, const std::string &pass)
NIM HTTP提供的http传输相关接口
Definition: nim_tools_http_cpp.h:122
void SetTimeout(int timeout_ms)
void Uninit()
std::function< void(bool, int)> CompletedCallback
Definition: nim_tools_http_cpp.h:28
HttpRequest(const std::string &url, const std::string &download_file_path, const CompletedCallback &complete_cb, const ProgressCallback &progress_cb=ProgressCallback(), const SpeedCallback &speed_cb=SpeedCallback(), const TransferCallback &transfer_cb=TransferCallback())
void SetLowSpeed(int low_speed_limit, int low_speed_time)
void SetGlobalProxy(NIMProxyType type, const std::string &host, short port, const std::string &user, const std::string &pass)
void Init(const std::wstring &dll_path=L"")
Definition: nim_tools_http_cpp.h:59
std::function< void(bool, int, const std::string &)> ResponseCallback
Definition: nim_tools_http_cpp.h:35
void InitLog(const std::string &log_file_path)
NIMProxyType
Definition: nim_tools_http_def.h:15
NIM提供的HTTP工具
std::string GetResponseHead(HttpRequestID http_request_id)
std::function< void(double, double, double, double)> ProgressCallback
Definition: nim_tools_http_cpp.h:43
int HttpRequestID
Definition: nim_tools_http_def.h:32
std::function< void(double, double)> SpeedCallback
Definition: nim_tools_http_cpp.h:49
bool IsInitLog()
void AddHeader(const std::string &key, const std::string &value)
void RemoveRequest(HttpRequestID http_request_id)