1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

update actix-net dependencies

This commit is contained in:
Nikolay Kim
2019-05-12 08:34:51 -07:00
parent 4066375737
commit df08baf67f
43 changed files with 361 additions and 321 deletions

View File

@ -40,7 +40,7 @@ flate2-rust = ["actix-http/flate2-rust"]
[dependencies]
actix-codec = "0.1.2"
actix-service = "0.3.6"
actix-service = "0.4.0"
actix-http = "0.1.4"
base64 = "0.10.1"
bytes = "0.4"
@ -62,7 +62,7 @@ actix-web = { version = "1.0.0-beta.1", features=["ssl"] }
actix-http = { version = "0.1.4", features=["ssl"] }
actix-http-test = { version = "0.1.1", features=["ssl"] }
actix-utils = "0.3.4"
actix-server = { version = "0.4.3", features=["ssl"] }
actix-server = { version = "0.5.0", features=["ssl"] }
brotli2 = { version="0.3.2" }
flate2 = { version="1.0.2" }
env_logger = "0.6"

View File

@ -140,51 +140,46 @@ impl ClientBuilder {
#[cfg(test)]
mod tests {
use super::*;
use crate::test;
#[test]
fn client_basic_auth() {
test::run_on(|| {
let client = ClientBuilder::new().basic_auth("username", Some("password"));
assert_eq!(
client
.config
.headers
.get(header::AUTHORIZATION)
.unwrap()
.to_str()
.unwrap(),
"Basic dXNlcm5hbWU6cGFzc3dvcmQ="
);
let client = ClientBuilder::new().basic_auth("username", Some("password"));
assert_eq!(
client
.config
.headers
.get(header::AUTHORIZATION)
.unwrap()
.to_str()
.unwrap(),
"Basic dXNlcm5hbWU6cGFzc3dvcmQ="
);
let client = ClientBuilder::new().basic_auth("username", None);
assert_eq!(
client
.config
.headers
.get(header::AUTHORIZATION)
.unwrap()
.to_str()
.unwrap(),
"Basic dXNlcm5hbWU="
);
});
let client = ClientBuilder::new().basic_auth("username", None);
assert_eq!(
client
.config
.headers
.get(header::AUTHORIZATION)
.unwrap()
.to_str()
.unwrap(),
"Basic dXNlcm5hbWU="
);
}
#[test]
fn client_bearer_auth() {
test::run_on(|| {
let client = ClientBuilder::new().bearer_auth("someS3cr3tAutht0k3n");
assert_eq!(
client
.config
.headers
.get(header::AUTHORIZATION)
.unwrap()
.to_str()
.unwrap(),
"Bearer someS3cr3tAutht0k3n"
);
})
let client = ClientBuilder::new().bearer_auth("someS3cr3tAutht0k3n");
assert_eq!(
client
.config
.headers
.get(header::AUTHORIZATION)
.unwrap()
.to_str()
.unwrap(),
"Bearer someS3cr3tAutht0k3n"
);
}
}

View File

@ -347,10 +347,11 @@ where
#[cfg(test)]
mod tests {
use super::*;
use actix_http_test::block_on;
use futures::Async;
use serde::{Deserialize, Serialize};
use crate::{http::header, test::block_on, test::TestResponse};
use crate::{http::header, test::TestResponse};
#[test]
fn test_body() {

View File

@ -6,39 +6,10 @@ use actix_http::http::header::{self, Header, HeaderValue, IntoHeaderValue};
use actix_http::http::{HeaderName, HttpTryFrom, StatusCode, Version};
use actix_http::{h1, Payload, ResponseHead};
use bytes::Bytes;
#[cfg(test)]
use futures::Future;
use percent_encoding::{percent_encode, USERINFO_ENCODE_SET};
use crate::ClientResponse;
#[cfg(test)]
thread_local! {
static RT: std::cell::RefCell<actix_rt::Runtime> = {
std::cell::RefCell::new(actix_rt::Runtime::new().unwrap())
};
}
#[cfg(test)]
pub(crate) fn run_on<F, R>(f: F) -> R
where
F: Fn() -> R,
{
RT.with(move |rt| {
rt.borrow_mut()
.block_on(futures::future::lazy(|| Ok::<_, ()>(f())))
})
.unwrap()
}
#[cfg(test)]
pub(crate) fn block_on<F>(f: F) -> Result<F::Item, F::Error>
where
F: Future,
{
RT.with(move |rt| rt.borrow_mut().block_on(f))
}
/// Test `ClientResponse` builder
pub struct TestResponse {
head: ResponseHead,

View File

@ -318,7 +318,9 @@ impl WebsocketsRequest {
}
} else {
log::trace!("Invalid connection header: {:?}", conn);
return Err(WsClientError::InvalidConnectionHeader(conn.clone()));
return Err(WsClientError::InvalidConnectionHeader(
conn.clone(),
));
}
} else {
log::trace!("Missing connection header");
@ -462,29 +464,28 @@ mod tests {
#[test]
fn basics() {
actix_http_test::run_on(|| {
let req = Client::new()
.ws("http://localhost/")
.origin("test-origin")
.max_frame_size(100)
.server_mode()
.protocols(&["v1", "v2"])
.set_header_if_none(header::CONTENT_TYPE, "json")
.set_header_if_none(header::CONTENT_TYPE, "text")
.cookie(Cookie::build("cookie1", "value1").finish());
assert_eq!(
req.origin.as_ref().unwrap().to_str().unwrap(),
"test-origin"
);
assert_eq!(req.max_size, 100);
assert_eq!(req.server_mode, true);
assert_eq!(req.protocols, Some("v1,v2".to_string()));
assert_eq!(
req.head.headers.get(header::CONTENT_TYPE).unwrap(),
header::HeaderValue::from_static("json")
);
let _ = req.connect();
});
let req = Client::new()
.ws("http://localhost/")
.origin("test-origin")
.max_frame_size(100)
.server_mode()
.protocols(&["v1", "v2"])
.set_header_if_none(header::CONTENT_TYPE, "json")
.set_header_if_none(header::CONTENT_TYPE, "text")
.cookie(Cookie::build("cookie1", "value1").finish());
assert_eq!(
req.origin.as_ref().unwrap().to_str().unwrap(),
"test-origin"
);
assert_eq!(req.max_size, 100);
assert_eq!(req.server_mode, true);
assert_eq!(req.protocols, Some("v1,v2".to_string()));
assert_eq!(
req.head.headers.get(header::CONTENT_TYPE).unwrap(),
header::HeaderValue::from_static("json")
);
let _ = actix_http_test::block_fn(move || req.connect());
assert!(Client::new().ws("/").connect().poll().is_err());
assert!(Client::new().ws("http:///test").connect().poll().is_err());

View File

@ -15,7 +15,7 @@ use rand::Rng;
use actix_codec::{AsyncRead, AsyncWrite};
use actix_http::HttpService;
use actix_http_test::TestServer;
use actix_service::{fn_service, NewService};
use actix_service::{service_fn, NewService};
use actix_web::http::{Cookie, Version};
use actix_web::middleware::{BodyEncoding, Compress};
use actix_web::{http::header, web, App, Error, HttpMessage, HttpRequest, HttpResponse};
@ -182,7 +182,7 @@ fn test_connection_reuse() {
let mut srv = TestServer::new(move || {
let num2 = num2.clone();
fn_service(move |io| {
service_fn(move |io| {
num2.fetch_add(1, Ordering::Relaxed);
Ok(io)
})
@ -216,7 +216,7 @@ fn test_connection_reuse_h2() {
let mut srv = TestServer::new(move || {
let num2 = num2.clone();
fn_service(move |io| {
service_fn(move |io| {
num2.fetch_add(1, Ordering::Relaxed);
Ok(io)
})
@ -268,7 +268,7 @@ fn test_connection_force_close() {
let mut srv = TestServer::new(move || {
let num2 = num2.clone();
fn_service(move |io| {
service_fn(move |io| {
num2.fetch_add(1, Ordering::Relaxed);
Ok(io)
})
@ -300,7 +300,7 @@ fn test_connection_server_close() {
let mut srv = TestServer::new(move || {
let num2 = num2.clone();
fn_service(move |io| {
service_fn(move |io| {
num2.fetch_add(1, Ordering::Relaxed);
Ok(io)
})
@ -335,7 +335,7 @@ fn test_connection_wait_queue() {
let mut srv = TestServer::new(move || {
let num2 = num2.clone();
fn_service(move |io| {
service_fn(move |io| {
num2.fetch_add(1, Ordering::Relaxed);
Ok(io)
})
@ -380,7 +380,7 @@ fn test_connection_wait_queue_force_close() {
let mut srv = TestServer::new(move || {
let num2 = num2.clone();
fn_service(move |io| {
service_fn(move |io| {
num2.fetch_add(1, Ordering::Relaxed);
Ok(io)
})

View File

@ -1,17 +1,11 @@
use std::io;
use actix_codec::Framed;
use actix_http::{body::BodySize, h1, ws, Error, HttpService, Request, Response};
use actix_http_test::TestServer;
use actix_server::Io;
use actix_service::{fn_service, NewService};
use actix_utils::framed::IntoFramed;
use actix_utils::stream::TakeItem;
use bytes::{Bytes, BytesMut};
use futures::future::{ok, Either};
use futures::future::ok;
use futures::{Future, Sink, Stream};
use tokio_tcp::TcpStream;
use actix_http::{body::BodySize, h1, ws, Request, ResponseError, ServiceConfig};
fn ws_service(req: ws::Frame) -> impl Future<Item = ws::Message, Error = io::Error> {
match req {
@ -37,52 +31,20 @@ fn ws_service(req: ws::Frame) -> impl Future<Item = ws::Message, Error = io::Err
#[test]
fn test_simple() {
let mut srv = TestServer::new(|| {
fn_service(|io: Io<TcpStream>| Ok(io.into_parts().0))
.and_then(IntoFramed::new(|| h1::Codec::new(ServiceConfig::default())))
.and_then(TakeItem::new().map_err(|_| ()))
.and_then(
|(req, framed): (Option<h1::Message<Request>>, Framed<_, _>)| {
// validate request
if let Some(h1::Message::Item(req)) = req {
match ws::verify_handshake(req.head()) {
Err(e) => {
// validation failed
let res = e.error_response();
Either::A(
framed
.send(h1::Message::Item((
res.drop_body(),
BodySize::Empty,
)))
.map_err(|_| ())
.map(|_| ()),
)
}
Ok(_) => {
let res = ws::handshake_response(req.head()).finish();
Either::B(
// send handshake response
framed
.send(h1::Message::Item((
res.drop_body(),
BodySize::None,
)))
.map_err(|_| ())
.and_then(|framed| {
// start websocket service
let framed =
framed.into_framed(ws::Codec::new());
ws::Transport::with(framed, ws_service)
.map_err(|_| ())
}),
)
}
}
} else {
panic!()
}
},
)
HttpService::build()
.upgrade(|(req, framed): (Request, Framed<_, _>)| {
let res = ws::handshake_response(req.head()).finish();
// send handshake response
framed
.send(h1::Message::Item((res.drop_body(), BodySize::None)))
.map_err(|e: io::Error| e.into())
.and_then(|framed| {
// start websocket service
let framed = framed.into_framed(ws::Codec::new());
ws::Transport::with(framed, ws_service)
})
})
.finish(|_| ok::<_, Error>(Response::NotFound()))
});
// client service