http_client.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include "fwd.h"
  3. #include <yt/cpp/mapreduce/interface/fwd.h>
  4. #include <util/datetime/base.h>
  5. #include <util/generic/maybe.h>
  6. #include <util/generic/string.h>
  7. #include <util/stream/fwd.h>
  8. #include <memory>
  9. namespace NYT::NHttpClient {
  10. ////////////////////////////////////////////////////////////////////////////////
  11. struct THttpConfig
  12. {
  13. TDuration SocketTimeout = TDuration::Zero();
  14. };
  15. ////////////////////////////////////////////////////////////////////////////////
  16. class IHttpResponse
  17. {
  18. public:
  19. virtual ~IHttpResponse() = default;
  20. virtual int GetStatusCode() = 0;
  21. virtual IInputStream* GetResponseStream() = 0;
  22. virtual TString GetResponse() = 0;
  23. virtual TString GetRequestId() const = 0;
  24. };
  25. class IHttpRequest
  26. {
  27. public:
  28. virtual ~IHttpRequest() = default;
  29. virtual IOutputStream* GetStream() = 0;
  30. virtual IHttpResponsePtr Finish() = 0;
  31. };
  32. class IHttpClient
  33. {
  34. public:
  35. virtual ~IHttpClient() = default;
  36. virtual IHttpResponsePtr Request(const TString& url, const TString& requestId, const THttpConfig& config, const THttpHeader& header, TMaybe<TStringBuf> body = {}) = 0;
  37. virtual IHttpResponsePtr Request(const TString& url, const TString& requestId, const THttpHeader& header, TMaybe<TStringBuf> body = {})
  38. {
  39. return Request(url, requestId, /*config*/ {}, header, body);
  40. }
  41. virtual IHttpRequestPtr StartRequest(const TString& url, const TString& requestId, const THttpConfig& config, const THttpHeader& header) = 0;
  42. virtual IHttpRequestPtr StartRequest(const TString& url, const TString& requestId, const THttpHeader& header)
  43. {
  44. return StartRequest(url, requestId, /*config*/ {}, header);
  45. }
  46. };
  47. ////////////////////////////////////////////////////////////////////////////////
  48. IHttpClientPtr CreateDefaultHttpClient();
  49. IHttpClientPtr CreateCoreHttpClient(bool useTLS, const TConfigPtr& config);
  50. ////////////////////////////////////////////////////////////////////////////////
  51. } // namespace NYT::NHttpClient