http_client_options.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. private:
  42. TString Host_;
  43. ui16 Port_;
  44. TDuration SocketTimeout_ = TDuration::Seconds(5);
  45. TDuration ConnectTimeout_ = TDuration::Seconds(30);
  46. };