c# ASHX addHeader 导致错误
c# ASHX addHeader causing error
我正在处理一个 c# .ashx 处理程序文件并具有以下代码:
context.Response.AddHeader("HTTP Header", "200");
context.Response.AddHeader("Content", "OK");
当使用 http 协议访问此页面时,它工作正常,但如果我使用 https,它会在 chrome://net-internals/#events
中生成以下错误:
t=10983 [st=37] HTTP2_SESSION_RECV_INVALID_HEADER
--> error = "Invalid character in header name."
--> header_name = "http%20header"
--> header_value = "200"
t=10983 [st=37] HTTP2_SESSION_SEND_RST_STREAM
--> description = "Could not parse Spdy Control Frame Header."
--> error_code = "1 (PROTOCOL_ERROR)"
--> stream_id = 1
"HTTP Header" 是一个安全的 header 名字吗?我读到 "space" 在 header 中应该不是问题,实际问题是什么?
到目前为止,上述情况发生在 chrome/safari,但在 Firefox 中运行良好。
有什么建议吗?
Space 不是 header 名称中的有效字符。 HTTP 由 RFC 7230.
定义
header 字段的语法在 3.2. Header Fields
节中定义
Each header field consists of a case-insensitive field name followed
by a colon (":"), optional leading whitespace, the field value, and
optional trailing whitespace.
header-field = field-name ":" OWS field-value OWS
field-name = token
field-value = *( field-content / obs-fold )
field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
field-vchar = VCHAR / obs-text
obs-fold = CRLF 1*( SP / HTAB )
; obsolete line folding
; see Section 3.2.4
所以字段名是一个token。令牌在 3.2.6. Field Value Components
中定义
Most HTTP header field values are defined using common syntax
components (token, quoted-string, and comment) separated by
whitespace or specific delimiting characters. Delimiters are chosen
from the set of US-ASCII visual characters not allowed in a token
(DQUOTE and "(),/:;?@[\]{}").
token = 1*tchar
tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
/ "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
/ DIGIT / ALPHA
; any VCHAR, except delimiters
最后一篇在1.2. Syntax Notation
The following core rules are included by reference, as defined in
[RFC5234], Appendix B.1: ALPHA (letters), CR (carriage return), CRLF
(CR LF), CTL (controls), DIGIT (decimal 0-9), DQUOTE (double quote),
HEXDIG (hexadecimal 0-9/A-F/a-f), HTAB (horizontal tab), LF (line
feed), OCTET (any 8-bit sequence of data), SP (space), and VCHAR (any
visible [USASCII] character).
因此 header.
的名称中不允许有空格
我正在处理一个 c# .ashx 处理程序文件并具有以下代码:
context.Response.AddHeader("HTTP Header", "200");
context.Response.AddHeader("Content", "OK");
当使用 http 协议访问此页面时,它工作正常,但如果我使用 https,它会在 chrome://net-internals/#events
中生成以下错误:
t=10983 [st=37] HTTP2_SESSION_RECV_INVALID_HEADER
--> error = "Invalid character in header name."
--> header_name = "http%20header"
--> header_value = "200"
t=10983 [st=37] HTTP2_SESSION_SEND_RST_STREAM
--> description = "Could not parse Spdy Control Frame Header."
--> error_code = "1 (PROTOCOL_ERROR)"
--> stream_id = 1
"HTTP Header" 是一个安全的 header 名字吗?我读到 "space" 在 header 中应该不是问题,实际问题是什么?
到目前为止,上述情况发生在 chrome/safari,但在 Firefox 中运行良好。
有什么建议吗?
Space 不是 header 名称中的有效字符。 HTTP 由 RFC 7230.
定义header 字段的语法在 3.2. Header Fields
节中定义Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field value, and optional trailing whitespace. header-field = field-name ":" OWS field-value OWS field-name = token field-value = *( field-content / obs-fold ) field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] field-vchar = VCHAR / obs-text obs-fold = CRLF 1*( SP / HTAB ) ; obsolete line folding ; see Section 3.2.4
所以字段名是一个token。令牌在 3.2.6. Field Value Components
中定义Most HTTP header field values are defined using common syntax components (token, quoted-string, and comment) separated by whitespace or specific delimiting characters. Delimiters are chosen from the set of US-ASCII visual characters not allowed in a token (DQUOTE and "(),/:;?@[\]{}"). token = 1*tchar tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA ; any VCHAR, except delimiters
最后一篇在1.2. Syntax Notation
The following core rules are included by reference, as defined in [RFC5234], Appendix B.1: ALPHA (letters), CR (carriage return), CRLF (CR LF), CTL (controls), DIGIT (decimal 0-9), DQUOTE (double quote), HEXDIG (hexadecimal 0-9/A-F/a-f), HTAB (horizontal tab), LF (line feed), OCTET (any 8-bit sequence of data), SP (space), and VCHAR (any visible [USASCII] character).
因此 header.
的名称中不允许有空格