Merge pull request #87 from actix/master

-
This commit is contained in:
Zhang Zhongyu 2020-09-11 13:38:16 +08:00 committed by GitHub
commit d21bdf8887
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 74 additions and 62 deletions

View File

@ -1,6 +1,9 @@
# Changes # Changes
## Unreleased - 2020-xx-xx ## Unreleased - 2020-xx-xx
## 3.0.0-beta.4 - 2020-09-09
### Added ### Added
* `middleware::NormalizePath` now has configurable behaviour for either always having a trailing * `middleware::NormalizePath` now has configurable behaviour for either always having a trailing
slash, or as the new addition, always trimming trailing slashes. [#1639] slash, or as the new addition, always trimming trailing slashes. [#1639]

View File

@ -1,6 +1,8 @@
#![allow(clippy::borrow_interior_mutable_const, clippy::type_complexity)]
//! Static files support //! Static files support
#![deny(rust_2018_idioms)]
#![allow(clippy::borrow_interior_mutable_const)]
use std::cell::RefCell; use std::cell::RefCell;
use std::fmt::Write; use std::fmt::Write;
use std::fs::{DirEntry, File}; use std::fs::{DirEntry, File};
@ -62,6 +64,7 @@ pub struct ChunkedReadFile {
size: u64, size: u64,
offset: u64, offset: u64,
file: Option<File>, file: Option<File>,
#[allow(clippy::type_complexity)]
fut: fut:
Option<LocalBoxFuture<'static, Result<(File, Bytes), BlockingError<io::Error>>>>, Option<LocalBoxFuture<'static, Result<(File, Bytes), BlockingError<io::Error>>>>,
counter: u64, counter: u64,
@ -72,7 +75,7 @@ impl Stream for ChunkedReadFile {
fn poll_next( fn poll_next(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
cx: &mut Context, cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> { ) -> Poll<Option<Self::Item>> {
if let Some(ref mut fut) = self.fut { if let Some(ref mut fut) = self.fut {
return match Pin::new(fut).poll(cx) { return match Pin::new(fut).poll(cx) {
@ -224,7 +227,7 @@ fn directory_listing(
)) ))
} }
type MimeOverride = dyn Fn(&mime::Name) -> DispositionType; type MimeOverride = dyn Fn(&mime::Name<'_>) -> DispositionType;
/// Static files handling /// Static files handling
/// ///
@ -232,12 +235,10 @@ type MimeOverride = dyn Fn(&mime::Name) -> DispositionType;
/// ///
/// ```rust /// ```rust
/// use actix_web::App; /// use actix_web::App;
/// use actix_files as fs; /// use actix_files::Files;
/// ///
/// fn main() { /// let app = App::new()
/// let app = App::new() /// .service(Files::new("/static", "."));
/// .service(fs::Files::new("/static", "."));
/// }
/// ``` /// ```
pub struct Files { pub struct Files {
path: String, path: String,
@ -330,7 +331,7 @@ impl Files {
/// Specifies mime override callback /// Specifies mime override callback
pub fn mime_override<F>(mut self, f: F) -> Self pub fn mime_override<F>(mut self, f: F) -> Self
where where
F: Fn(&mime::Name) -> DispositionType + 'static, F: Fn(&mime::Name<'_>) -> DispositionType + 'static,
{ {
self.mime_override = Some(Rc::new(f)); self.mime_override = Some(Rc::new(f));
self self
@ -469,6 +470,7 @@ pub struct FilesService {
} }
impl FilesService { impl FilesService {
#[allow(clippy::type_complexity)]
fn handle_err( fn handle_err(
&mut self, &mut self,
e: io::Error, e: io::Error,
@ -490,12 +492,13 @@ impl Service for FilesService {
type Request = ServiceRequest; type Request = ServiceRequest;
type Response = ServiceResponse; type Response = ServiceResponse;
type Error = Error; type Error = Error;
#[allow(clippy::type_complexity)]
type Future = Either< type Future = Either<
Ready<Result<Self::Response, Self::Error>>, Ready<Result<Self::Response, Self::Error>>,
LocalBoxFuture<'static, Result<Self::Response, Self::Error>>, LocalBoxFuture<'static, Result<Self::Response, Self::Error>>,
>; >;
fn poll_ready(&mut self, _: &mut Context) -> Poll<Result<(), Self::Error>> { fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(())) Poll::Ready(Ok(()))
} }
@ -898,7 +901,7 @@ mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn test_mime_override() { async fn test_mime_override() {
fn all_attachment(_: &mime::Name) -> DispositionType { fn all_attachment(_: &mime::Name<'_>) -> DispositionType {
DispositionType::Attachment DispositionType::Attachment
} }

View File

@ -714,7 +714,7 @@ mod tests {
let body = resp_body.downcast_ref::<String>().unwrap(); let body = resp_body.downcast_ref::<String>().unwrap();
assert_eq!(body, "hello cast"); assert_eq!(body, "hello cast");
let body = &mut resp_body.downcast_mut::<String>().unwrap(); let body = &mut resp_body.downcast_mut::<String>().unwrap();
body.push_str("!"); body.push('!');
let body = resp_body.downcast_ref::<String>().unwrap(); let body = resp_body.downcast_ref::<String>().unwrap();
assert_eq!(body, "hello cast!"); assert_eq!(body, "hello cast!");
let not_body = resp_body.downcast_ref::<()>(); let not_body = resp_body.downcast_ref::<()>();

View File

@ -119,11 +119,11 @@ where
match poll_fn(|cx| Poll::Ready(inner.borrow_mut().acquire(&key, cx))).await { match poll_fn(|cx| Poll::Ready(inner.borrow_mut().acquire(&key, cx))).await {
Acquire::Acquired(io, created) => { Acquire::Acquired(io, created) => {
// use existing connection // use existing connection
return Ok(IoConnection::new( Ok(IoConnection::new(
io, io,
created, created,
Some(Acquired(key, Some(inner))), Some(Acquired(key, Some(inner))),
)); ))
} }
Acquire::Available => { Acquire::Available => {
// open tcp connection // open tcp connection

View File

@ -1,5 +1,6 @@
//! Basic http primitives for actix-net framework. //! Basic http primitives for actix-net framework.
#![warn(rust_2018_idioms, warnings)]
#![deny(rust_2018_idioms)]
#![allow( #![allow(
clippy::type_complexity, clippy::type_complexity,
clippy::too_many_arguments, clippy::too_many_arguments,

View File

@ -87,7 +87,7 @@ mod tests {
let body = resp_body.downcast_ref::<String>().unwrap(); let body = resp_body.downcast_ref::<String>().unwrap();
assert_eq!(body, "hello cast"); assert_eq!(body, "hello cast");
let body = &mut resp_body.downcast_mut::<String>().unwrap(); let body = &mut resp_body.downcast_mut::<String>().unwrap();
body.push_str("!"); body.push('!');
let body = resp_body.downcast_ref::<String>().unwrap(); let body = resp_body.downcast_ref::<String>().unwrap();
assert_eq!(body, "hello cast!"); assert_eq!(body, "hello cast!");
let not_body = resp_body.downcast_ref::<()>(); let not_body = resp_body.downcast_ref::<()>();

View File

@ -3,6 +3,10 @@
## Unreleased - 2020-xx-xx ## Unreleased - 2020-xx-xx
## 3.0.0-beta.2 - 2020-09-10
* Update `actix-*` dependencies to latest versions.
## 0.3.0-beta.1 - 2020-07-15 ## 0.3.0-beta.1 - 2020-07-15
* Update `actix-web` to 3.0.0-beta.1 * Update `actix-web` to 3.0.0-beta.1

View File

@ -1,6 +1,6 @@
[package] [package]
name = "actix-multipart" name = "actix-multipart"
version = "0.3.0-beta.1" version = "0.3.0-beta.2"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"] authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Multipart support for actix web framework." description = "Multipart support for actix web framework."
readme = "README.md" readme = "README.md"

View File

@ -1,3 +1,6 @@
//! Multipart form support for Actix web.
#![deny(rust_2018_idioms)]
#![allow(clippy::borrow_interior_mutable_const)] #![allow(clippy::borrow_interior_mutable_const)]
mod error; mod error;

View File

@ -1,4 +1,5 @@
//! Multipart payload support //! Multipart payload support
use std::cell::{Cell, RefCell, RefMut}; use std::cell::{Cell, RefCell, RefMut};
use std::convert::TryFrom; use std::convert::TryFrom;
use std::marker::PhantomData; use std::marker::PhantomData;
@ -108,7 +109,7 @@ impl Stream for Multipart {
fn poll_next( fn poll_next(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
cx: &mut Context, cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> { ) -> Poll<Option<Self::Item>> {
if let Some(err) = self.error.take() { if let Some(err) = self.error.take() {
Poll::Ready(Some(Err(err))) Poll::Ready(Some(Err(err)))
@ -244,7 +245,7 @@ impl InnerMultipart {
fn poll( fn poll(
&mut self, &mut self,
safety: &Safety, safety: &Safety,
cx: &mut Context, cx: &mut Context<'_>,
) -> Poll<Option<Result<Field, MultipartError>>> { ) -> Poll<Option<Result<Field, MultipartError>>> {
if self.state == InnerState::Eof { if self.state == InnerState::Eof {
Poll::Ready(None) Poll::Ready(None)
@ -416,7 +417,10 @@ impl Field {
impl Stream for Field { impl Stream for Field {
type Item = Result<Bytes, MultipartError>; type Item = Result<Bytes, MultipartError>;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> { fn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> {
if self.safety.current() { if self.safety.current() {
let mut inner = self.inner.borrow_mut(); let mut inner = self.inner.borrow_mut();
if let Some(mut payload) = if let Some(mut payload) =
@ -434,7 +438,7 @@ impl Stream for Field {
} }
impl fmt::Debug for Field { impl fmt::Debug for Field {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "\nField: {}", self.ct)?; writeln!(f, "\nField: {}", self.ct)?;
writeln!(f, " boundary: {}", self.inner.borrow().boundary)?; writeln!(f, " boundary: {}", self.inner.borrow().boundary)?;
writeln!(f, " headers:")?; writeln!(f, " headers:")?;
@ -689,7 +693,7 @@ impl Safety {
self.clean.get() self.clean.get()
} }
fn clone(&self, cx: &mut Context) -> Safety { fn clone(&self, cx: &mut Context<'_>) -> Safety {
let payload = Rc::clone(&self.payload); let payload = Rc::clone(&self.payload);
let s = Safety { let s = Safety {
task: LocalWaker::new(), task: LocalWaker::new(),
@ -734,7 +738,7 @@ impl PayloadBuffer {
} }
} }
fn poll_stream(&mut self, cx: &mut Context) -> Result<(), PayloadError> { fn poll_stream(&mut self, cx: &mut Context<'_>) -> Result<(), PayloadError> {
loop { loop {
match Pin::new(&mut self.stream).poll_next(cx) { match Pin::new(&mut self.stream).poll_next(cx) {
Poll::Ready(Some(Ok(data))) => self.buf.extend_from_slice(&data), Poll::Ready(Some(Ok(data))) => self.buf.extend_from_slice(&data),
@ -887,7 +891,7 @@ mod tests {
fn poll_next( fn poll_next(
self: Pin<&mut Self>, self: Pin<&mut Self>,
cx: &mut Context, cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> { ) -> Poll<Option<Self::Item>> {
let this = self.get_mut(); let this = self.get_mut();
if !this.ready { if !this.ready {

View File

@ -1,6 +1,10 @@
# Changes # Changes
## [Unreleased] - 2020-xx-xx ## Unreleased - 2020-xx-xx
## 3.0.0-beta.2 - 2020-09-10
* Update `actix-*` dependencies to latest versions.
## [3.0.0-beta.1] - 2020-xx-xx ## [3.0.0-beta.1] - 2020-xx-xx

View File

@ -1,6 +1,6 @@
[package] [package]
name = "actix-web-actors" name = "actix-web-actors"
version = "3.0.0-beta.1" version = "3.0.0-beta.2"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"] authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix actors support for actix web framework." description = "Actix actors support for actix web framework."
readme = "README.md" readme = "README.md"

View File

@ -1,5 +1,8 @@
#![allow(clippy::borrow_interior_mutable_const)]
//! Actix actors integration for Actix web framework //! Actix actors integration for Actix web framework
#![deny(rust_2018_idioms)]
#![allow(clippy::borrow_interior_mutable_const)]
mod context; mod context;
pub mod ws; pub mod ws;

View File

@ -1,4 +1,4 @@
#![warn(rust_2018_idioms, warnings)] #![deny(rust_2018_idioms)]
#![allow( #![allow(
clippy::type_complexity, clippy::type_complexity,
clippy::borrow_interior_mutable_const, clippy::borrow_interior_mutable_const,

View File

@ -193,11 +193,7 @@ impl RequestSender {
} }
}; };
SendClientRequest::new( SendClientRequest::new(fut, response_decompress, timeout.or(config.timeout))
fut,
response_decompress,
timeout.or_else(|| config.timeout),
)
} }
pub(crate) fn send_json<T: Serialize>( pub(crate) fn send_json<T: Serialize>(

View File

@ -1,4 +1,4 @@
#![warn(rust_2018_idioms, warnings)] #![deny(rust_2018_idioms)]
#![allow(clippy::needless_doctest_main, clippy::type_complexity)] #![allow(clippy::needless_doctest_main, clippy::type_complexity)]
//! Actix web is a powerful, pragmatic, and extremely fast web framework for Rust. //! Actix web is a powerful, pragmatic, and extremely fast web framework for Rust.

View File

@ -195,7 +195,7 @@ impl<T: Serialize> Responder for Form<T> {
/// web::resource("/index.html") /// web::resource("/index.html")
/// // change `Form` extractor configuration /// // change `Form` extractor configuration
/// .app_data( /// .app_data(
/// web::Form::<FormData>::configure(|cfg| cfg.limit(4097)) /// web::FormConfig::default().limit(4097)
/// ) /// )
/// .route(web::get().to(index)) /// .route(web::get().to(index))
/// ); /// );

View File

@ -209,10 +209,10 @@ where
/// Json extractor configuration /// Json extractor configuration
/// ///
/// # Examples /// # Example
/// ///
/// ```rust /// ```rust
/// use actix_web::{error, web, App, FromRequest, HttpRequest, HttpResponse}; /// use actix_web::{error, web, App, FromRequest, HttpResponse};
/// use serde_derive::Deserialize; /// use serde_derive::Deserialize;
/// ///
/// #[derive(Deserialize)] /// #[derive(Deserialize)]
@ -225,35 +225,26 @@ where
/// format!("Welcome {}!", info.username) /// format!("Welcome {}!", info.username)
/// } /// }
/// ///
/// /// Return either a 400 or 415, and include the error message from serde
/// /// in the response body
/// fn json_error_handler(err: error::JsonPayloadError, _req: &HttpRequest) -> error::Error {
/// let detail = err.to_string();
/// let response = match &err {
/// error::JsonPayloadError::ContentType => {
/// HttpResponse::UnsupportedMediaType().content_type("text/plain").body(detail)
/// }
/// _ => HttpResponse::BadRequest().content_type("text/plain").body(detail),
/// };
/// error::InternalError::from_response(err, response).into()
/// }
///
/// fn main() { /// fn main() {
/// let app = App::new().service( /// let app = App::new().service(
/// web::resource("/index.html") /// web::resource("/index.html")
/// .app_data( /// .app_data(
/// // change json extractor configuration /// // Json extractor configuration for this resource.
/// web::Json::<Info>::configure(|cfg| { /// web::JsonConfig::default()
/// cfg.limit(4096) /// .limit(4096) // Limit request payload size
/// .content_type(|mime| { // <- accept text/plain content type /// .content_type(|mime| { // <- accept text/plain content type
/// mime.type_() == mime::TEXT && mime.subtype() == mime::PLAIN /// mime.type_() == mime::TEXT && mime.subtype() == mime::PLAIN
/// }) /// })
/// .error_handler(json_error_handler) // Use our custom error response /// .error_handler(|err, req| { // <- create custom error response
/// })) /// error::InternalError::from_response(
/// err, HttpResponse::Conflict().finish()).into()
/// })
/// )
/// .route(web::post().to(index)) /// .route(web::post().to(index))
/// ); /// );
/// } /// }
/// ``` /// ```
///
#[derive(Clone)] #[derive(Clone)]
pub struct JsonConfig { pub struct JsonConfig {
limit: usize, limit: usize,

View File

@ -188,12 +188,12 @@ where
/// let app = App::new().service( /// let app = App::new().service(
/// web::resource("/index.html").app_data( /// web::resource("/index.html").app_data(
/// // change query extractor configuration /// // change query extractor configuration
/// web::Query::<Info>::configure(|cfg| { /// web::QueryConfig::default()
/// cfg.error_handler(|err, req| { // <- create custom error response /// .error_handler(|err, req| { // <- create custom error response
/// error::InternalError::from_response( /// error::InternalError::from_response(
/// err, HttpResponse::Conflict().finish()).into() /// err, HttpResponse::Conflict().finish()).into()
/// }) /// })
/// })) /// )
/// .route(web::post().to(index)) /// .route(web::post().to(index))
/// ); /// );
/// } /// }