mirror of
https://github.com/actix/actix-web.git
synced 2025-04-10 20:04:05 +00:00
Merge branch 'master' into master
This commit is contained in:
commit
1aa64187c4
18 changed files with 127 additions and 95 deletions
26
Cargo.toml
26
Cargo.toml
|
@ -60,21 +60,21 @@ secure-cookies = ["actix-http/secure-cookies"]
|
|||
fail = ["actix-http/fail"]
|
||||
|
||||
# openssl
|
||||
openssl = ["open-ssl", "actix-tls/openssl", "awc/openssl"]
|
||||
openssl = ["actix-tls/openssl", "awc/openssl"]
|
||||
|
||||
# rustls
|
||||
rustls = ["rust-tls", "actix-tls/rustls", "awc/rustls"]
|
||||
rustls = ["actix-tls/rustls", "awc/rustls"]
|
||||
|
||||
[dependencies]
|
||||
actix-codec = "0.2.0-alpha.3"
|
||||
actix-service = "1.0.0-alpha.4"
|
||||
actix-utils = "1.0.0-alpha.3"
|
||||
actix-codec = "0.2.0"
|
||||
actix-service = "1.0.0"
|
||||
actix-utils = "1.0.1"
|
||||
actix-router = "0.2.0"
|
||||
actix-rt = "1.0.0-alpha.3"
|
||||
actix-server = "1.0.0-alpha.4"
|
||||
actix-testing = "1.0.0-alpha.3"
|
||||
actix-rt = "1.0.0"
|
||||
actix-server = "1.0.0"
|
||||
actix-testing = "1.0.0"
|
||||
actix-threadpool = "0.3.0"
|
||||
actix-tls = { version = "1.0.0-alpha.3" }
|
||||
actix-tls = "1.0.0"
|
||||
|
||||
actix-web-codegen = "0.2.0-alpha.2"
|
||||
actix-http = "1.0.0-alpha.4"
|
||||
|
@ -96,19 +96,17 @@ serde_urlencoded = "0.6.1"
|
|||
time = "0.1.42"
|
||||
url = "2.1"
|
||||
|
||||
# ssl support
|
||||
open-ssl = { version="0.10", package="openssl", optional = true }
|
||||
rust-tls = { version = "0.16", package="rustls", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
# actix = "0.8.3"
|
||||
actix-connect = "1.0.0-alpha.3"
|
||||
actix-connect = "1.0.0"
|
||||
actix-http-test = "1.0.0-alpha.3"
|
||||
rand = "0.7"
|
||||
env_logger = "0.6"
|
||||
serde_derive = "1.0"
|
||||
brotli = "3.3.0"
|
||||
flate2 = "1.0.2"
|
||||
open-ssl = { version="0.10", package = "openssl" }
|
||||
rust_tls = { version = "0.16.0", package = "rustls" }
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
|
|
@ -18,9 +18,9 @@ path = "src/lib.rs"
|
|||
|
||||
[dependencies]
|
||||
actix-web = "2.0.0-alpha.3"
|
||||
actix-service = "1.0.0-alpha.3"
|
||||
actix-service = "1.0.0"
|
||||
derive_more = "0.99.2"
|
||||
futures = "0.3.1"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "1.0.0-alpha.3"
|
||||
actix-rt = "1.0.0"
|
||||
|
|
|
@ -20,7 +20,7 @@ path = "src/lib.rs"
|
|||
[dependencies]
|
||||
actix-web = { version = "2.0.0-alpha.3", default-features = false }
|
||||
actix-http = "1.0.0-alpha.3"
|
||||
actix-service = "1.0.0-alpha.3"
|
||||
actix-service = "1.0.0"
|
||||
bitflags = "1"
|
||||
bytes = "0.5.2"
|
||||
futures = "0.3.1"
|
||||
|
@ -32,5 +32,5 @@ percent-encoding = "2.1"
|
|||
v_htmlescape = "0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "1.0.0-alpha.3"
|
||||
actix-rt = "1.0.0"
|
||||
actix-web = { version = "2.0.0-alpha.3", features=["openssl"] }
|
||||
|
|
|
@ -20,10 +20,10 @@ name = "actix_framed"
|
|||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
actix-codec = "0.2.0-alpha.3"
|
||||
actix-service = "1.0.0-alpha.3"
|
||||
actix-codec = "0.2.0"
|
||||
actix-service = "1.0.0"
|
||||
actix-router = "0.2.0"
|
||||
actix-rt = "1.0.0-alpha.3"
|
||||
actix-rt = "1.0.0"
|
||||
actix-http = "1.0.0-alpha.3"
|
||||
|
||||
bytes = "0.5.2"
|
||||
|
@ -32,7 +32,7 @@ pin-project = "0.4.6"
|
|||
log = "0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-server = { version = "1.0.0-alpha.3" }
|
||||
actix-connect = { version = "1.0.0-alpha.3", features=["openssl"] }
|
||||
actix-server = "1.0.0"
|
||||
actix-connect = { version = "1.0.0", features=["openssl"] }
|
||||
actix-http-test = { version = "1.0.0-alpha.3", features=["openssl"] }
|
||||
actix-utils = "1.0.0-alpha.3"
|
||||
actix-utils = "1.0.0"
|
||||
|
|
|
@ -2,7 +2,7 @@ use actix_codec::{AsyncRead, AsyncWrite};
|
|||
use actix_http::{body, http::StatusCode, ws, Error, HttpService, Response};
|
||||
use actix_http_test::TestServer;
|
||||
use actix_service::{pipeline_factory, IntoServiceFactory, ServiceFactory};
|
||||
use actix_utils::framed::FramedTransport;
|
||||
use actix_utils::framed::Dispatcher;
|
||||
use bytes::BytesMut;
|
||||
use futures::{future, SinkExt, StreamExt};
|
||||
|
||||
|
@ -18,7 +18,7 @@ async fn ws_service<T: AsyncRead + AsyncWrite>(
|
|||
.send((res, body::BodySize::None).into())
|
||||
.await
|
||||
.unwrap();
|
||||
FramedTransport::new(framed.into_framed(ws::Codec::new()), service)
|
||||
Dispatcher::new(framed.into_framed(ws::Codec::new()), service)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "actix-http"
|
||||
version = "1.0.0-alpha.5"
|
||||
version = "1.0.0-alpha.6"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Actix http primitives"
|
||||
readme = "README.md"
|
||||
|
@ -44,13 +44,13 @@ fail = ["failure"]
|
|||
secure-cookies = ["ring"]
|
||||
|
||||
[dependencies]
|
||||
actix-service = "1.0.0-alpha.4"
|
||||
actix-codec = "0.2.0-alpha.3"
|
||||
actix-connect = "1.0.0-alpha.3"
|
||||
actix-utils = "1.0.0-alpha.3"
|
||||
actix-rt = "1.0.0-alpha.3"
|
||||
actix-service = "1.0.0"
|
||||
actix-codec = "0.2.0"
|
||||
actix-connect = "1.0.0"
|
||||
actix-utils = "1.0.1"
|
||||
actix-rt = "1.0.0"
|
||||
actix-threadpool = "0.3.0"
|
||||
actix-tls = { version = "1.0.0-alpha.3", optional = true }
|
||||
actix-tls = { version = "1.0.0", optional = true }
|
||||
|
||||
base64 = "0.11"
|
||||
bitflags = "1.0"
|
||||
|
@ -92,10 +92,10 @@ flate2 = { version="1.0.7", optional = true, default-features = false }
|
|||
failure = { version = "0.1.5", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-server = { version = "1.0.0-alpha.4" }
|
||||
actix-connect = { version = "1.0.0-alpha.3", features=["openssl"] }
|
||||
actix-server = "1.0.0"
|
||||
actix-connect = { version = "1.0.0", features=["openssl"] }
|
||||
actix-http-test = { version = "1.0.0-alpha.3", features=["openssl"] }
|
||||
actix-tls = { version = "1.0.0-alpha.3", features=["openssl"] }
|
||||
actix-tls = { version = "1.0.0", features=["openssl"] }
|
||||
env_logger = "0.6"
|
||||
serde_derive = "1.0"
|
||||
open-ssl = { version="0.10", package = "openssl" }
|
||||
|
|
|
@ -4,19 +4,19 @@ use std::task::{Context, Poll};
|
|||
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_service::{IntoService, Service};
|
||||
use actix_utils::framed::{FramedTransport, FramedTransportError};
|
||||
use actix_utils::framed;
|
||||
|
||||
use super::{Codec, Frame, Message};
|
||||
|
||||
pub struct Transport<S, T>
|
||||
pub struct Dispatcher<S, T>
|
||||
where
|
||||
S: Service<Request = Frame, Response = Message> + 'static,
|
||||
T: AsyncRead + AsyncWrite,
|
||||
{
|
||||
inner: FramedTransport<S, T, Codec>,
|
||||
inner: framed::Dispatcher<S, T, Codec>,
|
||||
}
|
||||
|
||||
impl<S, T> Transport<S, T>
|
||||
impl<S, T> Dispatcher<S, T>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request = Frame, Response = Message>,
|
||||
|
@ -24,26 +24,26 @@ where
|
|||
S::Error: 'static,
|
||||
{
|
||||
pub fn new<F: IntoService<S>>(io: T, service: F) -> Self {
|
||||
Transport {
|
||||
inner: FramedTransport::new(Framed::new(io, Codec::new()), service),
|
||||
Dispatcher {
|
||||
inner: framed::Dispatcher::new(Framed::new(io, Codec::new()), service),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with<F: IntoService<S>>(framed: Framed<T, Codec>, service: F) -> Self {
|
||||
Transport {
|
||||
inner: FramedTransport::new(framed, service),
|
||||
Dispatcher {
|
||||
inner: framed::Dispatcher::new(framed, service),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, T> Future for Transport<S, T>
|
||||
impl<S, T> Future for Dispatcher<S, T>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request = Frame, Response = Message>,
|
||||
S::Future: 'static,
|
||||
S::Error: 'static,
|
||||
{
|
||||
type Output = Result<(), FramedTransportError<S::Error, Codec>>;
|
||||
type Output = Result<(), framed::DispatcherError<S::Error, Codec>>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
Pin::new(&mut self.inner).poll(cx)
|
|
@ -13,15 +13,15 @@ use crate::message::RequestHead;
|
|||
use crate::response::{Response, ResponseBuilder};
|
||||
|
||||
mod codec;
|
||||
mod dispatcher;
|
||||
mod frame;
|
||||
mod mask;
|
||||
mod proto;
|
||||
mod transport;
|
||||
|
||||
pub use self::codec::{Codec, Frame, Message};
|
||||
pub use self::dispatcher::Dispatcher;
|
||||
pub use self::frame::Parser;
|
||||
pub use self::proto::{hash_key, CloseCode, CloseReason, OpCode};
|
||||
pub use self::transport::Transport;
|
||||
|
||||
/// Websocket protocol errors
|
||||
#[derive(Debug, Display, From)]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_http::{body, h1, ws, Error, HttpService, Request, Response};
|
||||
use actix_http_test::TestServer;
|
||||
use actix_utils::framed::FramedTransport;
|
||||
use actix_utils::framed::Dispatcher;
|
||||
use bytes::BytesMut;
|
||||
use futures::future;
|
||||
use futures::{SinkExt, StreamExt};
|
||||
|
@ -16,7 +16,7 @@ async fn ws_service<T: AsyncRead + AsyncWrite + Unpin>(
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
FramedTransport::new(framed.into_framed(ws::Codec::new()), service)
|
||||
Dispatcher::new(framed.into_framed(ws::Codec::new()), service)
|
||||
.await
|
||||
.map_err(|_| panic!())
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@ path = "src/lib.rs"
|
|||
|
||||
[dependencies]
|
||||
actix-web = { version = "2.0.0-alpha.3", default-features = false, features = ["secure-cookies"] }
|
||||
actix-service = "1.0.0-alpha.3"
|
||||
actix-service = "1.0.0"
|
||||
futures = "0.3.1"
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
time = "0.1.42"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "1.0.0-alpha.3"
|
||||
actix-rt = "1.0.0"
|
||||
actix-http = "1.0.0-alpha.3"
|
||||
bytes = "0.5.2"
|
|
@ -1,5 +1,9 @@
|
|||
# Changes
|
||||
|
||||
## [2.0.0-alpha.4] - 2019-12-xx
|
||||
|
||||
* Multipart handling now handles Pending during read of boundary #1205
|
||||
|
||||
## [0.2.0-alpha.2] - 2019-12-03
|
||||
|
||||
* Migrate to `std::future`
|
||||
|
|
|
@ -19,8 +19,8 @@ path = "src/lib.rs"
|
|||
|
||||
[dependencies]
|
||||
actix-web = { version = "2.0.0-alpha.3", default-features = false }
|
||||
actix-service = "1.0.0-alpha.3"
|
||||
actix-utils = "1.0.0-alpha.3"
|
||||
actix-service = "1.0.0"
|
||||
actix-utils = "1.0.0"
|
||||
bytes = "0.5.2"
|
||||
derive_more = "0.99.2"
|
||||
httparse = "1.3"
|
||||
|
@ -31,5 +31,5 @@ time = "0.1"
|
|||
twoway = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "1.0.0-alpha.3"
|
||||
actix-rt = "1.0.0"
|
||||
actix-http = "1.0.0-alpha.3"
|
|
@ -610,7 +610,7 @@ impl InnerField {
|
|||
}
|
||||
|
||||
match payload.readline() {
|
||||
Ok(None) => Poll::Ready(None),
|
||||
Ok(None) => Poll::Pending,
|
||||
Ok(Some(line)) => {
|
||||
if line.as_ref() != b"\r\n" {
|
||||
log::warn!("multipart field did not read all the data or it is malformed");
|
||||
|
@ -867,6 +867,42 @@ mod tests {
|
|||
|
||||
(tx, rx.map(|res| res.map_err(|_| panic!())))
|
||||
}
|
||||
// Stream that returns from a Bytes, one char at a time and Pending every other poll()
|
||||
struct SlowStream {
|
||||
bytes: Bytes,
|
||||
pos: usize,
|
||||
ready: bool,
|
||||
}
|
||||
|
||||
impl SlowStream {
|
||||
fn new(bytes: Bytes) -> SlowStream {
|
||||
return SlowStream {
|
||||
bytes: bytes,
|
||||
pos: 0,
|
||||
ready: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Stream for SlowStream {
|
||||
type Item = Result<Bytes, PayloadError>;
|
||||
|
||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
|
||||
let this = self.get_mut();
|
||||
if !this.ready {
|
||||
this.ready = true;
|
||||
cx.waker().wake_by_ref();
|
||||
return Poll::Pending;
|
||||
}
|
||||
if this.pos == this.bytes.len() {
|
||||
return Poll::Ready(None);
|
||||
}
|
||||
let res = Poll::Ready(Some(Ok(this.bytes.slice(this.pos..(this.pos + 1)))));
|
||||
this.pos += 1;
|
||||
this.ready = false;
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
fn create_simple_request_with_header() -> (Bytes, HeaderMap) {
|
||||
let bytes = Bytes::from(
|
||||
|
@ -969,12 +1005,22 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
// Loops, collecting all bytes until end-of-field
|
||||
async fn get_whole_field(field: &mut Field) -> BytesMut {
|
||||
let mut b = BytesMut::new();
|
||||
loop {
|
||||
match field.next().await {
|
||||
Some(Ok(chunk)) => b.extend_from_slice(&chunk),
|
||||
None => return b,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_stream() {
|
||||
let (sender, payload) = create_stream();
|
||||
let (bytes, headers) = create_simple_request_with_header();
|
||||
|
||||
sender.send(Ok(bytes)).unwrap();
|
||||
let payload = SlowStream::new(bytes);
|
||||
|
||||
let mut multipart = Multipart::new(&headers, payload);
|
||||
match multipart.next().await.unwrap() {
|
||||
|
@ -986,14 +1032,7 @@ mod tests {
|
|||
assert_eq!(field.content_type().type_(), mime::TEXT);
|
||||
assert_eq!(field.content_type().subtype(), mime::PLAIN);
|
||||
|
||||
match field.next().await.unwrap() {
|
||||
Ok(chunk) => assert_eq!(chunk, "test"),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
match field.next().await {
|
||||
None => (),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
assert_eq!(get_whole_field(&mut field).await, "test");
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
@ -1003,14 +1042,7 @@ mod tests {
|
|||
assert_eq!(field.content_type().type_(), mime::TEXT);
|
||||
assert_eq!(field.content_type().subtype(), mime::PLAIN);
|
||||
|
||||
match field.next().await {
|
||||
Some(Ok(chunk)) => assert_eq!(chunk, "data"),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
match field.next().await {
|
||||
None => (),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
assert_eq!(get_whole_field(&mut field).await, "data");
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ cookie-session = ["actix-web/secure-cookies"]
|
|||
|
||||
[dependencies]
|
||||
actix-web = "2.0.0-alpha.3"
|
||||
actix-service = "1.0.0-alpha.3"
|
||||
actix-service = "1.0.0"
|
||||
bytes = "0.5.2"
|
||||
derive_more = "0.99.2"
|
||||
futures = "0.3.1"
|
||||
|
@ -34,4 +34,4 @@ serde_json = "1.0"
|
|||
time = "0.1.42"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "1.0.0-alpha.3"
|
||||
actix-rt = "1.0.0"
|
||||
|
|
|
@ -39,10 +39,10 @@ flate2-zlib = ["actix-http/flate2-zlib"]
|
|||
flate2-rust = ["actix-http/flate2-rust"]
|
||||
|
||||
[dependencies]
|
||||
actix-codec = "0.2.0-alpha.3"
|
||||
actix-service = "1.0.0-alpha.4"
|
||||
actix-codec = "0.2.0"
|
||||
actix-service = "1.0.0"
|
||||
actix-http = "1.0.0-alpha.4"
|
||||
actix-rt = "1.0.0-alpha.3"
|
||||
actix-rt = "1.0.0"
|
||||
|
||||
base64 = "0.11"
|
||||
bytes = "0.5.2"
|
||||
|
@ -59,13 +59,13 @@ open-ssl = { version="0.10", package="openssl", optional = true }
|
|||
rust-tls = { version = "0.16.0", package="rustls", optional = true, features = ["dangerous_configuration"] }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-connect = { version = "1.0.0-alpha.3", features=["openssl"] }
|
||||
actix-connect = { version = "1.0.0", features=["openssl"] }
|
||||
actix-web = { version = "2.0.0-alpha.3", features=["openssl"] }
|
||||
actix-http = { version = "1.0.0-alpha.4", features=["openssl"] }
|
||||
actix-http-test = { version = "1.0.0-alpha.3", features=["openssl"] }
|
||||
actix-utils = "1.0.0-alpha.3"
|
||||
actix-server = { version = "1.0.0-alpha.4" }
|
||||
actix-tls = { version = "1.0.0-alpha.3", features=["openssl", "rustls"] }
|
||||
actix-utils = "1.0.0"
|
||||
actix-server = "1.0.0"
|
||||
actix-tls = { version = "1.0.0", features=["openssl", "rustls"] }
|
||||
brotli = "3.3.0"
|
||||
flate2 = { version="1.0.2" }
|
||||
env_logger = "0.6"
|
||||
|
|
|
@ -42,7 +42,7 @@ async fn test_simple() {
|
|||
|
||||
// start websocket service
|
||||
let framed = framed.into_framed(ws::Codec::new());
|
||||
ws::Transport::with(framed, ws_service).await
|
||||
ws::Dispatcher::with(framed, ws_service).await
|
||||
}
|
||||
})
|
||||
.finish(|_| ok::<_, Error>(Response::NotFound()))
|
||||
|
|
|
@ -12,7 +12,7 @@ use futures::future::ok;
|
|||
use net2::TcpBuilder;
|
||||
|
||||
#[cfg(feature = "openssl")]
|
||||
use actix_tls::openssl::{SslAcceptor, SslAcceptorBuilder};
|
||||
use actix_tls::openssl::{AlpnError, SslAcceptor, SslAcceptorBuilder};
|
||||
#[cfg(feature = "rustls")]
|
||||
use actix_tls::rustls::ServerConfig as RustlsServerConfig;
|
||||
|
||||
|
@ -549,8 +549,6 @@ fn create_tcp_listener(
|
|||
#[cfg(feature = "openssl")]
|
||||
/// Configure `SslAcceptorBuilder` with custom server flags.
|
||||
fn openssl_acceptor(mut builder: SslAcceptorBuilder) -> io::Result<SslAcceptor> {
|
||||
use open_ssl::ssl::AlpnError;
|
||||
|
||||
builder.set_alpn_select_callback(|_, protos| {
|
||||
const H2: &[u8] = b"\x02h2";
|
||||
const H11: &[u8] = b"\x08http/1.1";
|
||||
|
|
|
@ -30,13 +30,13 @@ default = []
|
|||
openssl = ["open-ssl", "awc/openssl", ] # "actix-tls/openssl"]
|
||||
|
||||
[dependencies]
|
||||
actix-service = "1.0.0-alpha.3"
|
||||
actix-codec = "0.2.0-alpha.3"
|
||||
actix-connect = "1.0.0-alpha.3"
|
||||
actix-utils = "1.0.0-alpha.3"
|
||||
actix-rt = "1.0.0-alpha.3"
|
||||
actix-server = "1.0.0-alpha.3"
|
||||
actix-testing = "1.0.0-alpha.3"
|
||||
actix-service = "1.0.0"
|
||||
actix-codec = "0.2.0"
|
||||
actix-connect = "1.0.0"
|
||||
actix-utils = "1.0.0"
|
||||
actix-rt = "1.0.0"
|
||||
actix-server = "1.0.0"
|
||||
actix-testing = "1.0.0"
|
||||
awc = "1.0.0-alpha.3"
|
||||
|
||||
base64 = "0.11"
|
||||
|
|
Loading…
Reference in a new issue