options.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "options.h"
  2. #include <util/string/cast.h>
  3. #include <util/digest/numeric.h>
  4. #include <util/network/ip.h>
  5. #include <util/network/socket.h>
  6. #include <util/generic/hash_set.h>
  7. #include <util/generic/yexception.h>
  8. using TAddr = THttpServerOptions::TAddr;
  9. static inline TString AddrToString(const TAddr& addr) {
  10. return addr.Addr + ":" + ToString(addr.Port);
  11. }
  12. static inline TNetworkAddress ToNetworkAddr(const TString& address, ui16 port) {
  13. if (address.empty() || address == TStringBuf("*")) {
  14. return TNetworkAddress(port);
  15. }
  16. return TNetworkAddress(address, port);
  17. }
  18. void THttpServerOptions::BindAddresses(TBindAddresses& ret) const {
  19. THashSet<TString> check;
  20. for (auto addr : BindSockaddr) {
  21. if (!addr.Port) {
  22. addr.Port = Port;
  23. }
  24. const TString straddr = AddrToString(addr);
  25. if (check.find(straddr) == check.end()) {
  26. check.insert(straddr);
  27. ret.push_back(ToNetworkAddr(addr.Addr, addr.Port));
  28. }
  29. }
  30. if (ret.empty()) {
  31. ret.push_back(Host ? TNetworkAddress(Host, Port) : TNetworkAddress(Port));
  32. }
  33. }