Http.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. typedef void __fastcall (__closure * THttpErrorEvent)(THttp * Sender, int Status, const UnicodeString & Message);
  15. //---------------------------------------------------------------------------
  16. extern const int BasicHttpResponseLimit;
  17. //---------------------------------------------------------------------------
  18. class THttp
  19. {
  20. public:
  21. THttp();
  22. ~THttp();
  23. void Get();
  24. void Post(const UnicodeString & Request);
  25. bool IsCertificateError();
  26. __property UnicodeString URL = { read = FURL, write = FURL };
  27. __property UnicodeString ProxyHost = { read = FProxyHost, write = FProxyHost };
  28. __property int ProxyPort = { read = FProxyPort, write = FProxyPort };
  29. __property TStrings * RequestHeaders = { read = FRequestHeaders, write = FRequestHeaders };
  30. __property UnicodeString Response = { read = GetResponse };
  31. __property RawByteString ResponseRaw = { read = FResponse };
  32. __property TStrings * ResponseHeaders = { read = FResponseHeaders };
  33. __property __int64 ResponseLength = { read = GetResponseLength };
  34. __property __int64 ResponseLimit = { read = FResponseLimit, write = FResponseLimit };
  35. __property THttpDownloadEvent OnDownload = { read = FOnDownload, write = FOnDownload };
  36. __property THttpErrorEvent OnError = { read = FOnError, write = FOnError };
  37. __property UnicodeString Certificate = { read = FCertificate, write = FCertificate };
  38. private:
  39. UnicodeString FURL;
  40. UnicodeString FProxyHost;
  41. int FProxyPort;
  42. RawByteString FResponse;
  43. __int64 FResponseLimit;
  44. std::unique_ptr<Exception> FException;
  45. THttpDownloadEvent FOnDownload;
  46. THttpErrorEvent FOnError;
  47. UnicodeString FHostName;
  48. UnicodeString FCertificateError;
  49. TStrings * FRequestHeaders;
  50. TStrings * FResponseHeaders;
  51. UnicodeString FCertificate;
  52. static int NeonBodyReader(void * UserData, const char * Buf, size_t Len);
  53. int NeonBodyReaderImpl(const char * Buf, size_t Len);
  54. void SendRequest(const char * Method, const UnicodeString & Request);
  55. UnicodeString GetResponse();
  56. __int64 GetResponseLength();
  57. void InitSslSession(ssl_st * Ssl, ne_session_s * Session);
  58. static int NeonServerSSLCallback(void * UserData, int Failures, const ne_ssl_certificate_s * Certificate);
  59. int NeonServerSSLCallbackImpl(int Failures, const ne_ssl_certificate_s * Certificate);
  60. };
  61. //---------------------------------------------------------------------------
  62. #endif