在 warp 中考虑以下路由规范:
let read_book_route = warp::path!("book" / Address)
.and(warp::get())
.and(warp::any().map(move || read_book_state.clone()))
.and_then(handler::read_book_handler);
如果 URL 中提供了 non- Address
,warp 会自动返回 HTTP 405 Method Not Allowed 状态代码:
$ curl -i http://example.com/book/not_a_valid_address
HTTP/1.1 405 Method Not Allowed
content-type: text/plain; charset=utf-8
content-length: 23
date: Thu, 25 Feb 2021 06:22:20 GMT
HTTP method not allowed
为什么是 HTTP 405?为什么不是 HTTP 400 或任何其他客户端错误?