V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xiangyuecn
V2EX  ›  Android

WebResourceResponse 谷歌也请临时工写代码吗

  •  
  •   xiangyuecn · 2019-09-17 17:06:11 +08:00 · 5848 次点击
    这是一个创建于 1654 天前的主题,其中的信息可能已经有所发展或是发生改变。

    吐槽贴,基于事实,不喜可喷

    WTF

    Android 的 WebView 本来不想做拦截请求,但当前需求必须要用到 shouldInterceptRequest 去处理请求。。。

    看到 WebResourceResponse 这个比玩意就想骂街😂

    过时的那个短方法就不提了,废柴一个。

    API 21 才增加的第二个方法,看起来很强大,但稍微用过 HTTP 响应头也不会写出这种接口代码。。。

    响应头居然是<String, String>,我至今不知道如何填写这个比玩意,每次看到这货就想骂,不提供多值特性也至少留个数组<String, List<string>>啊,提供这个接口的人非蠢即坏。没办法只能从多值里面强制取第一个,其余的全部丢弃(懒得研究用,还是;还是什么鸟规范去拼接后是否能够被正常使用)。</string>

    另外细想,已经有了响应头参数了,还要 mime 和 encoding 参数做吊,纯粹多余,读一下 content-type 响应头就会烂 jj 吗(如果会,那加这两个参数可以原谅😂)


    猜想当时 Google 内部加这个方法时是这样的:

    [boss] 我们在 Android 5.0 上给 WebResourceResponse 升级一下,多开放点,让那群 2B 开心开心

    [临时工] ok boss,好的 boss,马上搞 boss

    ...

    [临时工] 我加了状态码和响应头

    [临时工] HTTP 响应的要素都齐全了,该有的有了不该有的也有了,绝对吊炸天

    [boss] 八错八错,上线

    ...

    [我] 一棍子呼死你们这群王八犊子


    纯吐槽,仅供娱乐

    7 条回复    2019-09-21 15:37:31 +08:00
    yegle
        1
    yegle  
       2019-09-18 03:39:10 +08:00
    等等,第一个没有被 deprecate 啊

    第二个,你看了 RFC 没? www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
    yegle
        2
    yegle  
       2019-09-18 03:39:55 +08:00
    其中关键的部分:

    Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, and thus a proxy MUST NOT change the order of these field values when a message is forwarded.
    xiangyuecn
        3
    xiangyuecn  
    OP
       2019-09-18 08:12:01 +08:00
    @yegle 我信你个鬼 rfc 这个地方坏的很😂。。。代码没有写完,就不在 Android 里面测试了,不过猜测 99.99% Google 的那个临时工更加不会去对响应头 value 内的格式进行深度处理。

    `by appending each subsequent field-value to the first, each separated by a comma`,浏览器里面跑一边看看能否识别用逗号拼接的:




    另外搞笑的是 URLConnection 获得的响应头是 Map<String,List<String>>结构,chorme 也是谷歌自家的玩意,综合起来可笑不可笑
    xuanbg
        4
    xuanbg  
       2019-09-18 08:55:24 +08:00
    头部数据还是是对象?楼主怕是在做 http 5G 的梦吧
    no1xsyzy
        5
    no1xsyzy  
       2019-09-18 09:10:32 +08:00
    @xuanbg 有哪个语言的 http 库头部数据不是对象的吗?
    1. 这语言根本没人用
    2. 这语言没有对象只有字符串
    3. 第二天就有人写个封装
    xiangyuecn
        6
    xiangyuecn  
    OP
       2019-09-18 09:55:19 +08:00
    @xuanbg 哈哈,数组也是可以的,只要能把数据完整的表达😏
    1. ["k1: v1", "k2: v2"]
    2. ["k1","v1", "k2","v2"]
    3. "k1: v1 \n k2: v2" 没区别😂
    4. 5G 锟斤拷烫烫烫
    yankebupt
        7
    yankebupt  
       2019-09-21 15:37:31 +08:00
    这个坑估计迟早要亲自踩,先 mark 一下......
    话说往 header 里面塞乱七八糟东西还各有各的格式这股风气怎么刮起来的...是 RESTful 还是 ws 干的,接触少还不知道影响有多大。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1037 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 22:29 · PVG 06:29 · LAX 15:29 · JFK 18:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.