java 的域名解释实用程序

发布于 2024-08-04 02:09:57 字数 569 浏览 2 评论 0原文

我发现自己需要一个 java 实用程序来获取完全合格的主机名,并生成 域名< /a> 从此。

在简单的情况下,这意味着将 host.company.com 转换为 company.com,但如果使用 host.subdomain.company.com<,情况会变得更加复杂。例如,/code> 或 host.company.co.uk,其中“域名”的含义有点模糊。 SLDccSLD,它变得混乱。

所以我的问题是是否有第三方库能够理解这些事情并可以给我合理的解释。

I find myself with a need for a java utility for taking a fully-qualified hostname, and producing the domain name from that.

In the simple case, that means turning host.company.com into company.com, but this gets rapidly more complicated with host.subdomain.company.com, for example, or host.company.co.uk, where the meaning of "domain name" gets a bit fuzzy. Throw in complications with the definition of SLD and ccSLD, and it gets messy.

So my question is whether there's a 3rd-party library out there that understands these things and can give me sensible interpreations.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

极致的悲 2024-08-11 02:09:57

Mozilla 定期以其他人可以解析和使用的格式维护其在浏览器中使用的 cookie 安全规则:

http:// /publicsuffix.org/

搜索 Google,可能有可以解析该列表的 Java 库,但我不知道其中任何一个的质量。

Mozilla regularly maintains the rules that it uses in its browser for cookie security in a format that can be parsed and used by others:

http://publicsuffix.org/

Searching Google, there are probably Java libraries that can parse the list, but I don't know the quality of any of them.

傻比既视感 2024-08-11 02:09:57

我认为这样的事情不存在,因为这是一个行政问题而不是技术问题,而且是一个非常多边的问题。

如果您最终自己推出,Mozilla wiki 上的此页面看起来是一个很好的起点,很多参考资料。不过看起来很头疼。只需查看日本规则即可。哎哟。

I don't think such a thing exists, since it's an adminstrative rather than technical issue, and a very multi-lateral one, at that.

If you end up rolling your own, this page on the Mozilla wiki looks like a good starting point, with lots of references. Looks like a major headache though. Just look at the rules for Japan. Ouch.

西瑶 2024-08-11 02:09:57

不确定是否出于相同的目的,我在代码中做了类似的事情。当我设置cookie时,我想将域设置为尽可能靠近顶部,因此我需要找到比公共后缀低一级的域。例如,您可以为host.div.example.com设置cookie的最高域是.example.com。对于 host.div.example.co.jp 来说,是 .example.co.jp

不幸的是,该代码不属于公共领域。这很容易做到。我基本上使用 Apache HttpClient 4 中的以下 2 个类,

org.apache.http.impl.cookie.PublicSuffixFilter
org.apache.http.impl.cookie.PublicSuffixListParser

我忘记了确切的原因,但我们必须进行一些非常小的调整。您只需从上到下遍历域,第一个有效的 cookie 域就是您所需要的。

您需要从此处下载公共后缀列表并将其包含在您的 JAR 中,

http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/src/ effective_tld_names.dat?raw=1

Not sure if it's for the same purpose, I do something similar in my code. When I set cookies, I want to set the domain as close to top as possible so I need to find the domain one-level lower than a public suffix. For example, the highest domain you can set cookie for host.div.example.com is .example.com. For host.div.example.co.jp is .example.co.jp.

Unfortunately, the code is not in the public domain. It's very easy to do. I basically use following 2 classes from Apache HttpClient 4,

org.apache.http.impl.cookie.PublicSuffixFilter
org.apache.http.impl.cookie.PublicSuffixListParser

I forgot the exact reason but we had to make some very minor tweaks. You just walk the domain from top to bottom, first valid cookie domain is what you need.

You need to download the public suffix list from here and include it in your JAR,

http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/src/effective_tld_names.dat?raw=1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文