http_client_options.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <util/datetime/base.h>
  3. #include <util/string/cast.h>
  4. #include <library/cpp/string_utils/url/url.h>
  5. class TSimpleHttpClientOptions {
  6. using TSelf = TSimpleHttpClientOptions;
  7. public:
  8. TSimpleHttpClientOptions() = default;
  9. explicit TSimpleHttpClientOptions(TStringBuf url) {
  10. TStringBuf scheme, host;
  11. GetSchemeHostAndPort(url, scheme, host, Port_);
  12. Host_ = url.Head(scheme.size() + host.size());
  13. }
  14. TSelf& Host(TStringBuf host) {
  15. Host_ = host;
  16. return *this;
  17. }
  18. const TString& Host() const noexcept {
  19. return Host_;
  20. }
  21. TSelf& Port(ui16 port) {
  22. Port_ = port;
  23. return *this;
  24. }
  25. ui16 Port() const noexcept {
  26. return Port_;
  27. }
  28. TSelf& SocketTimeout(TDuration timeout) {
  29. SocketTimeout_ = timeout;
  30. return *this;
  31. }
  32. TDuration SocketTimeout() const noexcept {
  33. return SocketTimeout_;
  34. }
  35. TSelf& ConnectTimeout(TDuration timeout) {
  36. ConnectTimeout_ = timeout;
  37. return *this;
  38. }
  39. TDuration ConnectTimeout() const noexcept {
  40. return ConnectTimeout_;
  41. }
  42. TSelf& MaxRedirectCount(int count) {
  43. MaxRedirectCount_ = count;
  44. return *this;
  45. }
  46. ui16 MaxRedirectCount() const noexcept {
  47. return MaxRedirectCount_;
  48. }
  49. private:
  50. TString Host_;
  51. ui16 Port_;
  52. TDuration SocketTimeout_ = TDuration::Seconds(5);
  53. TDuration ConnectTimeout_ = TDuration::Seconds(30);
  54. int MaxRedirectCount_ = INT_MAX;
  55. };