我目前正在处理一些针对我的Ruby应用程序的POST请求,并且收到了与wrong status line
相关的错误。查看文档,如果匹配以下正则表达式,则抛出异常:
def read_status_line(sock)
str = sock.readline
m = /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?\z/in.match(str) or
raise Net::HTTPBadResponse, "wrong status line: #{str.dump}"
m.captures
end
我很好奇正规法师实际上想要匹配什么?
/\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?\z/in.match(str)
答案 0 :(得分:0)
这是直接来自section 6 of RFC2616的HTTP响应标头:
Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
换句话说,比如:
HTTP/1.1 200 OK
或者也许:
HTTP/1.1 302 Moved Temporarily