mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-08 00:00:24 +02:00
Remove take_* methods from RequestParts for Version, Method, and Uri (#151)
* Remove `RequestParts::take_method` * Remove `RequestParts::take_uri` * Remove `RequestParts::take_version`
This commit is contained in:
@@ -4,6 +4,7 @@ use bytes::Bytes;
|
||||
use futures_util::stream::Stream;
|
||||
use http::{HeaderMap, Method, Request, Uri, Version};
|
||||
use std::{
|
||||
convert::Infallible,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
@@ -18,21 +19,15 @@ where
|
||||
|
||||
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
|
||||
let RequestParts {
|
||||
method,
|
||||
uri,
|
||||
version,
|
||||
method: _,
|
||||
uri: _,
|
||||
version: _,
|
||||
headers,
|
||||
extensions,
|
||||
body,
|
||||
} = req;
|
||||
|
||||
let all_parts = method
|
||||
.as_ref()
|
||||
.zip(version.as_ref())
|
||||
.zip(uri.as_ref())
|
||||
.zip(extensions.as_ref())
|
||||
.zip(body.as_ref())
|
||||
.zip(headers.as_ref());
|
||||
let all_parts = extensions.as_ref().zip(body.as_ref()).zip(headers.as_ref());
|
||||
|
||||
if all_parts.is_some() {
|
||||
Ok(req.into_request())
|
||||
@@ -60,10 +55,10 @@ impl<B> FromRequest<B> for Method
|
||||
where
|
||||
B: Send,
|
||||
{
|
||||
type Rejection = MethodAlreadyExtracted;
|
||||
type Rejection = Infallible;
|
||||
|
||||
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
|
||||
req.take_method().ok_or(MethodAlreadyExtracted)
|
||||
Ok(req.method().clone())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,10 +67,10 @@ impl<B> FromRequest<B> for Uri
|
||||
where
|
||||
B: Send,
|
||||
{
|
||||
type Rejection = UriAlreadyExtracted;
|
||||
type Rejection = Infallible;
|
||||
|
||||
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
|
||||
req.take_uri().ok_or(UriAlreadyExtracted)
|
||||
Ok(req.uri().clone())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,10 +79,10 @@ impl<B> FromRequest<B> for Version
|
||||
where
|
||||
B: Send,
|
||||
{
|
||||
type Rejection = VersionAlreadyExtracted;
|
||||
type Rejection = Infallible;
|
||||
|
||||
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
|
||||
req.take_version().ok_or(VersionAlreadyExtracted)
|
||||
Ok(req.version())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user