1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-23 00:26:34 +00:00

restore cookie methods on ServiceRequest

This commit is contained in:
Rob Ede 2021-04-19 02:24:20 +01:00
parent 8ffb1f2011
commit 35f8188410
No known key found for this signature in database
GPG key ID: 97C636207D3EF933
2 changed files with 22 additions and 6 deletions

View file

@ -1,14 +1,18 @@
use std::cell::{Ref, RefMut};
use std::str;
use std::{
cell::{Ref, RefMut},
str,
};
use encoding_rs::{Encoding, UTF_8};
use http::header;
use mime::Mime;
use crate::error::{ContentTypeError, ParseError};
use crate::extensions::Extensions;
use crate::header::{Header, HeaderMap};
use crate::payload::Payload;
use crate::{
error::{ContentTypeError, ParseError},
header::{Header, HeaderMap},
payload::Payload,
Extensions,
};
/// Trait that implements general purpose operations on HTTP messages.
pub trait HttpMessage: Sized {

View file

@ -9,6 +9,7 @@ use actix_http::{
};
use actix_router::{IntoPattern, Path, Resource, ResourceDef, Url};
use actix_service::{IntoServiceFactory, ServiceFactory};
use cookie::{Cookie, ParseError as CookieParseError};
use crate::dev::insert_slash;
use crate::guard::Guard;
@ -244,6 +245,17 @@ impl ServiceRequest {
None
}
#[cfg(feature = "cookies")]
pub fn cookies(&self) -> Result<Ref<'_, Vec<Cookie<'static>>>, CookieParseError> {
self.req.cookies()
}
/// Return request cookie.
#[cfg(feature = "cookies")]
pub fn cookie(&self, name: &str) -> Option<Cookie<'static>> {
self.req.cookie(name)
}
/// Set request payload.
pub fn set_payload(&mut self, payload: Payload) {
self.payload = payload;