mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
feat: enable use of patch as request method (#718)
This commit is contained in:
parent
17ecdd63d2
commit
bf8262196f
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
* Add client HTTP Authentication methods `.basic_auth()` and `.bearer_auth()`. #540
|
* Add client HTTP Authentication methods `.basic_auth()` and `.bearer_auth()`. #540
|
||||||
|
|
||||||
|
* Add support for PATCH HTTP method
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
* Ignored the `If-Modified-Since` if `If-None-Match` is specified. #680
|
* Ignored the `If-Modified-Since` if `If-None-Match` is specified. #680
|
||||||
|
@ -105,6 +105,13 @@ pub fn post<U: AsRef<str>>(uri: U) -> ClientRequestBuilder {
|
|||||||
builder
|
builder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create request builder for `PATCH` requests
|
||||||
|
pub fn patch<U: AsRef<str>>(uri: U) -> ClientRequestBuilder {
|
||||||
|
let mut builder = ClientRequest::build();
|
||||||
|
builder.method(Method::PATCH).uri(uri);
|
||||||
|
builder
|
||||||
|
}
|
||||||
|
|
||||||
/// Create request builder for `PUT` requests
|
/// Create request builder for `PUT` requests
|
||||||
pub fn put<U: AsRef<str>>(uri: U) -> ClientRequestBuilder {
|
pub fn put<U: AsRef<str>>(uri: U) -> ClientRequestBuilder {
|
||||||
let mut builder = ClientRequest::build();
|
let mut builder = ClientRequest::build();
|
||||||
|
@ -112,6 +112,13 @@ impl ClientRequest {
|
|||||||
builder
|
builder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create request builder for `PATCH` request
|
||||||
|
pub fn patch<U: AsRef<str>>(uri: U) -> ClientRequestBuilder {
|
||||||
|
let mut builder = ClientRequest::build();
|
||||||
|
builder.method(Method::PATCH).uri(uri);
|
||||||
|
builder
|
||||||
|
}
|
||||||
|
|
||||||
/// Create request builder for `PUT` request
|
/// Create request builder for `PUT` request
|
||||||
pub fn put<U: AsRef<str>>(uri: U) -> ClientRequestBuilder {
|
pub fn put<U: AsRef<str>>(uri: U) -> ClientRequestBuilder {
|
||||||
let mut builder = ClientRequest::build();
|
let mut builder = ClientRequest::build();
|
||||||
|
@ -107,6 +107,12 @@ impl<S: 'static> Resource<S> {
|
|||||||
self.routes.last_mut().unwrap().filter(pred::Post())
|
self.routes.last_mut().unwrap().filter(pred::Post())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Register a new `PATCH` route.
|
||||||
|
pub fn patch(&mut self) -> &mut Route<S> {
|
||||||
|
self.routes.push(Route::default());
|
||||||
|
self.routes.last_mut().unwrap().filter(pred::Patch())
|
||||||
|
}
|
||||||
|
|
||||||
/// Register a new `PUT` route.
|
/// Register a new `PUT` route.
|
||||||
pub fn put(&mut self) -> &mut Route<S> {
|
pub fn put(&mut self) -> &mut Route<S> {
|
||||||
self.routes.push(Route::default());
|
self.routes.push(Route::default());
|
||||||
|
@ -239,6 +239,11 @@ impl TestServer {
|
|||||||
ClientRequest::post(self.url("/").as_str())
|
ClientRequest::post(self.url("/").as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create `PATCH` request
|
||||||
|
pub fn patch(&self) -> ClientRequestBuilder {
|
||||||
|
ClientRequest::patch(self.url("/").as_str())
|
||||||
|
}
|
||||||
|
|
||||||
/// Create `HEAD` request
|
/// Create `HEAD` request
|
||||||
pub fn head(&self) -> ClientRequestBuilder {
|
pub fn head(&self) -> ClientRequestBuilder {
|
||||||
ClientRequest::head(self.url("/").as_str())
|
ClientRequest::head(self.url("/").as_str())
|
||||||
|
@ -1398,3 +1398,11 @@ fn test_content_length() {
|
|||||||
assert_eq!(response.headers().get(&header), Some(&value));
|
assert_eq!(response.headers().get(&header), Some(&value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_patch_method() {
|
||||||
|
let mut srv = test::TestServer::new(|app| app.handler(|_| HttpResponse::Ok()));
|
||||||
|
let req = srv.patch().finish().unwrap();
|
||||||
|
let response = srv.execute(req.send()).unwrap();
|
||||||
|
assert!(response.status().is_success());
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user