Http.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. private:
  38. UnicodeString FURL;
  39. UnicodeString FProxyHost;
  40. int FProxyPort;
  41. RawByteString FResponse;
  42. __int64 FResponseLimit;
  43. std::unique_ptr<Exception> FException;
  44. THttpDownloadEvent FOnDownload;
  45. THttpErrorEvent FOnError;
  46. UnicodeString FHostName;
  47. UnicodeString FCertificateError;
  48. TStrings * FRequestHeaders;
  49. TStrings * FResponseHeaders;
  50. static int NeonBodyReader(void * UserData, const char * Buf, size_t Len);
  51. int NeonBodyReaderImpl(const char * Buf, size_t Len);
  52. void SendRequest(const char * Method, const UnicodeString & Request);
  53. UnicodeString GetResponse();
  54. __int64 GetResponseLength();
  55. void InitSslSession(ssl_st * Ssl, ne_session_s * Session);
  56. static int NeonServerSSLCallback(void * UserData, int Failures, const ne_ssl_certificate_s * Certificate);
  57. int NeonServerSSLCallbackImpl(int Failures, const ne_ssl_certificate_s * Certificate);
  58. };
  59. //---------------------------------------------------------------------------
  60. #endif