use std::rc::Rc; use actix_http::body::{Body, MessageBody, ResponseBody}; use actix_http::http::HeaderMap; use actix_http::{ Error, Extensions, HttpMessage, Payload, Request, Response, ResponseHead, }; use actix_router::{Path, Url}; use crate::request::HttpRequest; pub struct ServiceRequest

{ req: HttpRequest, payload: Payload

, } impl

ServiceRequest

{ pub(crate) fn new( path: Path, request: Request

, extensions: Rc, ) -> Self { let (head, payload) = request.into_parts(); ServiceRequest { payload, req: HttpRequest::new(head, path, extensions), } } #[inline] pub fn request(&self) -> &HttpRequest { &self.req } #[inline] pub fn into_request(self) -> HttpRequest { self.req } /// Create service response #[inline] pub fn into_response(self, res: Response) -> ServiceResponse { ServiceResponse::new(self.req, res) } /// Create service response for error #[inline] pub fn error_response>(self, err: E) -> ServiceResponse { ServiceResponse::new(self.req, err.into().into()) } #[inline] pub fn match_info_mut(&mut self) -> &mut Path { &mut self.req.path } } impl

HttpMessage for ServiceRequest

{ type Stream = P; #[inline] fn headers(&self) -> &HeaderMap { self.req.headers() } #[inline] fn take_payload(&mut self) -> Payload { std::mem::replace(&mut self.payload, Payload::None) } } impl

std::ops::Deref for ServiceRequest

{ type Target = HttpRequest; fn deref(&self) -> &HttpRequest { self.request() } } pub struct ServiceResponse { request: HttpRequest, response: Response, } impl ServiceResponse { /// Create service response instance pub fn new(request: HttpRequest, response: Response) -> Self { ServiceResponse { request, response } } /// Get reference to original request #[inline] pub fn request(&self) -> &HttpRequest { &self.request } /// Get reference to response #[inline] pub fn response(&self) -> &Response { &self.response } /// Get mutable reference to response #[inline] pub fn response_mut(&mut self) -> &mut Response { &mut self.response } /// Get the headers from the response #[inline] pub fn headers(&self) -> &HeaderMap { self.response.headers() } /// Get a mutable reference to the headers #[inline] pub fn headers_mut(&mut self) -> &mut HeaderMap { self.response.headers_mut() } } impl ServiceResponse { /// Set a new body pub fn map_body(self, f: F) -> ServiceResponse where F: FnOnce(&mut ResponseHead, ResponseBody) -> ResponseBody, { let response = self.response.map_body(f); ServiceResponse { response, request: self.request, } } } impl std::ops::Deref for ServiceResponse { type Target = Response; fn deref(&self) -> &Response { self.response() } } impl std::ops::DerefMut for ServiceResponse { fn deref_mut(&mut self) -> &mut Response { self.response_mut() } } impl Into> for ServiceResponse { fn into(self) -> Response { self.response } }