美文网首页
http header横杆被替换的原因

http header横杆被替换的原因

作者: brightwang | 来源:发表于2017-05-25 18:21 被阅读79次

个人博客迁移

在用curl发送http请求的时候发现,自定义添加的header头会被特殊处理,比如  发送x-real-ip在server端接收会发现变为HTTP_X_REAL_IP,因为之前一直使用IIS,没遇到过这个问题,后来才知道这个是CGI的规范之一,如下所示http://www.ietf.org/rfc/rfc38754.1. 

Request Meta-VariablesMeta-variables contain data about the request passed from the serverto the script, and are accessed by the script in a system-definedmanner.Meta-variables are identified by case-insensitive names;there cannot be two different variables whose names differ in caseonly. Here they are shown using a canonical representation ofcapitals plus underscore ("_"). A particular system can define adifferent representation.4.1.18. Protocol-Specific Meta-VariablesThe server SHOULD set meta-variables specific to the protocol andscheme for the request. Interpretation of protocol-specificvariables depends on the protocol version in SERVER_PROTOCOL. Theserver MAY set a meta-variable with the name of the scheme to anon-NULL value if the scheme is not the same as the protocol. Thepresence of such a variable indicates to a script which scheme isused by the request.Meta-variables with names beginning with "HTTP_" contain values readfrom the client request header fields, if the protocol used is HTTP.The HTTP header field name is converted to upper case, has alloccurrences of "-" replaced with "_" and has "HTTP_" prepended togive the meta-variable name.The header data can be presented assent by the client, or can be rewritten in ways which do not changeits semantics. If multiple header fields with the same field-nameare received then the server MUST rewrite them as a single valuehaving the same semantics. Similarly, a header field that spansmultiple lines MUST be merged onto a single line. The server MUST,if necessary, change the representation of the data (for example, thecharacter set) to be appropriate for a CGI meta-variable.The server is not required to create meta-variables for all theheader fields that it receives. In particular, it SHOULD remove anyheader fields carrying authentication information, such as'Authorization'; or that are available to the script in othervariables, such as 'Content-Length' and 'Content-Type'. The serverMAY remove header fields that relate solely to client-sidecommunication issues, such as 'Connection'.如果是用nginx做web服务器,用户自定义的header,在带有下划线的情况下无法传递,因为在ngx_http_parse_header_line() 函数中

if (ch == '_') {

if (allow_underscores) {

hash = ngx_hash(hash, ch);

r->lowcase_header[i++] = ch;

i &= (NGX_HTTP_LC_HEADER_LEN - 1);

} else {

r->invalid_header = 1;

}break;}

nginx对headername的字符做了限制,默认 underscores_in_headers 为off,表示如果headername中包含下划线,则忽略掉。

 nginx中文档syntax: underscores_in_headers on | off;default:underscores_in_headers off;context: http, serverEnables or disables the use of underscores in client request header fields. When disabled, request header fields whose namescontain underscores are marked as invalid and are subject to the ignore_invalid_headers directive.Controls whether header fields with invalid names should be ignored. Valid names are composed of English letters, digits,hyphens, and possibly underscores (as controlled by theunderscores_in_headers directive).

相关文章

  • http header横杆被替换的原因

    个人博客迁移 在用curl发送http请求的时候发现,自定义添加的header头会被特殊处理,比如 发送x-rea...

  • 【前端】安全防御篇

    XSS防御 转义字符(正则替换) 转义字符(js-xss插件) CSP1》设置 HTTP Header 中的 Co...

  • HTTP Header

    HTTP Header 详解HTTP Header解析 HTTP(HyperTextTransferProtoco...

  • Fiddler查看HTTP请求Header

    1,HTTP Header介绍 HTTP 请求中有Header,HTTP 响应中也有Header。使用 Fiddl...

  • 【Nginx】配置自定义环境变量

    Nginx在处理客户端请求header头时,会将名称中的‘-’替换为‘’,所有字母变为小写,加上前缀“$http”...

  • HTTP Header

    HTTP Header 大体分为Request和Response两部分 Requests部分 Header ...

  • Http Header

    Referer 当浏览器向服务器发送请求时,带上referer告诉服务器我是从哪个页面链接过来的 X-Frame-...

  • Http Header

    什么是头信息? resource 这里只作简单解释,详细的自己看http协议。在 HTTP协议中,服务器端的回答(...

  • http header

    CSRF Token

  • HTTP header

    HTTP基于TCP协议之上的应用层协议,服务于Web浏览器和Web服务器的通信。是通用的、无状态的面向对象的协议。...

网友评论

      本文标题:http header横杆被替换的原因

      本文链接:https://www.haomeiwen.com/subject/lkpzxxtx.html