Http.h 2.4 KB

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