1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
use http::Method;
use filter::{filter_fn, filter_fn_one, And, Filter, One};
use never::Never;
use reject::{CombineRejection, Rejection};
pub use self::v2::{
delete as delete2, get as get2, head, options, patch, post as post2, put as put2,
};
#[doc(hidden)]
#[deprecated(note = "warp::get2() is meant to replace get()")]
pub fn get<F>(filter: F) -> And<impl Filter<Extract = (), Error = Rejection> + Copy, F>
where
F: Filter + Clone,
F::Error: CombineRejection<Rejection>,
<F::Error as CombineRejection<Rejection>>::Rejection: CombineRejection<Rejection>,
{
method_is(|| &Method::GET).and(filter)
}
#[doc(hidden)]
#[deprecated(note = "warp::post2() is meant to replace post()")]
pub fn post<F>(filter: F) -> And<impl Filter<Extract = (), Error = Rejection> + Copy, F>
where
F: Filter + Clone,
F::Error: CombineRejection<Rejection>,
<F::Error as CombineRejection<Rejection>>::Rejection: CombineRejection<Rejection>,
{
method_is(|| &Method::POST).and(filter)
}
#[doc(hidden)]
#[deprecated(note = "warp::put2() is meant to replace put()")]
pub fn put<F>(filter: F) -> And<impl Filter<Extract = (), Error = Rejection> + Copy, F>
where
F: Filter + Clone,
F::Error: CombineRejection<Rejection>,
<F::Error as CombineRejection<Rejection>>::Rejection: CombineRejection<Rejection>,
{
method_is(|| &Method::PUT).and(filter)
}
#[doc(hidden)]
#[deprecated(note = "warp::delete2() is meant to replace delete()")]
pub fn delete<F>(filter: F) -> And<impl Filter<Extract = (), Error = Rejection> + Copy, F>
where
F: Filter + Clone,
F::Error: CombineRejection<Rejection>,
<F::Error as CombineRejection<Rejection>>::Rejection: CombineRejection<Rejection>,
{
method_is(|| &Method::DELETE).and(filter)
}
pub fn method() -> impl Filter<Extract = One<Method>, Error = Never> + Copy {
filter_fn_one(|route| Ok::<_, Never>(route.method().clone()))
}
fn method_is<F>(func: F) -> impl Filter<Extract = (), Error = Rejection> + Copy
where
F: Fn() -> &'static Method + Copy,
{
filter_fn(move |route| {
let method = func();
trace!("method::{:?}?: {:?}", method, route.method());
if route.method() == method {
Ok(())
} else {
Err(::reject::method_not_allowed())
}
})
}
pub mod v2 {
use http::Method;
use filter::Filter;
use reject::Rejection;
use super::method_is;
pub fn get() -> impl Filter<Extract = (), Error = Rejection> + Copy {
method_is(|| &Method::GET)
}
pub fn post() -> impl Filter<Extract = (), Error = Rejection> + Copy {
method_is(|| &Method::POST)
}
pub fn put() -> impl Filter<Extract = (), Error = Rejection> + Copy {
method_is(|| &Method::PUT)
}
pub fn delete() -> impl Filter<Extract = (), Error = Rejection> + Copy {
method_is(|| &Method::DELETE)
}
pub fn head() -> impl Filter<Extract = (), Error = Rejection> + Copy {
method_is(|| &Method::HEAD)
}
pub fn options() -> impl Filter<Extract = (), Error = Rejection> + Copy {
method_is(|| &Method::OPTIONS)
}
pub fn patch() -> impl Filter<Extract = (), Error = Rejection> + Copy {
method_is(|| &Method::PATCH)
}
}