Skip to content

feat: allow ".local" suffixed addresses for inspector #28470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/inspector_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,8 @@ class HttpHandler : public ProtocolHandler {
std::string host = TrimPort(host_with_port);
return host.empty() || IsIPAddress(host)
|| node::StringEqualNoCase(host.data(), "localhost")
|| node::StringEqualNoCase(host.data(), "localhost6");
|| node::StringEqualNoCase(host.data(), "localhost6")
|| node::StringEndsWith(host.data(), ".local");
}

bool parsing_value_;
Expand Down
10 changes: 10 additions & 0 deletions src/util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ bool StringEqualNoCaseN(const char* a, const char* b, size_t length) {
return true;
}

bool StringEndsWith(const char* str, const char* suffix) {
if (!str || !suffix)
return false;
size_t lenstr = strlen(str);
size_t lensuffix = strlen(suffix);
if (lensuffix > lenstr)
return false;
return StringEqualNoCaseN(str + lenstr - lensuffix, suffix, lensuffix);
}

template <typename T>
inline T MultiplyWithOverflowCheck(T a, T b) {
auto ret = a * b;
Expand Down
3 changes: 3 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ inline bool StringEqualNoCase(const char* a, const char* b);
// strncasecmp() is locale-sensitive. Use StringEqualNoCaseN() instead.
inline bool StringEqualNoCaseN(const char* a, const char* b, size_t length);

// tests if str ends with the given suffix
inline bool StringEndsWith(const char* str, const char* suffix);

// Allocates an array of member type T. For up to kStackStorageSize items,
// the stack is used, otherwise malloc().
template <typename T, size_t kStackStorageSize = 1024>
Expand Down