Remove support for CONNECT (#428)

Given how different `CONNECT` requests are I think its fine to require
users to handle them manually. Since they don't contain paths you
probably don't need a full routing framework 🤷

An example can be found [here](https://github.com/tokio-rs/axum/blob/main/examples/http-proxy/src/main.rs)

Fixes #418
This commit is contained in:
David Pedersen
2021-10-26 21:11:33 +00:00
committed by GitHub
parent 94330b7796
commit a2627e9084
5 changed files with 5 additions and 44 deletions
-20
View File
@@ -64,16 +64,6 @@ where
on(MethodFilter::all(), handler)
}
/// Route `CONNECT` requests to the given handler.
///
/// See [`get`] for an example.
pub fn connect<H, B, T>(handler: H) -> MethodRouter<H, B, T, MethodNotAllowed>
where
H: Handler<B, T>,
{
on(MethodFilter::CONNECT, handler)
}
/// Route `DELETE` requests to the given handler.
///
/// See [`get`] for an example.
@@ -261,16 +251,6 @@ impl<H, B, T, F> MethodRouter<H, B, T, F> {
self.on(MethodFilter::all(), handler)
}
/// Chain an additional handler that will only accept `CONNECT` requests.
///
/// See [`MethodRouter::get`] for an example.
pub fn connect<H2, T2>(self, handler: H2) -> MethodRouter<H2, B, T2, Self>
where
H2: Handler<B, T2>,
{
self.on(MethodFilter::CONNECT, handler)
}
/// Chain an additional handler that will only accept `DELETE` requests.
///
/// See [`MethodRouter::get`] for an example.
-3
View File
@@ -4,8 +4,6 @@ use http::Method;
bitflags! {
/// A filter that matches one or more HTTP methods.
pub struct MethodFilter: u16 {
/// Match `CONNECT` requests.
const CONNECT = 0b000000001;
/// Match `DELETE` requests.
const DELETE = 0b000000010;
/// Match `GET` requests.
@@ -29,7 +27,6 @@ impl MethodFilter {
#[allow(clippy::match_like_matches_macro)]
pub(crate) fn matches(self, method: &Method) -> bool {
let method = match *method {
Method::CONNECT => Self::CONNECT,
Method::DELETE => Self::DELETE,
Method::GET => Self::GET,
Method::HEAD => Self::HEAD,
+1 -1
View File
@@ -42,7 +42,7 @@ pub use self::{into_make_service::IntoMakeService, method_filter::MethodFilter,
#[doc(no_inline)]
pub use self::handler_method_router::{
any, connect, delete, get, head, on, options, patch, post, put, trace, MethodRouter,
any, delete, get, head, on, options, patch, post, put, trace, MethodRouter,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
-20
View File
@@ -130,16 +130,6 @@ where
on(MethodFilter::all(), svc)
}
/// Route `CONNECT` requests to the given service.
///
/// See [`get`] for an example.
pub fn connect<S, B>(svc: S) -> MethodRouter<S, MethodNotAllowed<S::Error>, B>
where
S: Service<Request<B>> + Clone,
{
on(MethodFilter::CONNECT, svc)
}
/// Route `DELETE` requests to the given service.
///
/// See [`get`] for an example.
@@ -319,16 +309,6 @@ impl<S, F, B> MethodRouter<S, F, B> {
self.on(MethodFilter::all(), svc)
}
/// Chain an additional service that will only accept `CONNECT` requests.
///
/// See [`MethodRouter::get`] for an example.
pub fn connect<T>(self, svc: T) -> MethodRouter<T, Self, B>
where
T: Service<Request<B>> + Clone,
{
self.on(MethodFilter::CONNECT, svc)
}
/// Chain an additional service that will only accept `DELETE` requests.
///
/// See [`MethodRouter::get`] for an example.