http_client_options.h 1.5 KB

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