options.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "options.h"
  2. #include <util/stream/output.h>
  3. #include <util/string/cast.h>
  4. #include <util/digest/numeric.h>
  5. #include <util/network/ip.h>
  6. #include <util/network/socket.h>
  7. #include <util/generic/hash_set.h>
  8. #include <util/generic/yexception.h>
  9. using TAddr = THttpServerOptions::TAddr;
  10. static inline TString AddrToString(const TAddr& addr) {
  11. return addr.Addr + ":" + ToString(addr.Port);
  12. }
  13. static inline TNetworkAddress ToNetworkAddr(const TString& address, ui16 port) {
  14. if (address.empty() || address == TStringBuf("*")) {
  15. return TNetworkAddress(port);
  16. }
  17. return TNetworkAddress(address, port);
  18. }
  19. void THttpServerOptions::BindAddresses(TBindAddresses& ret) const {
  20. THashSet<TString> check;
  21. for (auto addr : BindSockaddr) {
  22. if (!addr.Port) {
  23. addr.Port = Port;
  24. }
  25. const TString straddr = AddrToString(addr);
  26. if (check.find(straddr) == check.end()) {
  27. check.insert(straddr);
  28. ret.push_back(ToNetworkAddr(addr.Addr, addr.Port));
  29. }
  30. }
  31. if (ret.empty()) {
  32. ret.push_back(Host ? TNetworkAddress(Host, Port) : TNetworkAddress(Port));
  33. }
  34. }
  35. void THttpServerOptions::DebugPrint(IOutputStream& stream) const noexcept {
  36. stream << "Port: " << Port << "\n";
  37. stream << "Host: " << Host << "\n";
  38. stream << "KeepAliveEnabled: " << KeepAliveEnabled << "\n";
  39. stream << "CompressionEnabled: " << CompressionEnabled << "\n";
  40. stream << "nThreads: " << nThreads << "\n";
  41. stream << "nListenerThreads: " << nListenerThreads << "\n";
  42. stream << "MaxQueueSize: " << MaxQueueSize << "\n";
  43. stream << "nFThreads: " << nFThreads << "\n";
  44. stream << "MaxFQueueSize: " << MaxFQueueSize << "\n";
  45. stream << "MaxConnections: " << MaxConnections << "\n";
  46. stream << "MaxRequestsPerConnection: " << MaxRequestsPerConnection << "\n";
  47. stream << "ClientTimeout(ms): " << ClientTimeout.MilliSeconds() << "\n";
  48. }