use std::cell::{Ref, RefMut}; use std::rc::Rc; use actix_http::body::{Body, MessageBody, ResponseBody}; use actix_http::http::{HeaderMap, Method, Uri, Version}; use actix_http::{ Error, Extensions, HttpMessage, Payload, Request, RequestHead, 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 ,
extensions: Rc HttpMessage for ServiceRequest {
type Stream = P;
#[inline]
fn headers(&self) -> &HeaderMap {
self.req.headers()
}
#[inline]
fn take_payload(&mut self) -> Payload std::ops::Deref for ServiceRequest {
type Target = RequestHead;
fn deref(&self) -> &RequestHead {
self.req.head()
}
}
impl std::ops::DerefMut for ServiceRequest {
fn deref_mut(&mut self) -> &mut RequestHead {
self.head_mut()
}
}
pub struct ServiceFromRequest {
req: HttpRequest,
payload: Payload ,
}
impl ServiceFromRequest {
#[inline]
pub fn into_request(self) -> HttpRequest {
self.req
}
/// Create service response for error
#[inline]
pub fn error_response std::ops::Deref for ServiceFromRequest {
type Target = HttpRequest;
fn deref(&self) -> &HttpRequest {
&self.req
}
}
impl HttpMessage for ServiceFromRequest {
type Stream = P;
#[inline]
fn headers(&self) -> &HeaderMap {
self.req.headers()
}
#[inline]
fn take_payload(&mut self) -> Payload From {
fn from(req: ServiceRequest ) -> Self {
Self {
req: req.req,
payload: req.payload,
}
}
}
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