Http.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. bool IsCertificateError();
  23. __property UnicodeString URL = { read = FURL, write = FURL };
  24. __property UnicodeString ProxyHost = { read = FProxyHost, write = FProxyHost };
  25. __property int ProxyPort = { read = FProxyPort, write = FProxyPort };
  26. __property TStrings * RequestHeaders = { read = FRequestHeaders, write = FRequestHeaders };
  27. __property UnicodeString Response = { read = GetResponse };
  28. __property RawByteString ResponseRaw = { read = FResponse };
  29. __property TStrings * ResponseHeaders = { read = FResponseHeaders };
  30. __property __int64 ResponseLength = { read = GetResponseLength };
  31. __property __int64 ResponseLimit = { read = FResponseLimit, write = FResponseLimit };
  32. __property THttpDownloadEvent OnDownload = { read = FOnDownload, write = FOnDownload};
  33. private:
  34. UnicodeString FURL;
  35. UnicodeString FProxyHost;
  36. int FProxyPort;
  37. RawByteString FResponse;
  38. __int64 FResponseLimit;
  39. std::unique_ptr<Exception> FException;
  40. THttpDownloadEvent FOnDownload;
  41. UnicodeString FHostName;
  42. UnicodeString FCertificateError;
  43. TStrings * FRequestHeaders;
  44. TStrings * FResponseHeaders;
  45. static int NeonBodyReader(void * UserData, const char * Buf, size_t Len);
  46. int NeonBodyReaderImpl(const char * Buf, size_t Len);
  47. void SendRequest(const char * Method, const UnicodeString & Request);
  48. UnicodeString GetResponse();
  49. __int64 GetResponseLength();
  50. static void InitSslSession(ssl_st * Ssl, ne_session_s * Session);
  51. static int NeonServerSSLCallback(void * UserData, int Failures, const ne_ssl_certificate_s * Certificate);
  52. int NeonServerSSLCallbackImpl(int Failures, const ne_ssl_certificate_s * Certificate);
  53. };
  54. //---------------------------------------------------------------------------
  55. #endif