client.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #include <library/cpp/messagebus/rain_check/core/task.h>
  3. #include <library/cpp/http/misc/httpcodes.h>
  4. #include <util/generic/maybe.h>
  5. #include <util/generic/ptr.h>
  6. #include <util/generic/string.h>
  7. #include <util/system/defaults.h>
  8. #include <util/system/yassert.h>
  9. class THttpHeaders;
  10. namespace NNeh {
  11. class IProtocol;
  12. struct TResponse;
  13. }
  14. namespace NRainCheck {
  15. class THttpCallback;
  16. class THttpClientService;
  17. class THttpFuture: public TSubtaskCompletion {
  18. public:
  19. enum EError {
  20. NoError = 0,
  21. CantResolveNameError = 1,
  22. BadHttpCodeError = 2,
  23. OtherError = 100
  24. };
  25. private:
  26. friend class THttpCallback;
  27. friend class THttpClientService;
  28. public:
  29. THttpFuture();
  30. ~THttpFuture() override;
  31. bool HasHttpCode() const;
  32. bool HasResponseBody() const;
  33. ui32 GetHttpCode() const;
  34. TString GetResponseBody() const;
  35. bool HasError() const;
  36. EError GetErrorCode() const;
  37. TString GetErrorDescription() const;
  38. private:
  39. void SetDoneAndSchedule(TAutoPtr<NNeh::TResponse> response);
  40. void SetFail(EError errorCode, const TStringBuf& errorDescription);
  41. private:
  42. TTaskRunnerBase* Task;
  43. TMaybe<HttpCodes> HttpCode;
  44. THolder<NNeh::TResponse> Response;
  45. EError ErrorCode;
  46. TString ErrorDescription;
  47. };
  48. class THttpClientService {
  49. public:
  50. THttpClientService();
  51. virtual ~THttpClientService();
  52. void Send(const TString& request, THttpFuture* future);
  53. void SendPost(TString addr, const TString& data, const THttpHeaders& headers, THttpFuture* future);
  54. private:
  55. NNeh::IProtocol* const GetProtocol;
  56. NNeh::IProtocol* const FullProtocol;
  57. };
  58. }