mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-03 09:36:36 +02:00
Compare commits
5 Commits
http-test-
...
http-v0.2.
Author | SHA1 | Date | |
---|---|---|---|
baaa7b3fbb | |||
32718b7e31 | |||
c01611d8b5 | |||
7b1dcaffda | |||
c65dbaf88e |
@ -1,15 +1,19 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## [1.0.4] - TBD
|
## [1.0.4] - 2019-07-17
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
* Add `Responder` impl for `(T, StatusCode) where T: Responder`
|
* Add `Responder` impl for `(T, StatusCode) where T: Responder`
|
||||||
|
|
||||||
|
* Allow to access app's resource map via
|
||||||
|
`ServiceRequest::resource_map()` and `HttpRequest::resource_map()` methods.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
* Upgrade `rand` dependency version to 0.7
|
* Upgrade `rand` dependency version to 0.7
|
||||||
|
|
||||||
|
|
||||||
## [1.0.3] - 2019-06-28
|
## [1.0.3] - 2019-06-28
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-web"
|
name = "actix-web"
|
||||||
version = "1.0.3"
|
version = "1.0.4"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust."
|
description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
@ -71,9 +71,9 @@ rust-tls = ["rustls", "actix-server/rust-tls"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.1.2"
|
actix-codec = "0.1.2"
|
||||||
actix-service = "0.4.1"
|
actix-service = "0.4.1"
|
||||||
actix-utils = "0.4.2"
|
actix-utils = "0.4.4"
|
||||||
actix-router = "0.1.5"
|
actix-router = "0.1.5"
|
||||||
actix-rt = "0.2.3"
|
actix-rt = "0.2.4"
|
||||||
actix-web-codegen = "0.1.2"
|
actix-web-codegen = "0.1.2"
|
||||||
actix-http = "0.2.5"
|
actix-http = "0.2.5"
|
||||||
actix-server = "0.5.1"
|
actix-server = "0.5.1"
|
||||||
|
@ -681,7 +681,7 @@ where
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Either<
|
type Future = Either<
|
||||||
FutureResult<Self::Response, Error>,
|
FutureResult<Self::Response, Error>,
|
||||||
Either<S::Future, Box<Future<Item = Self::Response, Error = Error>>>,
|
Either<S::Future, Box<dyn Future<Item = Self::Response, Error = Error>>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
|
@ -50,7 +50,7 @@ pub struct ChunkedReadFile {
|
|||||||
size: u64,
|
size: u64,
|
||||||
offset: u64,
|
offset: u64,
|
||||||
file: Option<File>,
|
file: Option<File>,
|
||||||
fut: Option<Box<Future<Item = (File, Bytes), Error = BlockingError<io::Error>>>>,
|
fut: Option<Box<dyn Future<Item = (File, Bytes), Error = BlockingError<io::Error>>>>,
|
||||||
counter: u64,
|
counter: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,7 +370,7 @@ impl NewService for Files {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Service = FilesService;
|
type Service = FilesService;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Future = Box<Future<Item = Self::Service, Error = Self::InitError>>;
|
type Future = Box<dyn Future<Item = Self::Service, Error = Self::InitError>>;
|
||||||
|
|
||||||
fn new_service(&self, _: &()) -> Self::Future {
|
fn new_service(&self, _: &()) -> Self::Future {
|
||||||
let mut srv = FilesService {
|
let mut srv = FilesService {
|
||||||
@ -416,7 +416,7 @@ impl FilesService {
|
|||||||
req: ServiceRequest,
|
req: ServiceRequest,
|
||||||
) -> Either<
|
) -> Either<
|
||||||
FutureResult<ServiceResponse, Error>,
|
FutureResult<ServiceResponse, Error>,
|
||||||
Box<Future<Item = ServiceResponse, Error = Error>>,
|
Box<dyn Future<Item = ServiceResponse, Error = Error>>,
|
||||||
> {
|
> {
|
||||||
log::debug!("Files: Failed to handle {}: {}", req.path(), e);
|
log::debug!("Files: Failed to handle {}: {}", req.path(), e);
|
||||||
if let Some(ref mut default) = self.default {
|
if let Some(ref mut default) = self.default {
|
||||||
@ -433,7 +433,7 @@ impl Service for FilesService {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Either<
|
type Future = Either<
|
||||||
FutureResult<Self::Response, Self::Error>,
|
FutureResult<Self::Response, Self::Error>,
|
||||||
Box<Future<Item = Self::Response, Error = Self::Error>>,
|
Box<dyn Future<Item = Self::Response, Error = Self::Error>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
|
@ -13,7 +13,7 @@ use crate::helpers::{BoxedHttpNewService, BoxedHttpService, HttpNewService};
|
|||||||
use crate::request::FramedRequest;
|
use crate::request::FramedRequest;
|
||||||
use crate::state::State;
|
use crate::state::State;
|
||||||
|
|
||||||
type BoxedResponse = Box<Future<Item = (), Error = Error>>;
|
type BoxedResponse = Box<dyn Future<Item = (), Error = Error>>;
|
||||||
|
|
||||||
pub trait HttpServiceFactory {
|
pub trait HttpServiceFactory {
|
||||||
type Factory: NewService;
|
type Factory: NewService;
|
||||||
@ -61,7 +61,7 @@ impl<T: 'static, S: 'static> FramedApp<T, S> {
|
|||||||
Request = FramedRequest<T, S>,
|
Request = FramedRequest<T, S>,
|
||||||
Response = (),
|
Response = (),
|
||||||
Error = Error,
|
Error = Error,
|
||||||
Future = Box<Future<Item = (), Error = Error>>,
|
Future = Box<dyn Future<Item = (), Error = Error>>,
|
||||||
>,
|
>,
|
||||||
{
|
{
|
||||||
let path = factory.path().to_string();
|
let path = factory.path().to_string();
|
||||||
@ -129,7 +129,7 @@ pub struct CreateService<T, S> {
|
|||||||
enum CreateServiceItem<T, S> {
|
enum CreateServiceItem<T, S> {
|
||||||
Future(
|
Future(
|
||||||
Option<String>,
|
Option<String>,
|
||||||
Box<Future<Item = BoxedHttpService<FramedRequest<T, S>>, Error = ()>>,
|
Box<dyn Future<Item = BoxedHttpService<FramedRequest<T, S>>, Error = ()>>,
|
||||||
),
|
),
|
||||||
Service(String, BoxedHttpService<FramedRequest<T, S>>),
|
Service(String, BoxedHttpService<FramedRequest<T, S>>),
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ pub(crate) type BoxedHttpService<Req> = Box<
|
|||||||
Request = Req,
|
Request = Req,
|
||||||
Response = (),
|
Response = (),
|
||||||
Error = Error,
|
Error = Error,
|
||||||
Future = Box<Future<Item = (), Error = Error>>,
|
Future = Box<dyn Future<Item = (), Error = Error>>,
|
||||||
>,
|
>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ pub(crate) type BoxedHttpNewService<Req> = Box<
|
|||||||
Error = Error,
|
Error = Error,
|
||||||
InitError = (),
|
InitError = (),
|
||||||
Service = BoxedHttpService<Req>,
|
Service = BoxedHttpService<Req>,
|
||||||
Future = Box<Future<Item = BoxedHttpService<Req>, Error = ()>>,
|
Future = Box<dyn Future<Item = BoxedHttpService<Req>, Error = ()>>,
|
||||||
>,
|
>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ where
|
|||||||
T: NewService<Response = (), Error = Error>,
|
T: NewService<Response = (), Error = Error>,
|
||||||
T::Response: 'static,
|
T::Response: 'static,
|
||||||
T::Future: 'static,
|
T::Future: 'static,
|
||||||
T::Service: Service<Future = Box<Future<Item = (), Error = Error>>> + 'static,
|
T::Service: Service<Future = Box<dyn Future<Item = (), Error = Error>>> + 'static,
|
||||||
<T::Service as Service>::Future: 'static,
|
<T::Service as Service>::Future: 'static,
|
||||||
{
|
{
|
||||||
pub fn new(service: T) -> Self {
|
pub fn new(service: T) -> Self {
|
||||||
@ -43,7 +43,7 @@ where
|
|||||||
T: NewService<Config = (), Response = (), Error = Error>,
|
T: NewService<Config = (), Response = (), Error = Error>,
|
||||||
T::Request: 'static,
|
T::Request: 'static,
|
||||||
T::Future: 'static,
|
T::Future: 'static,
|
||||||
T::Service: Service<Future = Box<Future<Item = (), Error = Error>>> + 'static,
|
T::Service: Service<Future = Box<dyn Future<Item = (), Error = Error>>> + 'static,
|
||||||
<T::Service as Service>::Future: 'static,
|
<T::Service as Service>::Future: 'static,
|
||||||
{
|
{
|
||||||
type Config = ();
|
type Config = ();
|
||||||
@ -52,7 +52,7 @@ where
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Service = BoxedHttpService<T::Request>;
|
type Service = BoxedHttpService<T::Request>;
|
||||||
type Future = Box<Future<Item = Self::Service, Error = ()>>;
|
type Future = Box<dyn Future<Item = Self::Service, Error = ()>>;
|
||||||
|
|
||||||
fn new_service(&self, _: &()) -> Self::Future {
|
fn new_service(&self, _: &()) -> Self::Future {
|
||||||
Box::new(self.0.new_service(&()).map_err(|_| ()).and_then(|service| {
|
Box::new(self.0.new_service(&()).map_err(|_| ()).and_then(|service| {
|
||||||
@ -70,7 +70,7 @@ impl<T> Service for HttpServiceWrapper<T>
|
|||||||
where
|
where
|
||||||
T: Service<
|
T: Service<
|
||||||
Response = (),
|
Response = (),
|
||||||
Future = Box<Future<Item = (), Error = Error>>,
|
Future = Box<dyn Future<Item = (), Error = Error>>,
|
||||||
Error = Error,
|
Error = Error,
|
||||||
>,
|
>,
|
||||||
T::Request: 'static,
|
T::Request: 'static,
|
||||||
@ -78,7 +78,7 @@ where
|
|||||||
type Request = T::Request;
|
type Request = T::Request;
|
||||||
type Response = ();
|
type Response = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Box<Future<Item = (), Error = Error>>;
|
type Future = Box<dyn Future<Item = (), Error = Error>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
self.service.poll_ready()
|
self.service.poll_ready()
|
||||||
|
@ -140,7 +140,7 @@ where
|
|||||||
type Request = FramedRequest<Io, S>;
|
type Request = FramedRequest<Io, S>;
|
||||||
type Response = ();
|
type Response = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Box<Future<Item = (), Error = Error>>;
|
type Future = Box<dyn Future<Item = (), Error = Error>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
Ok(Async::Ready(()))
|
Ok(Async::Ready(()))
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## [0.2.6] - TBD
|
## [0.2.6] - 2019-07-17
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
* Replace `ClonableService` with local copy
|
||||||
|
|
||||||
* Upgrade `rand` dependency version to 0.7
|
* Upgrade `rand` dependency version to 0.7
|
||||||
|
|
||||||
|
|
||||||
## [0.2.5] - 2019-06-28
|
## [0.2.5] - 2019-06-28
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -46,10 +46,10 @@ secure-cookies = ["ring"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
actix-service = "0.4.1"
|
actix-service = "0.4.1"
|
||||||
actix-codec = "0.1.2"
|
actix-codec = "0.1.2"
|
||||||
actix-connect = "0.2.0"
|
actix-connect = "0.2.1"
|
||||||
actix-utils = "0.4.2"
|
actix-utils = "0.4.4"
|
||||||
actix-server-config = "0.1.1"
|
actix-server-config = "0.1.1"
|
||||||
actix-threadpool = "0.1.0"
|
actix-threadpool = "0.1.1"
|
||||||
|
|
||||||
base64 = "0.10"
|
base64 = "0.10"
|
||||||
bitflags = "1.0"
|
bitflags = "1.0"
|
||||||
|
@ -94,7 +94,8 @@ where
|
|||||||
T: AsyncRead + AsyncWrite + 'static,
|
T: AsyncRead + AsyncWrite + 'static,
|
||||||
{
|
{
|
||||||
type Io = T;
|
type Io = T;
|
||||||
type Future = Box<Future<Item = (ResponseHead, Payload), Error = SendRequestError>>;
|
type Future =
|
||||||
|
Box<dyn Future<Item = (ResponseHead, Payload), Error = SendRequestError>>;
|
||||||
|
|
||||||
fn protocol(&self) -> Protocol {
|
fn protocol(&self) -> Protocol {
|
||||||
match self.io {
|
match self.io {
|
||||||
@ -169,7 +170,8 @@ where
|
|||||||
B: AsyncRead + AsyncWrite + 'static,
|
B: AsyncRead + AsyncWrite + 'static,
|
||||||
{
|
{
|
||||||
type Io = EitherIo<A, B>;
|
type Io = EitherIo<A, B>;
|
||||||
type Future = Box<Future<Item = (ResponseHead, Payload), Error = SendRequestError>>;
|
type Future =
|
||||||
|
Box<dyn Future<Item = (ResponseHead, Payload), Error = SendRequestError>>;
|
||||||
|
|
||||||
fn protocol(&self) -> Protocol {
|
fn protocol(&self) -> Protocol {
|
||||||
match self {
|
match self {
|
||||||
|
@ -47,6 +47,7 @@ pub struct Connector<T, U> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Connector<(), ()> {
|
impl Connector<(), ()> {
|
||||||
|
#[allow(clippy::new_ret_no_self)]
|
||||||
pub fn new() -> Connector<
|
pub fn new() -> Connector<
|
||||||
impl Service<
|
impl Service<
|
||||||
Request = TcpConnect<Uri>,
|
Request = TcpConnect<Uri>,
|
||||||
|
@ -427,7 +427,9 @@ where
|
|||||||
|
|
||||||
fn check_availibility(&self) {
|
fn check_availibility(&self) {
|
||||||
if !self.waiters_queue.is_empty() && self.acquired < self.limit {
|
if !self.waiters_queue.is_empty() && self.acquired < self.limit {
|
||||||
self.task.as_ref().map(|t| t.notify());
|
if let Some(t) = self.task.as_ref() {
|
||||||
|
t.notify()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
42
actix-http/src/cloneable.rs
Normal file
42
actix-http/src/cloneable.rs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
use std::cell::UnsafeCell;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use actix_service::Service;
|
||||||
|
use futures::Poll;
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
/// Service that allows to turn non-clone service to a service with `Clone` impl
|
||||||
|
pub(crate) struct CloneableService<T>(Rc<UnsafeCell<T>>);
|
||||||
|
|
||||||
|
impl<T> CloneableService<T> {
|
||||||
|
pub(crate) fn new(service: T) -> Self
|
||||||
|
where
|
||||||
|
T: Service,
|
||||||
|
{
|
||||||
|
Self(Rc::new(UnsafeCell::new(service)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Clone for CloneableService<T> {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
Self(self.0.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Service for CloneableService<T>
|
||||||
|
where
|
||||||
|
T: Service,
|
||||||
|
{
|
||||||
|
type Request = T::Request;
|
||||||
|
type Response = T::Response;
|
||||||
|
type Error = T::Error;
|
||||||
|
type Future = T::Future;
|
||||||
|
|
||||||
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
|
unsafe { &mut *self.0.as_ref().get() }.poll_ready()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn call(&mut self, req: T::Request) -> Self::Future {
|
||||||
|
unsafe { &mut *self.0.as_ref().get() }.call(req)
|
||||||
|
}
|
||||||
|
}
|
@ -104,6 +104,7 @@ impl CookieStr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::ptr_arg)]
|
||||||
fn to_raw_str<'s, 'c: 's>(&'s self, string: &'s Cow<'c, str>) -> Option<&'c str> {
|
fn to_raw_str<'s, 'c: 's>(&'s self, string: &'s Cow<'c, str>) -> Option<&'c str> {
|
||||||
match *self {
|
match *self {
|
||||||
CookieStr::Indexed(i, j) => match *string {
|
CookieStr::Indexed(i, j) => match *string {
|
||||||
|
@ -7,7 +7,7 @@ use super::private::KEY_LEN as PRIVATE_KEY_LEN;
|
|||||||
use super::signed::KEY_LEN as SIGNED_KEY_LEN;
|
use super::signed::KEY_LEN as SIGNED_KEY_LEN;
|
||||||
|
|
||||||
static HKDF_DIGEST: &'static Algorithm = &SHA256;
|
static HKDF_DIGEST: &'static Algorithm = &SHA256;
|
||||||
const KEYS_INFO: &'static str = "COOKIE;SIGNED:HMAC-SHA256;PRIVATE:AEAD-AES-256-GCM";
|
const KEYS_INFO: &str = "COOKIE;SIGNED:HMAC-SHA256;PRIVATE:AEAD-AES-256-GCM";
|
||||||
|
|
||||||
/// A cryptographic master key for use with `Signed` and/or `Private` jars.
|
/// A cryptographic master key for use with `Signed` and/or `Private` jars.
|
||||||
///
|
///
|
||||||
|
@ -5,7 +5,6 @@ use std::{fmt, io, net};
|
|||||||
use actix_codec::{Decoder, Encoder, Framed, FramedParts};
|
use actix_codec::{Decoder, Encoder, Framed, FramedParts};
|
||||||
use actix_server_config::IoStream;
|
use actix_server_config::IoStream;
|
||||||
use actix_service::Service;
|
use actix_service::Service;
|
||||||
use actix_utils::cloneable::CloneableService;
|
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use bytes::{BufMut, BytesMut};
|
use bytes::{BufMut, BytesMut};
|
||||||
use futures::{Async, Future, Poll};
|
use futures::{Async, Future, Poll};
|
||||||
@ -13,6 +12,7 @@ use log::{error, trace};
|
|||||||
use tokio_timer::Delay;
|
use tokio_timer::Delay;
|
||||||
|
|
||||||
use crate::body::{Body, BodySize, MessageBody, ResponseBody};
|
use crate::body::{Body, BodySize, MessageBody, ResponseBody};
|
||||||
|
use crate::cloneable::CloneableService;
|
||||||
use crate::config::ServiceConfig;
|
use crate::config::ServiceConfig;
|
||||||
use crate::error::{DispatchError, Error};
|
use crate::error::{DispatchError, Error};
|
||||||
use crate::error::{ParseError, PayloadError};
|
use crate::error::{ParseError, PayloadError};
|
||||||
|
@ -5,11 +5,11 @@ use std::rc::Rc;
|
|||||||
use actix_codec::Framed;
|
use actix_codec::Framed;
|
||||||
use actix_server_config::{Io, IoStream, ServerConfig as SrvConfig};
|
use actix_server_config::{Io, IoStream, ServerConfig as SrvConfig};
|
||||||
use actix_service::{IntoNewService, NewService, Service};
|
use actix_service::{IntoNewService, NewService, Service};
|
||||||
use actix_utils::cloneable::CloneableService;
|
|
||||||
use futures::future::{ok, FutureResult};
|
use futures::future::{ok, FutureResult};
|
||||||
use futures::{try_ready, Async, Future, IntoFuture, Poll, Stream};
|
use futures::{try_ready, Async, Future, IntoFuture, Poll, Stream};
|
||||||
|
|
||||||
use crate::body::MessageBody;
|
use crate::body::MessageBody;
|
||||||
|
use crate::cloneable::CloneableService;
|
||||||
use crate::config::{KeepAlive, ServiceConfig};
|
use crate::config::{KeepAlive, ServiceConfig};
|
||||||
use crate::error::{DispatchError, Error, ParseError};
|
use crate::error::{DispatchError, Error, ParseError};
|
||||||
use crate::helpers::DataFactory;
|
use crate::helpers::DataFactory;
|
||||||
@ -259,7 +259,7 @@ where
|
|||||||
H1ServiceHandler {
|
H1ServiceHandler {
|
||||||
srv: CloneableService::new(srv),
|
srv: CloneableService::new(srv),
|
||||||
expect: CloneableService::new(expect),
|
expect: CloneableService::new(expect),
|
||||||
upgrade: upgrade.map(|s| CloneableService::new(s)),
|
upgrade: upgrade.map(CloneableService::new),
|
||||||
cfg,
|
cfg,
|
||||||
on_connect,
|
on_connect,
|
||||||
_t: PhantomData,
|
_t: PhantomData,
|
||||||
|
@ -6,7 +6,6 @@ use std::{fmt, mem, net};
|
|||||||
use actix_codec::{AsyncRead, AsyncWrite};
|
use actix_codec::{AsyncRead, AsyncWrite};
|
||||||
use actix_server_config::IoStream;
|
use actix_server_config::IoStream;
|
||||||
use actix_service::Service;
|
use actix_service::Service;
|
||||||
use actix_utils::cloneable::CloneableService;
|
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use futures::{try_ready, Async, Future, Poll, Sink, Stream};
|
use futures::{try_ready, Async, Future, Poll, Sink, Stream};
|
||||||
@ -20,6 +19,7 @@ use log::{debug, error, trace};
|
|||||||
use tokio_timer::Delay;
|
use tokio_timer::Delay;
|
||||||
|
|
||||||
use crate::body::{Body, BodySize, MessageBody, ResponseBody};
|
use crate::body::{Body, BodySize, MessageBody, ResponseBody};
|
||||||
|
use crate::cloneable::CloneableService;
|
||||||
use crate::config::ServiceConfig;
|
use crate::config::ServiceConfig;
|
||||||
use crate::error::{DispatchError, Error, ParseError, PayloadError, ResponseError};
|
use crate::error::{DispatchError, Error, ParseError, PayloadError, ResponseError};
|
||||||
use crate::helpers::DataFactory;
|
use crate::helpers::DataFactory;
|
||||||
|
@ -5,7 +5,6 @@ use std::{io, net, rc};
|
|||||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||||
use actix_server_config::{Io, IoStream, ServerConfig as SrvConfig};
|
use actix_server_config::{Io, IoStream, ServerConfig as SrvConfig};
|
||||||
use actix_service::{IntoNewService, NewService, Service};
|
use actix_service::{IntoNewService, NewService, Service};
|
||||||
use actix_utils::cloneable::CloneableService;
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::future::{ok, FutureResult};
|
use futures::future::{ok, FutureResult};
|
||||||
use futures::{try_ready, Async, Future, IntoFuture, Poll, Stream};
|
use futures::{try_ready, Async, Future, IntoFuture, Poll, Stream};
|
||||||
@ -14,6 +13,7 @@ use h2::RecvStream;
|
|||||||
use log::error;
|
use log::error;
|
||||||
|
|
||||||
use crate::body::MessageBody;
|
use crate::body::MessageBody;
|
||||||
|
use crate::cloneable::CloneableService;
|
||||||
use crate::config::{KeepAlive, ServiceConfig};
|
use crate::config::{KeepAlive, ServiceConfig};
|
||||||
use crate::error::{DispatchError, Error, ParseError, ResponseError};
|
use crate::error::{DispatchError, Error, ParseError, ResponseError};
|
||||||
use crate::helpers::DataFactory;
|
use crate::helpers::DataFactory;
|
||||||
@ -256,7 +256,7 @@ where
|
|||||||
on_connect.take(),
|
on_connect.take(),
|
||||||
config.take().unwrap(),
|
config.take().unwrap(),
|
||||||
None,
|
None,
|
||||||
peer_addr.clone(),
|
*peer_addr,
|
||||||
));
|
));
|
||||||
self.poll()
|
self.poll()
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@ impl<'a> From<&'a str> for DispositionType {
|
|||||||
/// assert_eq!(param.as_filename().unwrap(), "sample.txt");
|
/// assert_eq!(param.as_filename().unwrap(), "sample.txt");
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub enum DispositionParam {
|
pub enum DispositionParam {
|
||||||
/// For [`DispositionType::FormData`] (i.e. *multipart/form-data*), the name of an field from
|
/// For [`DispositionType::FormData`] (i.e. *multipart/form-data*), the name of an field from
|
||||||
/// the form.
|
/// the form.
|
||||||
@ -719,8 +720,10 @@ mod tests {
|
|||||||
};
|
};
|
||||||
assert_eq!(a, b);
|
assert_eq!(a, b);
|
||||||
|
|
||||||
let a =
|
let a = HeaderValue::from_str(
|
||||||
HeaderValue::from_str("form-data; name=upload; filename=\"余固知謇謇之為患兮,忍而不能舍也.pptx\"").unwrap();
|
"form-data; name=upload; filename=\"余固知謇謇之為患兮,忍而不能舍也.pptx\"",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
let a: ContentDisposition = ContentDisposition::from_raw(&a).unwrap();
|
let a: ContentDisposition = ContentDisposition::from_raw(&a).unwrap();
|
||||||
let b = ContentDisposition {
|
let b = ContentDisposition {
|
||||||
disposition: DispositionType::FormData,
|
disposition: DispositionType::FormData,
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
//! Basic http primitives for actix-net framework.
|
//! Basic http primitives for actix-net framework.
|
||||||
#![allow(
|
#![allow(
|
||||||
clippy::type_complexity,
|
clippy::type_complexity,
|
||||||
|
clippy::too_many_arguments,
|
||||||
clippy::new_without_default,
|
clippy::new_without_default,
|
||||||
clippy::borrow_interior_mutable_const
|
clippy::borrow_interior_mutable_const,
|
||||||
|
clippy::write_with_newline
|
||||||
)]
|
)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -11,6 +13,7 @@ extern crate log;
|
|||||||
pub mod body;
|
pub mod body;
|
||||||
mod builder;
|
mod builder;
|
||||||
pub mod client;
|
pub mod client;
|
||||||
|
mod cloneable;
|
||||||
mod config;
|
mod config;
|
||||||
pub mod encoding;
|
pub mod encoding;
|
||||||
mod extensions;
|
mod extensions;
|
||||||
|
@ -385,6 +385,7 @@ impl Drop for BoxedResponseHead {
|
|||||||
pub struct MessagePool<T: Head>(RefCell<Vec<Rc<T>>>);
|
pub struct MessagePool<T: Head>(RefCell<Vec<Rc<T>>>);
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
#[allow(clippy::vec_box)]
|
||||||
/// Request's objects pool
|
/// Request's objects pool
|
||||||
pub struct BoxedResponsePool(RefCell<Vec<Box<ResponseHead>>>);
|
pub struct BoxedResponsePool(RefCell<Vec<Box<ResponseHead>>>);
|
||||||
|
|
||||||
|
@ -6,13 +6,13 @@ use actix_server_config::{
|
|||||||
Io as ServerIo, IoStream, Protocol, ServerConfig as SrvConfig,
|
Io as ServerIo, IoStream, Protocol, ServerConfig as SrvConfig,
|
||||||
};
|
};
|
||||||
use actix_service::{IntoNewService, NewService, Service};
|
use actix_service::{IntoNewService, NewService, Service};
|
||||||
use actix_utils::cloneable::CloneableService;
|
|
||||||
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
||||||
use futures::{try_ready, Async, Future, IntoFuture, Poll};
|
use futures::{try_ready, Async, Future, IntoFuture, Poll};
|
||||||
use h2::server::{self, Handshake};
|
use h2::server::{self, Handshake};
|
||||||
|
|
||||||
use crate::body::MessageBody;
|
use crate::body::MessageBody;
|
||||||
use crate::builder::HttpServiceBuilder;
|
use crate::builder::HttpServiceBuilder;
|
||||||
|
use crate::cloneable::CloneableService;
|
||||||
use crate::config::{KeepAlive, ServiceConfig};
|
use crate::config::{KeepAlive, ServiceConfig};
|
||||||
use crate::error::{DispatchError, Error};
|
use crate::error::{DispatchError, Error};
|
||||||
use crate::helpers::DataFactory;
|
use crate::helpers::DataFactory;
|
||||||
@ -285,7 +285,7 @@ where
|
|||||||
on_connect,
|
on_connect,
|
||||||
srv: CloneableService::new(srv),
|
srv: CloneableService::new(srv),
|
||||||
expect: CloneableService::new(expect),
|
expect: CloneableService::new(expect),
|
||||||
upgrade: upgrade.map(|s| CloneableService::new(s)),
|
upgrade: upgrade.map(CloneableService::new),
|
||||||
_t: PhantomData,
|
_t: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,7 @@ impl Into<u8> for OpCode {
|
|||||||
Ping => 9,
|
Ping => 9,
|
||||||
Pong => 10,
|
Pong => 10,
|
||||||
Bad => {
|
Bad => {
|
||||||
debug_assert!(
|
log::error!("Attempted to convert invalid opcode to u8. This is a bug.");
|
||||||
false,
|
|
||||||
"Attempted to convert invalid opcode to u8. This is a bug."
|
|
||||||
);
|
|
||||||
8 // if this somehow happens, a close frame will help us tear down quickly
|
8 // if this somehow happens, a close frame will help us tear down quickly
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ where
|
|||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<B>;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
|
type Future = Box<dyn Future<Item = Self::Response, Error = Self::Error>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
self.service.borrow_mut().poll_ready()
|
self.service.borrow_mut().poll_ready()
|
||||||
|
@ -309,7 +309,7 @@ where
|
|||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<B>;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
|
type Future = Box<dyn Future<Item = Self::Response, Error = Self::Error>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
self.service.poll_ready()
|
self.service.poll_ready()
|
||||||
|
@ -20,7 +20,7 @@ pub(crate) trait Connect {
|
|||||||
head: RequestHead,
|
head: RequestHead,
|
||||||
body: Body,
|
body: Body,
|
||||||
addr: Option<net::SocketAddr>,
|
addr: Option<net::SocketAddr>,
|
||||||
) -> Box<Future<Item = ClientResponse, Error = SendRequestError>>;
|
) -> Box<dyn Future<Item = ClientResponse, Error = SendRequestError>>;
|
||||||
|
|
||||||
/// Send request, returns Response and Framed
|
/// Send request, returns Response and Framed
|
||||||
fn open_tunnel(
|
fn open_tunnel(
|
||||||
@ -49,7 +49,7 @@ where
|
|||||||
head: RequestHead,
|
head: RequestHead,
|
||||||
body: Body,
|
body: Body,
|
||||||
addr: Option<net::SocketAddr>,
|
addr: Option<net::SocketAddr>,
|
||||||
) -> Box<Future<Item = ClientResponse, Error = SendRequestError>> {
|
) -> Box<dyn Future<Item = ClientResponse, Error = SendRequestError>> {
|
||||||
Box::new(
|
Box::new(
|
||||||
self.0
|
self.0
|
||||||
// connect to the host
|
// connect to the host
|
||||||
|
@ -23,7 +23,7 @@ type HttpService = BoxedService<ServiceRequest, ServiceResponse, Error>;
|
|||||||
type HttpNewService = BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>;
|
type HttpNewService = BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>;
|
||||||
type BoxedResponse = Either<
|
type BoxedResponse = Either<
|
||||||
FutureResult<ServiceResponse, Error>,
|
FutureResult<ServiceResponse, Error>,
|
||||||
Box<Future<Item = ServiceResponse, Error = Error>>,
|
Box<dyn Future<Item = ServiceResponse, Error = Error>>,
|
||||||
>;
|
>;
|
||||||
type FnDataFactory = Box<Fn() -> Box<dyn Future<Item = Box<DataFactory>, Error = ()>>>;
|
type FnDataFactory = Box<Fn() -> Box<dyn Future<Item = Box<DataFactory>, Error = ()>>>;
|
||||||
|
|
||||||
@ -297,14 +297,14 @@ impl NewService for AppRoutingFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type HttpServiceFut = Box<Future<Item = HttpService, Error = ()>>;
|
type HttpServiceFut = Box<dyn Future<Item = HttpService, Error = ()>>;
|
||||||
|
|
||||||
/// Create app service
|
/// Create app service
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct AppRoutingFactoryResponse {
|
pub struct AppRoutingFactoryResponse {
|
||||||
fut: Vec<CreateAppRoutingItem>,
|
fut: Vec<CreateAppRoutingItem>,
|
||||||
default: Option<HttpService>,
|
default: Option<HttpService>,
|
||||||
default_fut: Option<Box<Future<Item = HttpService, Error = ()>>>,
|
default_fut: Option<Box<dyn Future<Item = HttpService, Error = ()>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CreateAppRoutingItem {
|
enum CreateAppRoutingItem {
|
||||||
|
@ -118,7 +118,7 @@ impl<T: 'static> FromRequest for Data<T> {
|
|||||||
impl<T: 'static> DataFactory for Data<T> {
|
impl<T: 'static> DataFactory for Data<T> {
|
||||||
fn create(&self, extensions: &mut Extensions) -> bool {
|
fn create(&self, extensions: &mut Extensions) -> bool {
|
||||||
if !extensions.contains::<Data<T>>() {
|
if !extensions.contains::<Data<T>>() {
|
||||||
let _ = extensions.insert(Data(self.0.clone()));
|
extensions.insert(Data(self.0.clone()));
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -94,7 +94,7 @@ where
|
|||||||
{
|
{
|
||||||
type Config = T::Config;
|
type Config = T::Config;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Box<Future<Item = Option<T>, Error = Error>>;
|
type Future = Box<dyn Future<Item = Option<T>, Error = Error>>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||||
@ -165,7 +165,7 @@ where
|
|||||||
{
|
{
|
||||||
type Config = T::Config;
|
type Config = T::Config;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Box<Future<Item = Result<T, T::Error>, Error = Error>>;
|
type Future = Box<dyn Future<Item = Result<T, T::Error>, Error = Error>>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||||
|
@ -250,7 +250,7 @@ where
|
|||||||
Ok(Async::Ready(res)) => {
|
Ok(Async::Ready(res)) => {
|
||||||
self.fut2 =
|
self.fut2 =
|
||||||
Some(res.respond_to(self.req.as_ref().unwrap()).into_future());
|
Some(res.respond_to(self.req.as_ref().unwrap()).into_future());
|
||||||
return self.poll();
|
self.poll()
|
||||||
}
|
}
|
||||||
Ok(Async::NotReady) => Ok(Async::NotReady),
|
Ok(Async::NotReady) => Ok(Async::NotReady),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -25,7 +25,11 @@ impl ConnectionInfo {
|
|||||||
Ref::map(req.extensions(), |e| e.get().unwrap())
|
Ref::map(req.extensions(), |e| e.get().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::cyclomatic_complexity)]
|
#[allow(
|
||||||
|
clippy::cyclomatic_complexity,
|
||||||
|
clippy::cognitive_complexity,
|
||||||
|
clippy::borrow_interior_mutable_const
|
||||||
|
)]
|
||||||
fn new(req: &RequestHead, cfg: &AppConfig) -> ConnectionInfo {
|
fn new(req: &RequestHead, cfg: &AppConfig) -> ConnectionInfo {
|
||||||
let mut host = None;
|
let mut host = None;
|
||||||
let mut scheme = None;
|
let mut scheme = None;
|
||||||
|
@ -134,6 +134,8 @@ pub mod dev {
|
|||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
pub use crate::config::{AppConfig, AppService};
|
pub use crate::config::{AppConfig, AppService};
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub use crate::handler::{AsyncFactory, Factory};
|
||||||
pub use crate::info::ConnectionInfo;
|
pub use crate::info::ConnectionInfo;
|
||||||
pub use crate::rmap::ResourceMap;
|
pub use crate::rmap::ResourceMap;
|
||||||
pub use crate::service::{
|
pub use crate::service::{
|
||||||
|
@ -107,6 +107,7 @@ where
|
|||||||
self.service.poll_ready()
|
self.service.poll_ready()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::borrow_interior_mutable_const)]
|
||||||
fn call(&mut self, req: ServiceRequest) -> Self::Future {
|
fn call(&mut self, req: ServiceRequest) -> Self::Future {
|
||||||
// negotiate content-encoding
|
// negotiate content-encoding
|
||||||
let encoding = if let Some(val) = req.headers().get(&ACCEPT_ENCODING) {
|
let encoding = if let Some(val) = req.headers().get(&ACCEPT_ENCODING) {
|
||||||
|
@ -119,12 +119,13 @@ where
|
|||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<B>;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
|
type Future = Box<dyn Future<Item = Self::Response, Error = Self::Error>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
self.service.poll_ready()
|
self.service.poll_ready()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::borrow_interior_mutable_const)]
|
||||||
fn call(&mut self, req: ServiceRequest) -> Self::Future {
|
fn call(&mut self, req: ServiceRequest) -> Self::Future {
|
||||||
let inner = self.inner.clone();
|
let inner = self.inner.clone();
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ pub enum ErrorHandlerResponse<B> {
|
|||||||
/// New http response got generated
|
/// New http response got generated
|
||||||
Response(ServiceResponse<B>),
|
Response(ServiceResponse<B>),
|
||||||
/// Result is a future that resolves to a new http response
|
/// Result is a future that resolves to a new http response
|
||||||
Future(Box<Future<Item = ServiceResponse<B>, Error = Error>>),
|
Future(Box<dyn Future<Item = ServiceResponse<B>, Error = Error>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrorHandler<B> = Fn(ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>>;
|
type ErrorHandler<B> = Fn(ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>>;
|
||||||
@ -117,7 +117,7 @@ where
|
|||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<B>;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
|
type Future = Box<dyn Future<Item = Self::Response, Error = Self::Error>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
self.service.poll_ready()
|
self.service.poll_ready()
|
||||||
|
@ -415,9 +415,9 @@ impl FormatText {
|
|||||||
))
|
))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
FormatText::UrlPath => *self = FormatText::Str(format!("{}", req.path())),
|
FormatText::UrlPath => *self = FormatText::Str(req.path().to_string()),
|
||||||
FormatText::RequestTime => {
|
FormatText::RequestTime => {
|
||||||
*self = FormatText::Str(format!("{}", now.rfc3339()))
|
*self = FormatText::Str(now.rfc3339().to_string())
|
||||||
}
|
}
|
||||||
FormatText::RequestHeader(ref name) => {
|
FormatText::RequestHeader(ref name) => {
|
||||||
let s = if let Some(val) = req.headers().get(name) {
|
let s = if let Some(val) = req.headers().get(name) {
|
||||||
|
@ -174,6 +174,12 @@ impl HttpRequest {
|
|||||||
self.url_for(name, &NO_PARAMS)
|
self.url_for(name, &NO_PARAMS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
/// Get a reference to a `ResourceMap` of current application.
|
||||||
|
pub fn resource_map(&self) -> &ResourceMap {
|
||||||
|
&self.0.rmap
|
||||||
|
}
|
||||||
|
|
||||||
/// Peer socket address
|
/// Peer socket address
|
||||||
///
|
///
|
||||||
/// Peer address is actual socket address, if proxy is used in front of
|
/// Peer address is actual socket address, if proxy is used in front of
|
||||||
|
@ -245,7 +245,7 @@ where
|
|||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use actix_web::*;
|
/// # use actix_web::*;
|
||||||
/// # use futures::future::Future;
|
/// # use futures::future::Future;
|
||||||
/// # fn index(req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
/// # fn index(req: HttpRequest) -> Box<dyn Future<Item=HttpResponse, Error=Error>> {
|
||||||
/// # unimplemented!()
|
/// # unimplemented!()
|
||||||
/// # }
|
/// # }
|
||||||
/// App::new().service(web::resource("/").route(web::route().to_async(index)));
|
/// App::new().service(web::resource("/").route(web::route().to_async(index)));
|
||||||
@ -426,7 +426,7 @@ where
|
|||||||
fn into_new_service(self) -> T {
|
fn into_new_service(self) -> T {
|
||||||
*self.factory_ref.borrow_mut() = Some(ResourceFactory {
|
*self.factory_ref.borrow_mut() = Some(ResourceFactory {
|
||||||
routes: self.routes,
|
routes: self.routes,
|
||||||
data: self.data.map(|data| Rc::new(data)),
|
data: self.data.map(Rc::new),
|
||||||
default: self.default,
|
default: self.default,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -478,7 +478,7 @@ pub struct CreateResourceService {
|
|||||||
fut: Vec<CreateRouteServiceItem>,
|
fut: Vec<CreateRouteServiceItem>,
|
||||||
data: Option<Rc<Extensions>>,
|
data: Option<Rc<Extensions>>,
|
||||||
default: Option<HttpService>,
|
default: Option<HttpService>,
|
||||||
default_fut: Option<Box<Future<Item = HttpService, Error = ()>>>,
|
default_fut: Option<Box<dyn Future<Item = HttpService, Error = ()>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Future for CreateResourceService {
|
impl Future for CreateResourceService {
|
||||||
@ -542,7 +542,7 @@ impl Service for ResourceService {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Either<
|
type Future = Either<
|
||||||
FutureResult<ServiceResponse, Error>,
|
FutureResult<ServiceResponse, Error>,
|
||||||
Box<Future<Item = ServiceResponse, Error = Error>>,
|
Box<dyn Future<Item = ServiceResponse, Error = Error>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
|
@ -337,7 +337,7 @@ impl<T: Responder> Future for CustomResponderFut<T> {
|
|||||||
/// use actix_web::{Either, Error, HttpResponse};
|
/// use actix_web::{Either, Error, HttpResponse};
|
||||||
///
|
///
|
||||||
/// type RegisterResult =
|
/// type RegisterResult =
|
||||||
/// Either<HttpResponse, Box<Future<Item = HttpResponse, Error = Error>>>;
|
/// Either<HttpResponse, Box<dyn Future<Item = HttpResponse, Error = Error>>>;
|
||||||
///
|
///
|
||||||
/// fn index() -> RegisterResult {
|
/// fn index() -> RegisterResult {
|
||||||
/// if is_a_variant() {
|
/// if is_a_variant() {
|
||||||
@ -411,13 +411,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I, E> Responder for Box<Future<Item = I, Error = E>>
|
impl<I, E> Responder for Box<dyn Future<Item = I, Error = E>>
|
||||||
where
|
where
|
||||||
I: Responder + 'static,
|
I: Responder + 'static,
|
||||||
E: Into<Error> + 'static,
|
E: Into<Error> + 'static,
|
||||||
{
|
{
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Box<Future<Item = Response, Error = Error>>;
|
type Future = Box<dyn Future<Item = Response, Error = Error>>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn respond_to(self, req: &HttpRequest) -> Self::Future {
|
fn respond_to(self, req: &HttpRequest) -> Self::Future {
|
||||||
|
@ -123,7 +123,7 @@ impl ResourceMap {
|
|||||||
I: AsRef<str>,
|
I: AsRef<str>,
|
||||||
{
|
{
|
||||||
if let Some(pattern) = self.named.get(name) {
|
if let Some(pattern) = self.named.get(name) {
|
||||||
if pattern.pattern().starts_with("/") {
|
if pattern.pattern().starts_with('/') {
|
||||||
self.fill_root(path, elements)?;
|
self.fill_root(path, elements)?;
|
||||||
}
|
}
|
||||||
if pattern.resource_path(path, elements) {
|
if pattern.resource_path(path, elements) {
|
||||||
|
15
src/route.rs
15
src/route.rs
@ -19,7 +19,7 @@ type BoxedRouteService<Req, Res> = Box<
|
|||||||
Error = Error,
|
Error = Error,
|
||||||
Future = Either<
|
Future = Either<
|
||||||
FutureResult<Res, Error>,
|
FutureResult<Res, Error>,
|
||||||
Box<Future<Item = Res, Error = Error>>,
|
Box<dyn Future<Item = Res, Error = Error>>,
|
||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
>;
|
>;
|
||||||
@ -32,7 +32,7 @@ type BoxedRouteNewService<Req, Res> = Box<
|
|||||||
Error = Error,
|
Error = Error,
|
||||||
InitError = (),
|
InitError = (),
|
||||||
Service = BoxedRouteService<Req, Res>,
|
Service = BoxedRouteService<Req, Res>,
|
||||||
Future = Box<Future<Item = BoxedRouteService<Req, Res>, Error = ()>>,
|
Future = Box<dyn Future<Item = BoxedRouteService<Req, Res>, Error = ()>>,
|
||||||
>,
|
>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
@ -78,8 +78,9 @@ impl NewService for Route {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type RouteFuture =
|
type RouteFuture = Box<
|
||||||
Box<Future<Item = BoxedRouteService<ServiceRequest, ServiceResponse>, Error = ()>>;
|
dyn Future<Item = BoxedRouteService<ServiceRequest, ServiceResponse>, Error = ()>,
|
||||||
|
>;
|
||||||
|
|
||||||
pub struct CreateRouteService {
|
pub struct CreateRouteService {
|
||||||
fut: RouteFuture,
|
fut: RouteFuture,
|
||||||
@ -123,7 +124,7 @@ impl Service for RouteService {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Either<
|
type Future = Either<
|
||||||
FutureResult<Self::Response, Self::Error>,
|
FutureResult<Self::Response, Self::Error>,
|
||||||
Box<Future<Item = Self::Response, Error = Self::Error>>,
|
Box<dyn Future<Item = Self::Response, Error = Self::Error>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
@ -317,7 +318,7 @@ where
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Service = BoxedRouteService<ServiceRequest, Self::Response>;
|
type Service = BoxedRouteService<ServiceRequest, Self::Response>;
|
||||||
type Future = Box<Future<Item = Self::Service, Error = Self::InitError>>;
|
type Future = Box<dyn Future<Item = Self::Service, Error = Self::InitError>>;
|
||||||
|
|
||||||
fn new_service(&self, _: &()) -> Self::Future {
|
fn new_service(&self, _: &()) -> Self::Future {
|
||||||
Box::new(
|
Box::new(
|
||||||
@ -351,7 +352,7 @@ where
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Either<
|
type Future = Either<
|
||||||
FutureResult<Self::Response, Self::Error>,
|
FutureResult<Self::Response, Self::Error>,
|
||||||
Box<Future<Item = Self::Response, Error = Self::Error>>,
|
Box<dyn Future<Item = Self::Response, Error = Self::Error>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
|
10
src/scope.rs
10
src/scope.rs
@ -28,7 +28,7 @@ type HttpService = BoxedService<ServiceRequest, ServiceResponse, Error>;
|
|||||||
type HttpNewService = BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>;
|
type HttpNewService = BoxedNewService<(), ServiceRequest, ServiceResponse, Error, ()>;
|
||||||
type BoxedResponse = Either<
|
type BoxedResponse = Either<
|
||||||
FutureResult<ServiceResponse, Error>,
|
FutureResult<ServiceResponse, Error>,
|
||||||
Box<Future<Item = ServiceResponse, Error = Error>>,
|
Box<dyn Future<Item = ServiceResponse, Error = Error>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// Resources scope.
|
/// Resources scope.
|
||||||
@ -195,7 +195,7 @@ where
|
|||||||
self.external.extend(cfg.external);
|
self.external.extend(cfg.external);
|
||||||
|
|
||||||
if !cfg.data.is_empty() {
|
if !cfg.data.is_empty() {
|
||||||
let mut data = self.data.unwrap_or_else(|| Extensions::new());
|
let mut data = self.data.unwrap_or_else(Extensions::new);
|
||||||
|
|
||||||
for value in cfg.data.iter() {
|
for value in cfg.data.iter() {
|
||||||
value.create(&mut data);
|
value.create(&mut data);
|
||||||
@ -425,7 +425,7 @@ where
|
|||||||
|
|
||||||
// complete scope pipeline creation
|
// complete scope pipeline creation
|
||||||
*self.factory_ref.borrow_mut() = Some(ScopeFactory {
|
*self.factory_ref.borrow_mut() = Some(ScopeFactory {
|
||||||
data: self.data.take().map(|data| Rc::new(data)),
|
data: self.data.take().map(Rc::new),
|
||||||
default: self.default.clone(),
|
default: self.default.clone(),
|
||||||
services: Rc::new(
|
services: Rc::new(
|
||||||
cfg.into_services()
|
cfg.into_services()
|
||||||
@ -503,10 +503,10 @@ pub struct ScopeFactoryResponse {
|
|||||||
fut: Vec<CreateScopeServiceItem>,
|
fut: Vec<CreateScopeServiceItem>,
|
||||||
data: Option<Rc<Extensions>>,
|
data: Option<Rc<Extensions>>,
|
||||||
default: Option<HttpService>,
|
default: Option<HttpService>,
|
||||||
default_fut: Option<Box<Future<Item = HttpService, Error = ()>>>,
|
default_fut: Option<Box<dyn Future<Item = HttpService, Error = ()>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
type HttpServiceFut = Box<Future<Item = HttpService, Error = ()>>;
|
type HttpServiceFut = Box<dyn Future<Item = HttpService, Error = ()>>;
|
||||||
|
|
||||||
enum CreateScopeServiceItem {
|
enum CreateScopeServiceItem {
|
||||||
Future(Option<ResourceDef>, Option<Guards>, HttpServiceFut),
|
Future(Option<ResourceDef>, Option<Guards>, HttpServiceFut),
|
||||||
|
@ -18,6 +18,7 @@ use crate::dev::insert_slash;
|
|||||||
use crate::guard::Guard;
|
use crate::guard::Guard;
|
||||||
use crate::info::ConnectionInfo;
|
use crate::info::ConnectionInfo;
|
||||||
use crate::request::HttpRequest;
|
use crate::request::HttpRequest;
|
||||||
|
use crate::rmap::ResourceMap;
|
||||||
|
|
||||||
pub trait HttpServiceFactory {
|
pub trait HttpServiceFactory {
|
||||||
fn register(self, config: &mut AppService);
|
fn register(self, config: &mut AppService);
|
||||||
@ -169,10 +170,17 @@ impl ServiceRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
/// Get a mutable reference to the Path parameters.
|
||||||
pub fn match_info_mut(&mut self) -> &mut Path<Url> {
|
pub fn match_info_mut(&mut self) -> &mut Path<Url> {
|
||||||
self.0.match_info_mut()
|
self.0.match_info_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
/// Get a reference to a `ResourceMap` of current application.
|
||||||
|
pub fn resource_map(&self) -> &ResourceMap {
|
||||||
|
self.0.resource_map()
|
||||||
|
}
|
||||||
|
|
||||||
/// Service configuration
|
/// Service configuration
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn app_config(&self) -> &AppConfig {
|
pub fn app_config(&self) -> &AppConfig {
|
||||||
|
@ -73,7 +73,7 @@ where
|
|||||||
{
|
{
|
||||||
type Config = FormConfig;
|
type Config = FormConfig;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Box<Future<Item = Self, Error = Error>>;
|
type Future = Box<dyn Future<Item = Self, Error = Error>>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||||
@ -187,11 +187,12 @@ pub struct UrlEncoded<U> {
|
|||||||
length: Option<usize>,
|
length: Option<usize>,
|
||||||
encoding: &'static Encoding,
|
encoding: &'static Encoding,
|
||||||
err: Option<UrlencodedError>,
|
err: Option<UrlencodedError>,
|
||||||
fut: Option<Box<Future<Item = U, Error = UrlencodedError>>>,
|
fut: Option<Box<dyn Future<Item = U, Error = UrlencodedError>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U> UrlEncoded<U> {
|
impl<U> UrlEncoded<U> {
|
||||||
/// Create a new future to URL encode a request
|
/// Create a new future to URL encode a request
|
||||||
|
#[allow(clippy::borrow_interior_mutable_const)]
|
||||||
pub fn new(req: &HttpRequest, payload: &mut Payload) -> UrlEncoded<U> {
|
pub fn new(req: &HttpRequest, payload: &mut Payload) -> UrlEncoded<U> {
|
||||||
// check content type
|
// check content type
|
||||||
if req.content_type().to_lowercase() != "application/x-www-form-urlencoded" {
|
if req.content_type().to_lowercase() != "application/x-www-form-urlencoded" {
|
||||||
|
@ -169,7 +169,7 @@ where
|
|||||||
T: DeserializeOwned + 'static,
|
T: DeserializeOwned + 'static,
|
||||||
{
|
{
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Box<Future<Item = Self, Error = Error>>;
|
type Future = Box<dyn Future<Item = Self, Error = Error>>;
|
||||||
type Config = JsonConfig;
|
type Config = JsonConfig;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -290,7 +290,7 @@ pub struct JsonBody<U> {
|
|||||||
length: Option<usize>,
|
length: Option<usize>,
|
||||||
stream: Option<Decompress<Payload>>,
|
stream: Option<Decompress<Payload>>,
|
||||||
err: Option<JsonPayloadError>,
|
err: Option<JsonPayloadError>,
|
||||||
fut: Option<Box<Future<Item = U, Error = JsonPayloadError>>>,
|
fut: Option<Box<dyn Future<Item = U, Error = JsonPayloadError>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U> JsonBody<U>
|
impl<U> JsonBody<U>
|
||||||
@ -298,6 +298,7 @@ where
|
|||||||
U: DeserializeOwned + 'static,
|
U: DeserializeOwned + 'static,
|
||||||
{
|
{
|
||||||
/// Create `JsonBody` for request.
|
/// Create `JsonBody` for request.
|
||||||
|
#[allow(clippy::borrow_interior_mutable_const)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
req: &HttpRequest,
|
req: &HttpRequest,
|
||||||
payload: &mut Payload,
|
payload: &mut Payload,
|
||||||
|
@ -124,7 +124,7 @@ impl FromRequest for Bytes {
|
|||||||
type Config = PayloadConfig;
|
type Config = PayloadConfig;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future =
|
type Future =
|
||||||
Either<Box<Future<Item = Bytes, Error = Error>>, FutureResult<Bytes, Error>>;
|
Either<Box<dyn Future<Item = Bytes, Error = Error>>, FutureResult<Bytes, Error>>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
||||||
@ -177,8 +177,10 @@ impl FromRequest for Bytes {
|
|||||||
impl FromRequest for String {
|
impl FromRequest for String {
|
||||||
type Config = PayloadConfig;
|
type Config = PayloadConfig;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future =
|
type Future = Either<
|
||||||
Either<Box<Future<Item = String, Error = Error>>, FutureResult<String, Error>>;
|
Box<dyn Future<Item = String, Error = Error>>,
|
||||||
|
FutureResult<String, Error>,
|
||||||
|
>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
||||||
@ -291,11 +293,12 @@ pub struct HttpMessageBody {
|
|||||||
length: Option<usize>,
|
length: Option<usize>,
|
||||||
stream: Option<dev::Decompress<dev::Payload>>,
|
stream: Option<dev::Decompress<dev::Payload>>,
|
||||||
err: Option<PayloadError>,
|
err: Option<PayloadError>,
|
||||||
fut: Option<Box<Future<Item = Bytes, Error = PayloadError>>>,
|
fut: Option<Box<dyn Future<Item = Bytes, Error = PayloadError>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HttpMessageBody {
|
impl HttpMessageBody {
|
||||||
/// Create `MessageBody` for request.
|
/// Create `MessageBody` for request.
|
||||||
|
#[allow(clippy::borrow_interior_mutable_const)]
|
||||||
pub fn new(req: &HttpRequest, payload: &mut dev::Payload) -> HttpMessageBody {
|
pub fn new(req: &HttpRequest, payload: &mut dev::Payload) -> HttpMessageBody {
|
||||||
let mut len = None;
|
let mut len = None;
|
||||||
if let Some(l) = req.headers().get(&header::CONTENT_LENGTH) {
|
if let Some(l) = req.headers().get(&header::CONTENT_LENGTH) {
|
||||||
|
Reference in New Issue
Block a user