api: Check http method in try_from_http_request
This commit is contained in:
parent
85f152fccc
commit
06a2a27a99
@ -577,6 +577,12 @@ impl Request {
|
|||||||
fn try_from_http_request(
|
fn try_from_http_request(
|
||||||
request: #http::Request<Vec<u8>>
|
request: #http::Request<Vec<u8>>
|
||||||
) -> ::std::result::Result<Self, #ruma_api::error::FromHttpRequestError> {
|
) -> ::std::result::Result<Self, #ruma_api::error::FromHttpRequestError> {
|
||||||
|
if request.method() != #http::Method::#method {
|
||||||
|
return Err(#ruma_api::error::FromHttpRequestError::MethodMismatch {
|
||||||
|
expected: #http::Method::#method,
|
||||||
|
received: request.method().clone(),
|
||||||
|
});
|
||||||
|
}
|
||||||
#extract_request_path
|
#extract_request_path
|
||||||
#extract_request_query
|
#extract_request_query
|
||||||
#extract_request_headers
|
#extract_request_headers
|
||||||
|
@ -65,6 +65,15 @@ pub enum FromHttpRequestError {
|
|||||||
/// Deserialization failed
|
/// Deserialization failed
|
||||||
#[error("deserialization failed: {0}")]
|
#[error("deserialization failed: {0}")]
|
||||||
Deserialization(#[from] RequestDeserializationError),
|
Deserialization(#[from] RequestDeserializationError),
|
||||||
|
|
||||||
|
/// HTTP method mismatch
|
||||||
|
#[error("http method mismatch: expected {expected}, received: {received}")]
|
||||||
|
MethodMismatch {
|
||||||
|
/// expected http method
|
||||||
|
expected: http::method::Method,
|
||||||
|
/// received http method
|
||||||
|
received: http::method::Method,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error that occurred when trying to deserialize a request.
|
/// An error that occurred when trying to deserialize a request.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user