Http.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //---------------------------------------------------------------------------
  2. #ifndef HttpH
  3. #define HttpH
  4. //---------------------------------------------------------------------------
  5. #include <memory>
  6. //---------------------------------------------------------------------------
  7. struct ne_session_s;
  8. struct ne_request_s;
  9. struct ne_ssl_certificate_s;
  10. struct ssl_st;
  11. //---------------------------------------------------------------------------
  12. class THttp;
  13. typedef void __fastcall (__closure * THttpDownloadEvent)(THttp * Sender, __int64 Size, bool & Cancel);
  14. //---------------------------------------------------------------------------
  15. class THttp
  16. {
  17. public:
  18. THttp();
  19. ~THttp();
  20. void Get();
  21. void Post(const UnicodeString & Request);
  22. __property UnicodeString URL = { read = FURL, write = FURL };
  23. __property UnicodeString ProxyHost = { read = FProxyHost, write = FProxyHost };
  24. __property int ProxyPort = { read = FProxyPort, write = FProxyPort };
  25. __property UnicodeString Response = { read = GetResponse };
  26. __property RawByteString ResponseRaw = { read = FResponse };
  27. __property __int64 ResponseLength = { read = GetResponseLength };
  28. __property __int64 ResponseLimit = { read = FResponseLimit, write = FResponseLimit };
  29. __property THttpDownloadEvent OnDownload = { read = FOnDownload, write = FOnDownload};
  30. private:
  31. UnicodeString FURL;
  32. UnicodeString FProxyHost;
  33. int FProxyPort;
  34. RawByteString FResponse;
  35. __int64 FResponseLimit;
  36. std::unique_ptr<Exception> FException;
  37. THttpDownloadEvent FOnDownload;
  38. UnicodeString FHostName;
  39. UnicodeString FCertificateError;
  40. static int NeonBodyReader(void * UserData, const char * Buf, size_t Len);
  41. int NeonBodyReaderImpl(const char * Buf, size_t Len);
  42. void SendRequest(const char * Method, const UnicodeString & Request);
  43. UnicodeString GetResponse();
  44. __int64 GetResponseLength();
  45. static void InitSslSession(ssl_st * Ssl, ne_session_s * Session);
  46. static int NeonServerSSLCallback(void * UserData, int Failures, const ne_ssl_certificate_s * Certificate);
  47. int NeonServerSSLCallbackImpl(int Failures, const ne_ssl_certificate_s * Certificate);
  48. };
  49. //---------------------------------------------------------------------------
  50. #endif