Skip to content

Commit bb8705b

Browse files
authored
feat(method): add QUERY method (#798)
1 parent 82db5b8 commit bb8705b

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/method.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ enum Inner {
6060
Trace,
6161
Connect,
6262
Patch,
63+
Query,
6364
// If the extension is short enough, store it inline
6465
ExtensionInline(InlineExtension),
6566
// Otherwise, allocate it
@@ -94,6 +95,9 @@ impl Method {
9495
/// TRACE
9596
pub const TRACE: Method = Method(Trace);
9697

98+
/// QUERY
99+
pub const QUERY: Method = Method(Query);
100+
97101
/// Converts a slice of bytes to an HTTP method.
98102
pub fn from_bytes(src: &[u8]) -> Result<Method, InvalidMethod> {
99103
match src.len() {
@@ -111,6 +115,7 @@ impl Method {
111115
5 => match src {
112116
b"PATCH" => Ok(Method(Patch)),
113117
b"TRACE" => Ok(Method(Trace)),
118+
b"QUERY" => Ok(Method(Query)),
114119
_ => Method::extension_inline(src),
115120
},
116121
6 => match src {
@@ -146,7 +151,7 @@ impl Method {
146151
/// See [the spec](https://tools.ietf.org/html/rfc7231#section-4.2.1)
147152
/// for more words.
148153
pub fn is_safe(&self) -> bool {
149-
matches!(self.0, Get | Head | Options | Trace)
154+
matches!(self.0, Get | Head | Options | Trace | Query)
150155
}
151156

152157
/// Whether a method is considered "idempotent", meaning the request has
@@ -174,6 +179,7 @@ impl Method {
174179
Trace => "TRACE",
175180
Connect => "CONNECT",
176181
Patch => "PATCH",
182+
Query => "QUERY",
177183
ExtensionInline(ref inline) => inline.as_str(),
178184
ExtensionAllocated(ref allocated) => allocated.as_str(),
179185
}
@@ -466,6 +472,7 @@ mod test {
466472
assert!(Method::DELETE.is_idempotent());
467473
assert!(Method::HEAD.is_idempotent());
468474
assert!(Method::TRACE.is_idempotent());
475+
assert!(Method::QUERY.is_idempotent());
469476

470477
assert!(!Method::POST.is_idempotent());
471478
assert!(!Method::CONNECT.is_idempotent());

src/request.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ impl Request<()> {
407407
{
408408
Builder::new().method(Method::TRACE).uri(uri)
409409
}
410+
411+
// This is purposefully excluded because of potential conflict with the
412+
// URI query.
413+
// pub fn query() -> Builder
410414
}
411415

412416
impl<T> Request<T> {

0 commit comments

Comments
 (0)