关于OkHttp3中publicsuffixes.gz的使用

15 篇文章 1 订阅
8 篇文章 0 订阅

关于OkHttp3中publicsuffixes.gz的使用

publicsuffixes.gz中是一个压缩的文本文件,里面包含了目前公开的“公共后缀列表”。
关于“公共后缀列表”的解释如下:、

“公共后缀”是指互联网用户可以(或历史上可以)直接注册名称的公共后缀。一些公共后缀的例子是.COM, .co.uk 和 pvt.k12.ma.us。公共后缀列表是所有已知公共后缀的列表。

公共后缀列表是Mozilla的一项举措,但作为社区资源进行维护。它可用于任何软件,但最初是为满足浏览器制造商的需求而创建的。它允许浏览器,例如:

避免为高级域名后缀设置破坏隐私的“supercookies”
突出显示用户界面中域名最重要的部分
按站点准确排序历史记录条目
我们保留了一份更全面(尽管并非详尽无遗)的人员名单。如果您将其用于其他目的,我们鼓励您告诉我们,因为它有助于我们评估变更的潜在影响。为此,您可以使用psl-discuss邮件列表,我们在其中考虑与列表的维护,格式和语义相关的问题。注意:请不要使用此邮件列表来 请求修改 PSL的数据。

部分数据示例如下:

*.alces.network
*.alwaysdata.net
在线
埼玉.jp
大众汽车
大分.jp
大拿
大阪.jp
天主教

为了互联网注册管理机构的利益,可以看到列表中的部分是最新的。如果不是,他们的客户可能无法设置Cookie,或者有关其网站的数据可能显示不佳。所以我们鼓励他们通过提交修正案来维护他们的部分。

在OkHttp3中主要用到Cookie解析时,判断Domain的值,是否是url host的后缀以及是否是公共后缀。

//okhttp3

static @Nullable Cookie parse(long currentTimeMillis, HttpUrl url, String setCookie) {
    ...
        // If the domain is a suffix of the url host, it must not be a public suffix.
    if (urlHost.length() != domain.length()
        && PublicSuffixDatabase.get().getEffectiveTldPlusOne(domain) == null) {
      return null;
    }
    ...
}

该步骤就是验证了Set-Cookie中返回的Domain域名的合法性,如果和url host长度不一致(Domain:abc.com ; url host:o.abc.com),并且不在公共的域名列表中,则返回null,也就是认为该Cookie不合法,不会返回给客户端。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
E/AndroidRuntime: FATAL EXCEPTION: Thread-18 Process: com.example.read, PID: 22568 java.lang.RuntimeException: java.net.UnknownServiceException: CLEARTEXT communication to 192.168.210.113 not permitted by network security policy at com.example.read.upload_serverActivity$1.run(upload_serverActivity.java:111) at java.lang.Thread.run(Thread.java:920) Caused by: java.net.UnknownServiceException: CLEARTEXT communication to 192.168.210.113 not permitted by network security policy at okhttp3.internal.connection.RealRoutePlanner.planConnectToRoute$okhttp(RealRoutePlanner.kt:195) at okhttp3.internal.connection.RealRoutePlanner.planConnect(RealRoutePlanner.kt:152) at okhttp3.internal.connection.RealRoutePlanner.plan(RealRoutePlanner.kt:67) at okhttp3.internal.connection.FastFallbackExchangeFinder.launchTcpConnect(FastFallbackExchangeFinder.kt:118) at okhttp3.internal.connection.FastFallbackExchangeFinder.find(FastFallbackExchangeFinder.kt:62) at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:267) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:84) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:65) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:205) at okhttp3.internal.connection.RealCall.execute(RealCall.kt:158) at com.example.read.upload_serverActivity$1.run(upload_serverActivity.java:106) at java.lang.Thread.run(Thread.java:920) 怎么解决
最新发布
05-29

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值