diff --git a/actix-http-test/src/lib.rs b/actix-http-test/src/lib.rs index f881dfb4c..3ab3f8a0d 100644 --- a/actix-http-test/src/lib.rs +++ b/actix-http-test/src/lib.rs @@ -53,7 +53,7 @@ pub async fn test_server>(factory: F) -> TestServer test_server_with_addr(tcp, factory).await } -/// Start [`test server`](./fn.test_server.html) on a concrete Address +/// Start [`test server`](test_server()) on a concrete Address pub async fn test_server_with_addr>( tcp: net::TcpListener, factory: F, diff --git a/actix-http/src/error.rs b/actix-http/src/error.rs index e93c077af..0ebd4c05c 100644 --- a/actix-http/src/error.rs +++ b/actix-http/src/error.rs @@ -25,7 +25,7 @@ pub use crate::cookie::ParseError as CookieParseError; use crate::helpers::Writer; use crate::response::{Response, ResponseBuilder}; -/// A specialized [`Result`](https://doc.rust-lang.org/std/result/enum.Result.html) +/// A specialized [`std::result::Result`] /// for actix web operations /// /// This typedef is generally used to avoid writing out diff --git a/actix-http/src/h1/payload.rs b/actix-http/src/h1/payload.rs index 6a348810c..d4cfee146 100644 --- a/actix-http/src/h1/payload.rs +++ b/actix-http/src/h1/payload.rs @@ -182,9 +182,7 @@ impl Inner { self.len += data.len(); self.items.push_back(data); self.need_read = self.len < MAX_BUFFER_SIZE; - if let Some(task) = self.task.take() { - task.wake() - } + self.task.wake(); } #[cfg(test)] diff --git a/actix-http/src/header/common/content_disposition.rs b/actix-http/src/header/common/content_disposition.rs index 37da830ca..826cfef63 100644 --- a/actix-http/src/header/common/content_disposition.rs +++ b/actix-http/src/header/common/content_disposition.rs @@ -550,8 +550,7 @@ impl fmt::Display for ContentDisposition { write!(f, "{}", self.disposition)?; self.parameters .iter() - .map(|param| write!(f, "; {}", param)) - .collect() + .try_for_each(|param| write!(f, "; {}", param)) } } diff --git a/actix-http/src/header/common/mod.rs b/actix-http/src/header/common/mod.rs index 83489b864..c3d18613c 100644 --- a/actix-http/src/header/common/mod.rs +++ b/actix-http/src/header/common/mod.rs @@ -3,7 +3,7 @@ //! ## Mime //! //! Several header fields use MIME values for their contents. Keeping with the -//! strongly-typed theme, the [mime](https://docs.rs/mime) crate +//! strongly-typed theme, the [mime] crate //! is used, such as `ContentType(pub Mime)`. #![cfg_attr(rustfmt, rustfmt_skip)] diff --git a/actix-http/src/header/map.rs b/actix-http/src/header/map.rs index 36c050b8f..6ab3509f7 100644 --- a/actix-http/src/header/map.rs +++ b/actix-http/src/header/map.rs @@ -8,8 +8,6 @@ use http::header::{HeaderName, HeaderValue}; /// A set of HTTP headers /// /// `HeaderMap` is an multi-map of [`HeaderName`] to values. -/// -/// [`HeaderName`]: struct.HeaderName.html #[derive(Debug, Clone)] pub struct HeaderMap { pub(crate) inner: FxHashMap, @@ -141,8 +139,6 @@ impl HeaderMap { /// The returned view does not incur any allocations and allows iterating /// the values associated with the key. See [`GetAll`] for more details. /// Returns `None` if there are no values associated with the key. - /// - /// [`GetAll`]: struct.GetAll.html pub fn get_all(&self, name: N) -> GetAll<'_> { GetAll { idx: 0, diff --git a/actix-http/src/header/shared/entity.rs b/actix-http/src/header/shared/entity.rs index 3525a19c6..344cfb864 100644 --- a/actix-http/src/header/shared/entity.rs +++ b/actix-http/src/header/shared/entity.rs @@ -7,10 +7,12 @@ use crate::header::{HeaderValue, IntoHeaderValue, InvalidHeaderValue, Writer}; /// 1. `%x21`, or /// 2. in the range `%x23` to `%x7E`, or /// 3. above `%x80` +fn entity_validate_char(c: u8) -> bool { + c == 0x21 || (0x23..=0x7e).contains(&c) || (c >= 0x80) +} + fn check_slice_validity(slice: &str) -> bool { - slice - .bytes() - .all(|c| c == b'\x21' || (c >= b'\x23' && c <= b'\x7e') | (c >= b'\x80')) + slice.bytes().all(entity_validate_char) } /// An entity tag, defined in [RFC7232](https://tools.ietf.org/html/rfc7232#section-2.3) diff --git a/actix-multipart/src/server.rs b/actix-multipart/src/server.rs index b9ebf97cc..b476f1791 100644 --- a/actix-multipart/src/server.rs +++ b/actix-multipart/src/server.rs @@ -725,9 +725,7 @@ impl Drop for Safety { if Rc::strong_count(&self.payload) != self.level { self.clean.set(true); } - if let Some(task) = self.task.take() { - task.wake() - } + self.task.wake(); } } diff --git a/actix-web-codegen/README.md b/actix-web-codegen/README.md index 6eca847b8..283591e86 100644 --- a/actix-web-codegen/README.md +++ b/actix-web-codegen/README.md @@ -3,7 +3,7 @@ > Helper and convenience macros for Actix Web [![crates.io](https://meritbadge.herokuapp.com/actix-web-codegen)](https://crates.io/crates/actix-web-codegen) -[![Documentation](https://docs.rs/actix-web-codegen/badge.svg)](https://docs.rs/actix-web) +[![Documentation](https://docs.rs/actix-web-codegen/badge.svg)](https://docs.rs/actix-web-codegen/0.4.0/actix_web_codegen/) [![Version](https://img.shields.io/badge/rustc-1.42+-ab6000.svg)](https://blog.rust-lang.org/2020/03/12/Rust-1.42.html) [![Build Status](https://travis-ci.org/actix/actix-web.svg?branch=master)](https://travis-ci.org/actix/actix-web) [![codecov](https://codecov.io/gh/actix/actix-web/branch/master/graph/badge.svg)](https://codecov.io/gh/actix/actix-web) diff --git a/actix-web-codegen/src/lib.rs b/actix-web-codegen/src/lib.rs index af2bc7f18..50e5be712 100644 --- a/actix-web-codegen/src/lib.rs +++ b/actix-web-codegen/src/lib.rs @@ -8,7 +8,7 @@ //! are re-exported. //! //! # Runtime Setup -//! Used for setting up the actix async runtime. See [main] macro docs. +//! Used for setting up the actix async runtime. See [macro@main] macro docs. //! //! ```rust //! #[actix_web_codegen::main] // or `#[actix_web::main]` in Actix Web apps @@ -34,7 +34,7 @@ //! //! # Multiple Method Handlers //! Similar to the single method handler macro but takes one or more arguments for the HTTP methods -//! it should respond to. See [route] macro docs. +//! it should respond to. See [macro@route] macro docs. //! //! ```rust //! # use actix_web::HttpResponse; @@ -46,17 +46,15 @@ //! ``` //! //! [actix-web attributes docs]: https://docs.rs/actix-web/*/actix_web/#attributes -//! [main]: attr.main.html -//! [route]: attr.route.html -//! [GET]: attr.get.html -//! [POST]: attr.post.html -//! [PUT]: attr.put.html -//! [DELETE]: attr.delete.html -//! [HEAD]: attr.head.html -//! [CONNECT]: attr.connect.html -//! [OPTIONS]: attr.options.html -//! [TRACE]: attr.trace.html -//! [PATCH]: attr.patch.html +//! [GET]: macro@get +//! [POST]: macro@post +//! [PUT]: macro@put +//! [HEAD]: macro@head +//! [CONNECT]: macro@macro@connect +//! [OPTIONS]: macro@options +//! [TRACE]: macro@trace +//! [PATCH]: macro@patch +//! [DELETE]: macro@delete #![recursion_limit = "512"] diff --git a/awc/src/ws.rs b/awc/src/ws.rs index 57e80bd46..dd43d08b3 100644 --- a/awc/src/ws.rs +++ b/awc/src/ws.rs @@ -1,6 +1,6 @@ //! Websockets client //! -//! Type definitions required to use [`awc::Client`](../struct.Client.html) as a WebSocket client. +//! Type definitions required to use [`awc::Client`](super::Client) as a WebSocket client. //! //! # Example //! @@ -70,9 +70,14 @@ impl WebsocketsRequest { >::Error: Into, { let mut err = None; - let mut head = RequestHead::default(); - head.method = Method::GET; - head.version = Version::HTTP_11; + + #[allow(clippy::field_reassign_with_default)] + let mut head = { + let mut head = RequestHead::default(); + head.method = Method::GET; + head.version = Version::HTTP_11; + head + }; match Uri::try_from(uri) { Ok(uri) => head.uri = uri, diff --git a/codecov.yml b/codecov.yml index 90cdfab47..102e8969d 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,4 +1,13 @@ -ignore: # ignore codecoverage on following paths +coverage: + status: + project: + default: + threshold: 10% # make CI green + patch: + default: + threshold: 10% # make CI green + +ignore: # ignore code coverage on following paths - "**/tests" - "test-server" - "**/benches" diff --git a/src/config.rs b/src/config.rs index 03ba82732..01959daa1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -141,7 +141,7 @@ impl AppConfig { /// Server host name. /// /// Host name is used by application router as a hostname for url generation. - /// Check [ConnectionInfo](./struct.ConnectionInfo.html#method.host) + /// Check [ConnectionInfo](super::dev::ConnectionInfo::host()) /// documentation for more information. /// /// By default host name is set to a "localhost" value. diff --git a/src/info.rs b/src/info.rs index 1d9b402a7..975604041 100644 --- a/src/info.rs +++ b/src/info.rs @@ -174,7 +174,7 @@ impl ConnectionInfo { /// Do not use this function for security purposes, unless you can ensure the Forwarded and /// X-Forwarded-For headers cannot be spoofed by the client. If you want the client's socket /// address explicitly, use - /// [`HttpRequest::peer_addr()`](../web/struct.HttpRequest.html#method.peer_addr) instead. + /// [`HttpRequest::peer_addr()`](super::web::HttpRequest::peer_addr()) instead. #[inline] pub fn realip_remote_addr(&self) -> Option<&str> { if let Some(ref r) = self.realip_remote_addr { diff --git a/src/lib.rs b/src/lib.rs index a8fc50d83..b8346d966 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,16 +29,16 @@ //! //! To get started navigating the API docs, you may consider looking at the following pages first: //! -//! * [App](struct.App.html): This struct represents an Actix web application and is used to +//! * [App]: This struct represents an Actix web application and is used to //! configure routes and other common application settings. //! -//! * [HttpServer](struct.HttpServer.html): This struct represents an HTTP server instance and is +//! * [HttpServer]: This struct represents an HTTP server instance and is //! used to instantiate and configure servers. //! -//! * [web](web/index.html): This module provides essential types for route registration as well as +//! * [web]: This module provides essential types for route registration as well as //! common utilities for request handlers. //! -//! * [HttpRequest](struct.HttpRequest.html) and [HttpResponse](struct.HttpResponse.html): These +//! * [HttpRequest] and [HttpResponse]: These //! structs represent HTTP requests and responses and expose methods for creating, inspecting, //! and otherwise utilizing them. //! diff --git a/src/middleware/compress.rs b/src/middleware/compress.rs index fe3ba841c..7575d7455 100644 --- a/src/middleware/compress.rs +++ b/src/middleware/compress.rs @@ -192,10 +192,7 @@ impl AcceptEncoding { }; let quality = match parts.len() { 1 => encoding.quality(), - _ => match f64::from_str(parts[1]) { - Ok(q) => q, - Err(_) => 0.0, - }, + _ => f64::from_str(parts[1]).unwrap_or(0.0), }; Some(AcceptEncoding { encoding, quality }) } diff --git a/src/middleware/condition.rs b/src/middleware/condition.rs index ab1c69746..9061c7458 100644 --- a/src/middleware/condition.rs +++ b/src/middleware/condition.rs @@ -105,6 +105,7 @@ mod tests { use crate::test::{self, TestRequest}; use crate::HttpResponse; + #[allow(clippy::unnecessary_wraps)] fn render_500(mut res: ServiceResponse) -> Result> { res.response_mut() .headers_mut() diff --git a/src/middleware/errhandlers.rs b/src/middleware/errhandlers.rs index 93a5d3f22..c0cb9594e 100644 --- a/src/middleware/errhandlers.rs +++ b/src/middleware/errhandlers.rs @@ -154,6 +154,7 @@ mod tests { use crate::test::{self, TestRequest}; use crate::HttpResponse; + #[allow(clippy::unnecessary_wraps)] fn render_500(mut res: ServiceResponse) -> Result> { res.response_mut() .headers_mut() diff --git a/src/middleware/logger.rs b/src/middleware/logger.rs index b2e5c791f..563cb6c32 100644 --- a/src/middleware/logger.rs +++ b/src/middleware/logger.rs @@ -82,11 +82,10 @@ use crate::HttpResponse; /// /// # Security /// **\*** It is calculated using -/// [`ConnectionInfo::realip_remote_addr()`](../dev/struct.ConnectionInfo.html#method.realip_remote_addr) +/// [`ConnectionInfo::realip_remote_addr()`](crate::dev::ConnectionInfo::realip_remote_addr()) /// /// If you use this value ensure that all requests come from trusted hosts, since it is trivial /// for the remote client to simulate being another client. -/// pub struct Logger(Rc); struct Inner { diff --git a/src/route.rs b/src/route.rs index dd850a50c..f10bbabd4 100644 --- a/src/route.rs +++ b/src/route.rs @@ -16,24 +16,24 @@ use crate::responder::Responder; use crate::service::{ServiceRequest, ServiceResponse}; use crate::HttpResponse; -type BoxedRouteService = Box< +type BoxedRouteService = Box< dyn Service< - Request = Req, - Response = Res, + Request = ServiceRequest, + Response = ServiceResponse, Error = Error, - Future = LocalBoxFuture<'static, Result>, + Future = LocalBoxFuture<'static, Result>, >, >; -type BoxedRouteNewService = Box< +type BoxedRouteNewService = Box< dyn ServiceFactory< Config = (), - Request = Req, - Response = Res, + Request = ServiceRequest, + Response = ServiceResponse, Error = Error, InitError = (), - Service = BoxedRouteService, - Future = LocalBoxFuture<'static, Result, ()>>, + Service = BoxedRouteService, + Future = LocalBoxFuture<'static, Result>, >, >; @@ -42,7 +42,7 @@ type BoxedRouteNewService = Box< /// Route uses builder-like pattern for configuration. /// If handler is not explicitly set, default *404 Not Found* handler is used. pub struct Route { - service: BoxedRouteNewService, + service: BoxedRouteNewService, guards: Rc>>, } @@ -80,15 +80,8 @@ impl ServiceFactory for Route { } } -type RouteFuture = LocalBoxFuture< - 'static, - Result, ()>, ->; - -#[pin_project::pin_project] pub struct CreateRouteService { - #[pin] - fut: RouteFuture, + fut: LocalBoxFuture<'static, Result>, guards: Rc>>, } @@ -96,9 +89,9 @@ impl Future for CreateRouteService { type Output = Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let this = self.project(); + let this = self.get_mut(); - match this.fut.poll(cx)? { + match this.fut.as_mut().poll(cx)? { Poll::Ready(service) => Poll::Ready(Ok(RouteService { service, guards: this.guards.clone(), @@ -109,7 +102,7 @@ impl Future for CreateRouteService { } pub struct RouteService { - service: BoxedRouteService, + service: BoxedRouteService, guards: Rc>>, } @@ -135,7 +128,7 @@ impl Service for RouteService { } fn call(&mut self, req: ServiceRequest) -> Self::Future { - self.service.call(req).boxed_local() + self.service.call(req) } } @@ -275,12 +268,12 @@ where T::Service: 'static, ::Future: 'static, { - type Config = (); type Request = ServiceRequest; type Response = ServiceResponse; type Error = Error; + type Config = (); + type Service = BoxedRouteService; type InitError = (); - type Service = BoxedRouteService; type Future = LocalBoxFuture<'static, Result>; fn new_service(&self, _: ()) -> Self::Future { @@ -288,8 +281,7 @@ where .new_service(()) .map(|result| match result { Ok(service) => { - let service: BoxedRouteService<_, _> = - Box::new(RouteServiceWrapper { service }); + let service = Box::new(RouteServiceWrapper { service }) as _; Ok(service) } Err(_) => Err(()), diff --git a/src/server.rs b/src/server.rs index e2d86df68..992e64f9a 100644 --- a/src/server.rs +++ b/src/server.rs @@ -213,7 +213,7 @@ where /// Set server host name. /// /// Host name is used by application router as a hostname for url generation. - /// Check [ConnectionInfo](./dev/struct.ConnectionInfo.html#method.host) + /// Check [ConnectionInfo](super::dev::ConnectionInfo::host()) /// documentation for more information. /// /// By default host name is set to a "localhost" value. diff --git a/src/service.rs b/src/service.rs index a861ba38c..189ba5554 100644 --- a/src/service.rs +++ b/src/service.rs @@ -195,13 +195,13 @@ impl ServiceRequest { self.0.match_info() } - /// Counterpart to [`HttpRequest::match_name`](../struct.HttpRequest.html#method.match_name). + /// Counterpart to [`HttpRequest::match_name`](super::HttpRequest::match_name()). #[inline] pub fn match_name(&self) -> Option<&str> { self.0.match_name() } - /// Counterpart to [`HttpRequest::match_pattern`](../struct.HttpRequest.html#method.match_pattern). + /// Counterpart to [`HttpRequest::match_pattern`](super::HttpRequest::match_pattern()). #[inline] pub fn match_pattern(&self) -> Option { self.0.match_pattern() @@ -225,7 +225,7 @@ impl ServiceRequest { self.0.app_config() } - /// Counterpart to [`HttpRequest::app_data`](../struct.HttpRequest.html#method.app_data). + /// Counterpart to [`HttpRequest::app_data`](super::HttpRequest::app_data()). pub fn app_data(&self) -> Option<&T> { for container in (self.0).0.app_data.iter().rev() { if let Some(data) = container.get::() { diff --git a/src/types/form.rs b/src/types/form.rs index 2a7101287..82ea73216 100644 --- a/src/types/form.rs +++ b/src/types/form.rs @@ -35,7 +35,7 @@ use crate::{responder::Responder, web}; /// To extract typed information from request's body, the type `T` must /// implement the `Deserialize` trait from *serde*. /// -/// [**FormConfig**](struct.FormConfig.html) allows to configure extraction +/// [**FormConfig**](FormConfig) allows to configure extraction /// process. /// /// ### Example diff --git a/src/types/json.rs b/src/types/json.rs index 081a022e8..83c9f21b0 100644 --- a/src/types/json.rs +++ b/src/types/json.rs @@ -31,7 +31,7 @@ use crate::{responder::Responder, web}; /// To extract typed information from request's body, the type `T` must /// implement the `Deserialize` trait from *serde*. /// -/// [**JsonConfig**](struct.JsonConfig.html) allows to configure extraction +/// [**JsonConfig**](JsonConfig) allows to configure extraction /// process. /// /// ## Example @@ -142,7 +142,7 @@ impl Responder for Json { /// To extract typed information from request's body, the type `T` must /// implement the `Deserialize` trait from *serde*. /// -/// [**JsonConfig**](struct.JsonConfig.html) allows to configure extraction +/// [**JsonConfig**](JsonConfig) allows to configure extraction /// process. /// /// ## Example @@ -306,7 +306,7 @@ impl Default for JsonConfig { /// Returns error: /// /// * content type is not `application/json` -/// (unless specified in [`JsonConfig`](struct.JsonConfig.html)) +/// (unless specified in [`JsonConfig`]) /// * content length is greater than 256k pub struct JsonBody { limit: usize, diff --git a/src/types/path.rs b/src/types/path.rs index dbb5f3ee0..640ff4346 100644 --- a/src/types/path.rs +++ b/src/types/path.rs @@ -15,7 +15,7 @@ use crate::FromRequest; #[derive(PartialEq, Eq, PartialOrd, Ord)] /// Extract typed information from the request's path. /// -/// [**PathConfig**](struct.PathConfig.html) allows to configure extraction process. +/// [**PathConfig**](PathConfig) allows to configure extraction process. /// /// ## Example /// diff --git a/src/types/payload.rs b/src/types/payload.rs index 4ff5ef4b4..acb8b9a82 100644 --- a/src/types/payload.rs +++ b/src/types/payload.rs @@ -111,7 +111,7 @@ impl FromRequest for Payload { /// /// Loads request's payload and construct Bytes instance. /// -/// [**PayloadConfig**](struct.PayloadConfig.html) allows to configure +/// [**PayloadConfig**](PayloadConfig) allows to configure /// extraction process. /// /// ## Example @@ -159,7 +159,7 @@ impl FromRequest for Bytes { /// /// Text extractor automatically decode body according to the request's charset. /// -/// [**PayloadConfig**](struct.PayloadConfig.html) allows to configure +/// [**PayloadConfig**](PayloadConfig) allows to configure /// extraction process. /// /// ## Example @@ -241,9 +241,10 @@ pub struct PayloadConfig { impl PayloadConfig { /// Create `PayloadConfig` instance and set max size of payload. pub fn new(limit: usize) -> Self { - let mut cfg = Self::default(); - cfg.limit = limit; - cfg + Self { + limit, + ..Default::default() + } } /// Change max size of payload. By default max size is 256Kb diff --git a/src/types/query.rs b/src/types/query.rs index 7eded49c5..27df220fc 100644 --- a/src/types/query.rs +++ b/src/types/query.rs @@ -18,7 +18,7 @@ use crate::request::HttpRequest; /// be decoded into any type which depends upon data ordering e.g. tuples or tuple-structs. /// Attempts to do so will *fail at runtime*. /// -/// [**QueryConfig**](struct.QueryConfig.html) allows to configure extraction process. +/// [**QueryConfig**](QueryConfig) allows to configure extraction process. /// /// ## Example ///