feat: add QUERY method helpers to awc client and test servers

Extend HTTP QUERY (RFC 10008) support to the remaining per-method
convenience surfaces, mirroring PATCH:

- awc: `Client::query()`
- actix-test: `TestServer::query()`
- actix-http-test: `TestServer::query()` and the HTTPS `TestServer::squery()`

Also tighten `TestRequest::query()`'s doc to match its sibling helpers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Bruno Oliveira 2026-07-07 19:21:22 -03:00
parent 38ef6b73f5
commit 2b090e0817
7 changed files with 39 additions and 2 deletions

View File

@ -2,6 +2,7 @@
## Unreleased
- Add `TestServer::{query, squery}()` for issuing HTTP `QUERY` requests (RFC 10008).
- Minimum supported Rust version (MSRV) is now 1.88.
## 3.2.0

View File

@ -216,6 +216,16 @@ impl TestServer {
self.client.patch(self.surl(path.as_ref()).as_str())
}
/// Create `QUERY` request
pub fn query<S: AsRef<str>>(&self, path: S) -> ClientRequest {
self.client.query(self.url(path.as_ref()).as_str())
}
/// Create HTTPS `QUERY` request
pub fn squery<S: AsRef<str>>(&self, path: S) -> ClientRequest {
self.client.query(self.surl(path.as_ref()).as_str())
}
/// Create `DELETE` request
pub fn delete<S: AsRef<str>>(&self, path: S) -> ClientRequest {
self.client.delete(self.url(path.as_ref()).as_str())

View File

@ -2,6 +2,7 @@
## Unreleased
- Add `TestServer::query()` for issuing HTTP `QUERY` requests (RFC 10008).
- Minimum supported Rust version (MSRV) is now 1.88.
## 0.1.5

View File

@ -697,6 +697,11 @@ impl TestServer {
self.client.patch(self.url(path.as_ref()).as_str())
}
/// Create `QUERY` request.
pub fn query(&self, path: impl AsRef<str>) -> ClientRequest {
self.client.query(self.url(path.as_ref()).as_str())
}
/// Create `DELETE` request.
pub fn delete(&self, path: impl AsRef<str>) -> ClientRequest {
self.client.delete(self.url(path.as_ref()).as_str())

View File

@ -112,8 +112,6 @@ impl TestRequest {
}
/// Constructs test request with QUERY method.
///
/// `QUERY` (RFC 10008) is safe and idempotent like `GET`, but carries a request body.
// TODO: use `Method::QUERY` once the `http` dependency is bumped (see #3384).
pub fn query() -> TestRequest {
TestRequest::default().method(Method::from_bytes(b"QUERY").unwrap())

View File

@ -2,6 +2,7 @@
## Unreleased
- Add `Client::query()` for constructing HTTP `QUERY` requests (RFC 10008).
- Add camel-case header controls to `WebsocketsRequest` via `camel_case_headers()` and `set_camel_case_headers()`. [#3953]
- Update `hickory-resolver` dependency to `0.26.1`.
- Update `rand` dependency to `0.10`.

View File

@ -181,6 +181,16 @@ impl Client {
self.request(Method::OPTIONS, url)
}
/// Construct HTTP *QUERY* request.
// TODO: use `Method::QUERY` once the `http` dependency is bumped (see #3384).
pub fn query<U>(&self, url: U) -> ClientRequest
where
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
{
self.request(Method::from_bytes(b"QUERY").unwrap(), url)
}
/// Initialize a WebSocket connection.
/// Returns a WebSocket connection builder.
pub fn ws<U>(&self, url: U) -> ws::WebsocketsRequest
@ -203,3 +213,14 @@ impl Client {
Rc::get_mut(&mut self.0.default_headers)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn client_query_builds_query_request() {
let req = Client::new().query("/");
assert_eq!(req.get_method().as_str(), "QUERY");
}
}