PageRenderTime 74ms CodeModel.GetById 6ms RepoModel.GetById 3ms app.codeStats 0ms

/3rdParty/src/http/httpclient/http_client.h

https://gitlab.com/yoage/TTWinClient
C Header | 72 lines | 55 code | 8 blank | 9 comment | 0 complexity | e7150838bbb7207702a2d77a1774e86e MD5 | raw file
Possible License(s): LGPL-3.0
  1. /**
  2. * @file http_client.h
  3. * @brief Http传输类
  4. * @author xiangwangfeng <xiangwangfeng@gmail.com>
  5. * @data 2011-4-24
  6. * @website www.xiangwangfeng.com
  7. */
  8. #pragma once
  9. #include <string>
  10. #include "global_defs.h"
  11. #include "http_global.h"
  12. #include "proxy_config.h"
  13. namespace Util
  14. {
  15. class Lock;
  16. }
  17. NAMESPACE_BEGIN(Http)
  18. class ProxySocket;
  19. class HttpRequest;
  20. class HttpResponse;
  21. class IHttpPostFile;
  22. class IProgressDelegate;
  23. //Http传输类
  24. class HTTP_CLASS HttpClient
  25. {
  26. public:
  27. HttpClient(bool keep_connection = false);
  28. ~HttpClient();
  29. public:
  30. //执行Http参数方法
  31. bool execute(HttpRequest* request,HttpResponse* respone); //执行Http传输
  32. static void setProxy(const ProxyConfig* proxy_config); //设置代理
  33. HTTPERROR getErrorCode() const { return _http_error;} //返回错误码
  34. void setProgressDelegate(IProgressDelegate* delegate) { _delegate = delegate;} //设置进度委托
  35. void killSelf(); //弃用当前HttpClient
  36. private:
  37. void reset(); //重设当前HttpClient
  38. void setErrorCode(HTTPERROR http_error);
  39. bool httpGet();
  40. bool httpPost();
  41. bool getResponse();
  42. bool downloadHeader(std::string& body_header);
  43. bool downloadBody(const std::string& body_header);
  44. bool downloadFixedSizeBody(const std::string& body_header,int content_length);
  45. bool downloadChunkedBody(const std::string& body_header);
  46. bool continueToReceiveBody(std::string& body);
  47. bool sendHeader();
  48. bool sendBody();
  49. bool doMultipartPost();
  50. bool uploadFile(IHttpPostFile* post_file);
  51. void onDataReadProgress(int read_length,int total_length);
  52. DECLARE_NON_COPYABLE(HttpClient)
  53. private:
  54. ProxySocket* _proxy_socket; //支持代理的Socket类
  55. HTTPERROR _http_error; //Http传输错误码
  56. bool _keep_connection; //是否保持连接
  57. HttpRequest* _request; //Http请求方法
  58. HttpResponse* _response; //Http反馈数据
  59. IProgressDelegate* _delegate; //Http传输的委托
  60. bool _is_valid; //是否可用(如果调用了killSelf接口这个Client就弃用)
  61. Util::Lock* _is_valid_lock; //是否可用的同步锁
  62. friend class HttpThread;
  63. };
  64. NAMESPACE_END(Http)