Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ enum Inner {
Trace,
Connect,
Patch,
Query,
// If the extension is short enough, store it inline
ExtensionInline(InlineExtension),
// Otherwise, allocate it
Expand Down Expand Up @@ -94,6 +95,9 @@ impl Method {
/// TRACE
pub const TRACE: Method = Method(Trace);

/// QUERY
pub const QUERY: Method = Method(Query);

/// Converts a slice of bytes to an HTTP method.
pub fn from_bytes(src: &[u8]) -> Result<Method, InvalidMethod> {
match src.len() {
Expand All @@ -111,6 +115,7 @@ impl Method {
5 => match src {
b"PATCH" => Ok(Method(Patch)),
b"TRACE" => Ok(Method(Trace)),
b"QUERY" => Ok(Method(Query)),
_ => Method::extension_inline(src),
},
6 => match src {
Expand Down Expand Up @@ -146,7 +151,7 @@ impl Method {
/// See [the spec](https://tools.ietf.org/html/rfc7231#section-4.2.1)
/// for more words.
pub fn is_safe(&self) -> bool {
matches!(self.0, Get | Head | Options | Trace)
matches!(self.0, Get | Head | Options | Trace | Query)
}

/// Whether a method is considered "idempotent", meaning the request has
Expand Down Expand Up @@ -174,6 +179,7 @@ impl Method {
Trace => "TRACE",
Connect => "CONNECT",
Patch => "PATCH",
Query => "QUERY",
ExtensionInline(ref inline) => inline.as_str(),
ExtensionAllocated(ref allocated) => allocated.as_str(),
}
Expand Down Expand Up @@ -466,6 +472,7 @@ mod test {
assert!(Method::DELETE.is_idempotent());
assert!(Method::HEAD.is_idempotent());
assert!(Method::TRACE.is_idempotent());
assert!(Method::QUERY.is_idempotent());

assert!(!Method::POST.is_idempotent());
assert!(!Method::CONNECT.is_idempotent());
Expand Down
4 changes: 4 additions & 0 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ impl Request<()> {
{
Builder::new().method(Method::TRACE).uri(uri)
}

// This is purposefully excluded because of potential conflict with the
// URI query.
// pub fn query() -> Builder
Comment on lines +411 to +413

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit late here, but could this be added as perhaps http_query if there is concern about a conflict?

For what it's worth, I don't find the conflict too worrisome: if there were a method to get the URI query, I'd expect that to be called uri_query, and this being a zero-param associated function (rather than a method to get the URI query, or a 1-param function to build a GET with one) is a pretty big clue.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mean confusion, but that it would prevent any addition of req.query() since it's on the same type.

Is that lack of this easy builder a big deal? It's also possible to do Request::builder().method("QUERY").

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It certainly isn't a big deal aside from consistency, these constructors aren't used directly all that frequently (at least IME).

I think there is still a case for spending the query name on this purpose, though; the typing savings from ::builder().method("QUERY") -> ::query() are quite a bit more than .uri().query() -> .query().

}

impl<T> Request<T> {
Expand Down