Merge branch 'master' into http-reexports

This commit is contained in:
Rob Ede 2021-04-19 02:33:30 +01:00 committed by GitHub
commit 7684d3c588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 16 deletions

View File

@ -9,6 +9,7 @@
### Changed ### Changed
* Most error types are now marked `#[non_exhaustive]`. [#2148] * Most error types are now marked `#[non_exhaustive]`. [#2148]
* Methods on `ContentDisposition` that took `T: AsRef<str>` now take `impl AsRef<str>`.
[#2065]: https://github.com/actix/actix-web/pull/2065 [#2065]: https://github.com/actix/actix-web/pull/2065
[#2148]: https://github.com/actix/actix-web/pull/2148 [#2148]: https://github.com/actix/actix-web/pull/2148

View File

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

View File

@ -401,11 +401,11 @@ impl ContentDisposition {
} }
/// Returns `true` if it is [`Ext`](DispositionType::Ext) and the `disp_type` matches. /// Returns `true` if it is [`Ext`](DispositionType::Ext) and the `disp_type` matches.
pub fn is_ext<T: AsRef<str>>(&self, disp_type: T) -> bool { pub fn is_ext(&self, disp_type: impl AsRef<str>) -> bool {
match self.disposition { matches!(
DispositionType::Ext(ref t) if t.eq_ignore_ascii_case(disp_type.as_ref()) => true, self.disposition,
_ => false, DispositionType::Ext(ref t) if t.eq_ignore_ascii_case(disp_type.as_ref())
} )
} }
/// Return the value of *name* if exists. /// Return the value of *name* if exists.
@ -430,7 +430,7 @@ impl ContentDisposition {
} }
/// Return the value of the parameter which the `name` matches. /// Return the value of the parameter which the `name` matches.
pub fn get_unknown<T: AsRef<str>>(&self, name: T) -> Option<&str> { pub fn get_unknown(&self, name: impl AsRef<str>) -> Option<&str> {
let name = name.as_ref(); let name = name.as_ref();
self.parameters self.parameters
.iter() .iter()
@ -439,7 +439,7 @@ impl ContentDisposition {
} }
/// Return the value of the extended parameter which the `name` matches. /// Return the value of the extended parameter which the `name` matches.
pub fn get_unknown_ext<T: AsRef<str>>(&self, name: T) -> Option<&ExtendedValue> { pub fn get_unknown_ext(&self, name: impl AsRef<str>) -> Option<&ExtendedValue> {
let name = name.as_ref(); let name = name.as_ref();
self.parameters self.parameters
.iter() .iter()
@ -552,8 +552,7 @@ impl fmt::Display for ContentDisposition {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{ContentDisposition, DispositionParam, DispositionType}; use super::{ContentDisposition, DispositionParam, DispositionType};
use crate::http::header::Charset; use crate::http::header::{Charset, ExtendedValue, HeaderValue};
use crate::http::header::{ExtendedValue, HeaderValue};
#[test] #[test]
fn test_from_raw_basic() { fn test_from_raw_basic() {

View File

@ -9,6 +9,7 @@ use actix_http::{
}; };
use actix_router::{IntoPattern, Path, Resource, ResourceDef, Url}; use actix_router::{IntoPattern, Path, Resource, ResourceDef, Url};
use actix_service::{IntoServiceFactory, ServiceFactory}; use actix_service::{IntoServiceFactory, ServiceFactory};
use cookie::{Cookie, ParseError as CookieParseError};
use crate::dev::insert_slash; use crate::dev::insert_slash;
use crate::guard::Guard; use crate::guard::Guard;
@ -244,6 +245,17 @@ impl ServiceRequest {
None 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. /// Set request payload.
pub fn set_payload(&mut self, payload: Payload) { pub fn set_payload(&mut self, payload: Payload) {
self.payload = payload; self.payload = payload;