mirror of https://github.com/fafhrd91/actix-web
actix-http: update ws example, tests for rustls 0.23
This commit is contained in:
parent
d7f5bcef95
commit
a16d713678
|
@ -1,7 +1,7 @@
|
||||||
//! Sets up a WebSocket server over TCP and TLS.
|
//! Sets up a WebSocket server over TCP and TLS.
|
||||||
//! Sends a heartbeat message every 4 seconds but does not respond to any incoming frames.
|
//! Sends a heartbeat message every 4 seconds but does not respond to any incoming frames.
|
||||||
|
|
||||||
extern crate tls_rustls_022 as rustls;
|
extern crate tls_rustls_023 as rustls;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
io,
|
io,
|
||||||
|
@ -30,7 +30,7 @@ async fn main() -> io::Result<()> {
|
||||||
.bind("tls", ("127.0.0.1", 8443), || {
|
.bind("tls", ("127.0.0.1", 8443), || {
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
.finish(handler)
|
.finish(handler)
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})?
|
})?
|
||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#![cfg(feature = "rustls-0_22")]
|
#![cfg(feature = "rustls-0_23")]
|
||||||
|
|
||||||
extern crate tls_rustls_022 as rustls;
|
extern crate tls_rustls_023 as rustls;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
convert::Infallible,
|
convert::Infallible,
|
||||||
|
@ -20,7 +20,7 @@ use actix_http::{
|
||||||
use actix_http_test::test_server;
|
use actix_http_test::test_server;
|
||||||
use actix_rt::pin;
|
use actix_rt::pin;
|
||||||
use actix_service::{fn_factory_with_config, fn_service};
|
use actix_service::{fn_factory_with_config, fn_service};
|
||||||
use actix_tls::connect::rustls_0_22::webpki_roots_cert_store;
|
use actix_tls::connect::rustls_0_23::webpki_roots_cert_store;
|
||||||
use actix_utils::future::{err, ok, poll_fn};
|
use actix_utils::future::{err, ok, poll_fn};
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use derive_more::{Display, Error};
|
use derive_more::{Display, Error};
|
||||||
|
@ -108,7 +108,7 @@ async fn h1() -> io::Result<()> {
|
||||||
let srv = test_server(move || {
|
let srv = test_server(move || {
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
.h1(|_| ok::<_, Error>(Response::ok()))
|
.h1(|_| ok::<_, Error>(Response::ok()))
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ async fn h2() -> io::Result<()> {
|
||||||
let srv = test_server(move || {
|
let srv = test_server(move || {
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
.h2(|_| ok::<_, Error>(Response::ok()))
|
.h2(|_| ok::<_, Error>(Response::ok()))
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ async fn h1_1() -> io::Result<()> {
|
||||||
assert_eq!(req.version(), Version::HTTP_11);
|
assert_eq!(req.version(), Version::HTTP_11);
|
||||||
ok::<_, Error>(Response::ok())
|
ok::<_, Error>(Response::ok())
|
||||||
})
|
})
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ async fn h2_1() -> io::Result<()> {
|
||||||
assert_eq!(req.version(), Version::HTTP_2);
|
assert_eq!(req.version(), Version::HTTP_2);
|
||||||
ok::<_, Error>(Response::ok())
|
ok::<_, Error>(Response::ok())
|
||||||
})
|
})
|
||||||
.rustls_0_22_with_config(
|
.rustls_0_23_with_config(
|
||||||
tls_config(),
|
tls_config(),
|
||||||
TlsAcceptorConfig::default().handshake_timeout(Duration::from_secs(5)),
|
TlsAcceptorConfig::default().handshake_timeout(Duration::from_secs(5)),
|
||||||
)
|
)
|
||||||
|
@ -179,7 +179,7 @@ async fn h2_body1() -> io::Result<()> {
|
||||||
let body = load_body(req.take_payload()).await?;
|
let body = load_body(req.take_payload()).await?;
|
||||||
Ok::<_, Error>(Response::ok().set_body(body))
|
Ok::<_, Error>(Response::ok().set_body(body))
|
||||||
})
|
})
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ async fn h2_content_length() {
|
||||||
];
|
];
|
||||||
ok::<_, Infallible>(Response::new(statuses[indx]))
|
ok::<_, Infallible>(Response::new(statuses[indx]))
|
||||||
})
|
})
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ async fn h2_headers() {
|
||||||
}
|
}
|
||||||
ok::<_, Infallible>(config.body(data.clone()))
|
ok::<_, Infallible>(config.body(data.clone()))
|
||||||
})
|
})
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ async fn h2_body2() {
|
||||||
let mut srv = test_server(move || {
|
let mut srv = test_server(move || {
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
|
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -333,7 +333,7 @@ async fn h2_head_empty() {
|
||||||
let mut srv = test_server(move || {
|
let mut srv = test_server(move || {
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
.finish(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
|
.finish(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -359,7 +359,7 @@ async fn h2_head_binary() {
|
||||||
let mut srv = test_server(move || {
|
let mut srv = test_server(move || {
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
|
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -384,7 +384,7 @@ async fn h2_head_binary2() {
|
||||||
let srv = test_server(move || {
|
let srv = test_server(move || {
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
|
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -410,7 +410,7 @@ async fn h2_body_length() {
|
||||||
Response::ok().set_body(SizedStream::new(STR.len() as u64, body)),
|
Response::ok().set_body(SizedStream::new(STR.len() as u64, body)),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -434,7 +434,7 @@ async fn h2_body_chunked_explicit() {
|
||||||
.body(BodyStream::new(body)),
|
.body(BodyStream::new(body)),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -463,7 +463,7 @@ async fn h2_response_http_error_handling() {
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
}))
|
}))
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -493,7 +493,7 @@ async fn h2_service_error() {
|
||||||
let mut srv = test_server(move || {
|
let mut srv = test_server(move || {
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
.h2(|_| err::<Response<BoxBody>, _>(BadRequest))
|
.h2(|_| err::<Response<BoxBody>, _>(BadRequest))
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -510,7 +510,7 @@ async fn h1_service_error() {
|
||||||
let mut srv = test_server(move || {
|
let mut srv = test_server(move || {
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
.h1(|_| err::<Response<BoxBody>, _>(BadRequest))
|
.h1(|_| err::<Response<BoxBody>, _>(BadRequest))
|
||||||
.rustls_0_22(tls_config())
|
.rustls_0_23(tls_config())
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -533,7 +533,7 @@ async fn alpn_h1() -> io::Result<()> {
|
||||||
config.alpn_protocols.push(CUSTOM_ALPN_PROTOCOL.to_vec());
|
config.alpn_protocols.push(CUSTOM_ALPN_PROTOCOL.to_vec());
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
.h1(|_| ok::<_, Error>(Response::ok()))
|
.h1(|_| ok::<_, Error>(Response::ok()))
|
||||||
.rustls_0_22(config)
|
.rustls_0_23(config)
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -555,7 +555,7 @@ async fn alpn_h2() -> io::Result<()> {
|
||||||
config.alpn_protocols.push(CUSTOM_ALPN_PROTOCOL.to_vec());
|
config.alpn_protocols.push(CUSTOM_ALPN_PROTOCOL.to_vec());
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
.h2(|_| ok::<_, Error>(Response::ok()))
|
.h2(|_| ok::<_, Error>(Response::ok()))
|
||||||
.rustls_0_22(config)
|
.rustls_0_23(config)
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -581,7 +581,7 @@ async fn alpn_h2_1() -> io::Result<()> {
|
||||||
config.alpn_protocols.push(CUSTOM_ALPN_PROTOCOL.to_vec());
|
config.alpn_protocols.push(CUSTOM_ALPN_PROTOCOL.to_vec());
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
.finish(|_| ok::<_, Error>(Response::ok()))
|
.finish(|_| ok::<_, Error>(Response::ok()))
|
||||||
.rustls_0_22(config)
|
.rustls_0_23(config)
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue