api: Check http method in try_from_http_request

This commit is contained in:
Akshay 2021-04-09 20:51:05 +05:30 committed by GitHub
parent 85f152fccc
commit 06a2a27a99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -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

View File

@ -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.