Valid HTTP verbs
Posted | stdout
从这里 想到,fetch/xhr 可以发起哪些 http verb 呢?
python -m http.server
随手测试了下,发现连 !
,$
这种符号都可以作为 http verb,比如 fetch('/asdf', {method:"$"})
这样的请求是能发起的。于是去 chromium 搜了下 "is not a valid HTTP method"
相关的解析放在 blink/renderer/platform/network/http_parsers.cc
// See RFC 7230, Section 3.2.6.
bool IsValidHTTPToken(const String& characters) {
if (characters.empty())
return false;
for (unsigned i = 0; i < characters.length(); ++i) {
UChar c = characters[i];
if (c > 0x7F || !net::HttpUtil::IsTokenChar(c))
return false;
}
return true;
}
bool HttpUtil::IsTokenChar(char c) {
return !(c >= 0x7F || c <= 0x20 || c == '(' || c == ')' || c == '<' ||
c == '>' || c == '@' || c == ',' || c == ';' || c == ':' ||
c == '\\' || c == '"' || c == '/' || c == '[' || c == ']' ||
c == '?' || c == '=' || c == '{' || c == '}');
}
原来如此,RFC 7230呀。于是把这些字符打出来:' '.join(chr(x) for x in range(0x20, 0x7f))
! # $ % & ' * + - . 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z | ~
那还搞个屁的 RESTful 啊。直接用特殊符号一把梭。不过各种服务端框架可能不是很容易做兼容。哈哈。
Comments