V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
httpbin - 协议调试工具
httpstatuses - 协议状态码查询
httpie - cURL-like tool for humans
Fiddler
pyKun
V2EX  ›  HTTP

request/response的header可以含有回车么?

  •  
  •   pyKun · 2013-06-08 22:35:12 +08:00 · 4644 次点击
    这是一个创建于 3974 天前的主题,其中的信息可能已经有所发展或是发生改变。
    具体的是\n
    carriage return
    (没有\t)

    在curl的文档里有提到:
    curl will make sure that each header you add/replace is sent with the proper end-of-line marker, you should thus not add that as a part of the header content: do not add newlines or carriage returns, they will only mess things up for you.

    但是我想要到http协议的依据,这样是不行的
    例如这里
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2
    有http的协议说header line是不能包括回车,必须要quote的么?
    8 条回复    1970-01-01 08:00:00 +08:00
    elden
        1
    elden  
       2013-06-08 22:45:24 +08:00
    header的字段值可以包含换行符,但后面必需跟有空格或tab,否则后面的字符就会被当做下一个字段来解析。
    pyKun
        2
    pyKun  
    OP
       2013-06-08 22:48:35 +08:00
    pyKun
        3
    pyKun  
    OP
       2013-06-08 22:49:25 +08:00
    @elden
    这个引用有链接么?
    tab是LF么?
    pyKun
        4
    pyKun  
    OP
       2013-06-08 22:51:03 +08:00
    elden
        5
    elden  
       2013-06-08 22:55:54 +08:00
    @pyKun tab是\t


    rfc2616 2.2 http://www.w3.org/Protocols/rfc2616/rfc2616.txt

    "HTTP/1.1 header field values can be folded onto multiple lines if the
    continuation line begins with a space or horizontal tab. All linear
    white space, including folding, has the same semantics as SP. A
    recipient MAY replace any linear white space with a single SP before
    interpreting the field value or forwarding the message downstream."
    elden
        6
    elden  
       2013-06-08 22:57:44 +08:00
    @pyKun 我是指\r\n或\n后面加空格
    pyKun
        7
    pyKun  
    OP
       2013-06-08 23:11:08 +08:00
    @elden
    貌似看懂点了,换行到下个文本间要加空格

    那参照django和curl,其实我的client拒绝掉包含换行的value其实也没有问题
    elden
        8
    elden  
       2013-06-09 00:20:49 +08:00
    @pyKun django不清楚,但curl是遵循rfc2616规范的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1590 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 411ms · UTC 16:59 · PVG 00:59 · LAX 09:59 · JFK 12:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.