1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-20 06:54:46 +00:00

Add path matchers that are more capable than gotham's stock ones

This commit is contained in:
msrd0 2020-04-25 18:31:57 +00:00
parent d08d9bea8c
commit 4ce53bc361
7 changed files with 435 additions and 16 deletions

View file

@ -1,4 +1,5 @@
use crate::{
matcher::{AcceptHeaderMatcher, ContentTypeMatcher},
resource::*,
result::{ResourceError, ResourceResult, Response},
RequestBody,
@ -15,11 +16,7 @@ use gotham::{
router::{
builder::*,
non_match::RouteNonMatch,
route::matcher::{
content_type::ContentTypeHeaderRouteMatcher,
AcceptHeaderRouteMatcher,
RouteMatcher
}
route::matcher::RouteMatcher
},
state::{FromState, State}
};
@ -253,7 +250,7 @@ fn delete_handler<Handler : ResourceDelete>(state : State) -> Pin<Box<HandlerFut
#[derive(Clone)]
struct MaybeMatchAcceptHeader
{
matcher : Option<AcceptHeaderRouteMatcher>
matcher : Option<AcceptHeaderMatcher>
}
impl RouteMatcher for MaybeMatchAcceptHeader
@ -276,7 +273,7 @@ impl From<Option<Vec<Mime>>> for MaybeMatchAcceptHeader
types => types
};
Self {
matcher: types.map(AcceptHeaderRouteMatcher::new)
matcher: types.map(AcceptHeaderMatcher::new)
}
}
}
@ -284,7 +281,7 @@ impl From<Option<Vec<Mime>>> for MaybeMatchAcceptHeader
#[derive(Clone)]
struct MaybeMatchContentTypeHeader
{
matcher : Option<ContentTypeHeaderRouteMatcher>
matcher : Option<ContentTypeMatcher>
}
impl RouteMatcher for MaybeMatchContentTypeHeader
@ -303,7 +300,7 @@ impl From<Option<Vec<Mime>>> for MaybeMatchContentTypeHeader
fn from(types : Option<Vec<Mime>>) -> Self
{
Self {
matcher: types.map(ContentTypeHeaderRouteMatcher::new)
matcher: types.map(ContentTypeMatcher::new).map(ContentTypeMatcher::allow_no_type)
}
}
}