1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-23 23:51:06 +01:00

feat: enable use of patch as request method (#718)

This commit is contained in:
Jannik Keye 2019-03-14 09:36:10 +01:00 committed by Douman
parent 17ecdd63d2
commit bf8262196f
6 changed files with 35 additions and 0 deletions

View File

@ -10,6 +10,8 @@
* Add client HTTP Authentication methods `.basic_auth()` and `.bearer_auth()`. #540
* Add support for PATCH HTTP method
### Fixed
* Ignored the `If-Modified-Since` if `If-None-Match` is specified. #680

View File

@ -105,6 +105,13 @@ pub fn post<U: AsRef<str>>(uri: U) -> ClientRequestBuilder {
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
pub fn put<U: AsRef<str>>(uri: U) -> ClientRequestBuilder {
let mut builder = ClientRequest::build();

View File

@ -112,6 +112,13 @@ impl ClientRequest {
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
pub fn put<U: AsRef<str>>(uri: U) -> ClientRequestBuilder {
let mut builder = ClientRequest::build();

View File

@ -107,6 +107,12 @@ impl<S: 'static> Resource<S> {
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.
pub fn put(&mut self) -> &mut Route<S> {
self.routes.push(Route::default());

View File

@ -239,6 +239,11 @@ impl TestServer {
ClientRequest::post(self.url("/").as_str())
}
/// Create `PATCH` request
pub fn patch(&self) -> ClientRequestBuilder {
ClientRequest::patch(self.url("/").as_str())
}
/// Create `HEAD` request
pub fn head(&self) -> ClientRequestBuilder {
ClientRequest::head(self.url("/").as_str())

View File

@ -1398,3 +1398,11 @@ fn test_content_length() {
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());
}