Http.h 2.7 KB

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