Add request and payload getters to ServiceRequest

This commit is contained in:
Andrey Kutejko 2021-04-18 03:00:50 +02:00
parent f462aaa7b6
commit 06ebab09ee
2 changed files with 13 additions and 1 deletions

View File

@ -7,7 +7,7 @@ use std::sync::Arc;
use actix_http::HttpService;
use actix_http_test::test_server;
use actix_service::{map_config, fn_service, ServiceFactoryExt};
use actix_service::{fn_service, map_config, ServiceFactoryExt};
use actix_utils::future::ok;
use actix_web::http::Version;
use actix_web::{dev::AppConfig, web, App, HttpResponse};

View File

@ -99,6 +99,18 @@ impl ServiceRequest {
}
}
/// This method returns reference to the request
#[inline]
pub fn request(&self) -> &HttpRequest {
&self.req
}
/// This method returns reference to the payload
#[inline]
pub fn payload(&self) -> &Payload {
&self.payload
}
/// Create service response
#[inline]
pub fn into_response<B, R: Into<Response<B>>>(self, res: R) -> ServiceResponse<B> {