mirror of https://github.com/fafhrd91/actix-web
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:
parent
38ef6b73f5
commit
2b090e0817
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Add `TestServer::{query, squery}()` for issuing HTTP `QUERY` requests (RFC 10008).
|
||||||
- Minimum supported Rust version (MSRV) is now 1.88.
|
- Minimum supported Rust version (MSRV) is now 1.88.
|
||||||
|
|
||||||
## 3.2.0
|
## 3.2.0
|
||||||
|
|
|
||||||
|
|
@ -216,6 +216,16 @@ impl TestServer {
|
||||||
self.client.patch(self.surl(path.as_ref()).as_str())
|
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
|
/// Create `DELETE` request
|
||||||
pub fn delete<S: AsRef<str>>(&self, path: S) -> ClientRequest {
|
pub fn delete<S: AsRef<str>>(&self, path: S) -> ClientRequest {
|
||||||
self.client.delete(self.url(path.as_ref()).as_str())
|
self.client.delete(self.url(path.as_ref()).as_str())
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Add `TestServer::query()` for issuing HTTP `QUERY` requests (RFC 10008).
|
||||||
- Minimum supported Rust version (MSRV) is now 1.88.
|
- Minimum supported Rust version (MSRV) is now 1.88.
|
||||||
|
|
||||||
## 0.1.5
|
## 0.1.5
|
||||||
|
|
|
||||||
|
|
@ -697,6 +697,11 @@ impl TestServer {
|
||||||
self.client.patch(self.url(path.as_ref()).as_str())
|
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.
|
/// Create `DELETE` request.
|
||||||
pub fn delete(&self, path: impl AsRef<str>) -> ClientRequest {
|
pub fn delete(&self, path: impl AsRef<str>) -> ClientRequest {
|
||||||
self.client.delete(self.url(path.as_ref()).as_str())
|
self.client.delete(self.url(path.as_ref()).as_str())
|
||||||
|
|
|
||||||
|
|
@ -112,8 +112,6 @@ impl TestRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs test request with QUERY method.
|
/// 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).
|
// TODO: use `Method::QUERY` once the `http` dependency is bumped (see #3384).
|
||||||
pub fn query() -> TestRequest {
|
pub fn query() -> TestRequest {
|
||||||
TestRequest::default().method(Method::from_bytes(b"QUERY").unwrap())
|
TestRequest::default().method(Method::from_bytes(b"QUERY").unwrap())
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
## Unreleased
|
## 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]
|
- 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 `hickory-resolver` dependency to `0.26.1`.
|
||||||
- Update `rand` dependency to `0.10`.
|
- Update `rand` dependency to `0.10`.
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,16 @@ impl Client {
|
||||||
self.request(Method::OPTIONS, url)
|
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.
|
/// Initialize a WebSocket connection.
|
||||||
/// Returns a WebSocket connection builder.
|
/// Returns a WebSocket connection builder.
|
||||||
pub fn ws<U>(&self, url: U) -> ws::WebsocketsRequest
|
pub fn ws<U>(&self, url: U) -> ws::WebsocketsRequest
|
||||||
|
|
@ -203,3 +213,14 @@ impl Client {
|
||||||
Rc::get_mut(&mut self.0.default_headers)
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue