对于包含空格的方法,这是不可能的,因为请求行定义如下:
Request-Line = Method SP Request-URI SP HTTP-Version CRLF
Method被定义为 HTTP/1.1 动词或扩展方法之一,是 a token(不能包含空格)。所以服务器遇到的第一个空格标志着方法的结束。因此,方法不能包含空格。您可以对其进行百分比编码,但服务器不知道如何处理类似GET%20ME.
对于您的Class:Test: example,http 标头定义为:
message-header = field-name ":" [ field-value ]
field-name = token
field-value = *( field-content | LWS )
field-content = <the OCTETs making up the field-value
and consisting of either *TEXT or combinations
of token, separators, and quoted-string>
TEXT 定义为:
TEXT = <any OCTET except CTLs,
but including LWS>
CTL定义为:
CTL = <any US-ASCII control character
(octets 0 - 31) and DEL (127)>
所以不,您不必转义更多的冒号(58),标题行中的第一个始终被视为分隔符,因为冒号不允许在 a 中使用token。
因此,在您的示例中,字段名称是Class,而field-valueis Test: example。