1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 17:52:56 +01:00

re-export ready boilerplate macros in dev

This commit is contained in:
Rob Ede 2021-04-16 23:21:02 +01:00
parent 2449f2555c
commit 879a4cbcd8
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
3 changed files with 16 additions and 16 deletions

View File

@ -1,11 +1,15 @@
use std::future::Future; use std::future::Future;
use std::task::{Context, Poll};
use actix_utils::future::{ok, Ready}; use actix_utils::future::{ok, Ready};
use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform}; use actix_web::{
use actix_web::http::header::{HeaderName, HeaderValue}; dev::{Service, ServiceRequest, ServiceResponse, Transform},
use actix_web::http::StatusCode; http::{
use actix_web::{http, web::Path, App, Error, HttpResponse, Responder}; self,
header::{HeaderName, HeaderValue},
StatusCode,
},
web, App, Error, HttpResponse, Responder,
};
use actix_web_codegen::{connect, delete, get, head, options, patch, post, put, route, trace}; use actix_web_codegen::{connect, delete, get, head, options, patch, post, put, route, trace};
use futures_core::future::LocalBoxFuture; use futures_core::future::LocalBoxFuture;
@ -66,17 +70,17 @@ fn auto_sync() -> impl Future<Output = Result<HttpResponse, actix_web::Error>> {
} }
#[put("/test/{param}")] #[put("/test/{param}")]
async fn put_param_test(_: Path<String>) -> impl Responder { async fn put_param_test(_: web::Path<String>) -> impl Responder {
HttpResponse::Created() HttpResponse::Created()
} }
#[delete("/test/{param}")] #[delete("/test/{param}")]
async fn delete_param_test(_: Path<String>) -> impl Responder { async fn delete_param_test(_: web::Path<String>) -> impl Responder {
HttpResponse::NoContent() HttpResponse::NoContent()
} }
#[get("/test/{param}")] #[get("/test/{param}")]
async fn get_param_test(_: Path<String>) -> impl Responder { async fn get_param_test(_: web::Path<String>) -> impl Responder {
HttpResponse::Ok() HttpResponse::Ok()
} }
@ -125,9 +129,7 @@ where
type Error = Error; type Error = Error;
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>; type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { actix_web::dev::forward_ready!(service);
self.service.poll_ready(cx)
}
fn call(&self, req: ServiceRequest) -> Self::Future { fn call(&self, req: ServiceRequest) -> Self::Future {
let fut = self.service.call(req); let fut = self.service.call(req);
@ -144,7 +146,7 @@ where
} }
#[get("/test/wrap", wrap = "ChangeStatusCode")] #[get("/test/wrap", wrap = "ChangeStatusCode")]
async fn get_wrap(_: Path<String>) -> impl Responder { async fn get_wrap(_: web::Path<String>) -> impl Responder {
// panic!("actually never gets called because path failed to extract"); // panic!("actually never gets called because path failed to extract");
HttpResponse::Ok() HttpResponse::Ok()
} }

View File

@ -145,7 +145,7 @@ pub mod dev {
pub use actix_http::{Extensions, Payload, PayloadStream, RequestHead, ResponseHead}; pub use actix_http::{Extensions, Payload, PayloadStream, RequestHead, ResponseHead};
pub use actix_router::{Path, ResourceDef, ResourcePath, Url}; pub use actix_router::{Path, ResourceDef, ResourcePath, Url};
pub use actix_server::Server; pub use actix_server::Server;
pub use actix_service::{Service, Transform}; pub use actix_service::{always_ready, forward_ready, Service, Transform};
pub(crate) fn insert_slash(mut patterns: Vec<String>) -> Vec<String> { pub(crate) fn insert_slash(mut patterns: Vec<String>) -> Vec<String> {
for path in &mut patterns { for path in &mut patterns {

View File

@ -80,9 +80,7 @@ where
type Error = Error; type Error = Error;
type Future = CompatMiddlewareFuture<S::Future>; type Future = CompatMiddlewareFuture<S::Future>;
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { actix_service::forward_ready!(service);
self.service.poll_ready(cx).map_err(From::from)
}
fn call(&self, req: Req) -> Self::Future { fn call(&self, req: Req) -> Self::Future {
let fut = self.service.call(req); let fut = self.service.call(req);