mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-05 13:57:39 +03:00
parent
f47e830cfb
commit
15019a2a43
32 changed files with 196 additions and 118 deletions
|
@ -975,6 +975,7 @@ mod tests {
|
||||||
use crate::{BytesMut, BytesVec};
|
use crate::{BytesMut, BytesVec};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::needless_borrow)]
|
||||||
fn buf_mut_tests() {
|
fn buf_mut_tests() {
|
||||||
let mut buf = vec![];
|
let mut buf = vec![];
|
||||||
buf.put_u8(0x01);
|
buf.put_u8(0x01);
|
||||||
|
|
|
@ -4071,6 +4071,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::len_zero)]
|
||||||
fn bytes() {
|
fn bytes() {
|
||||||
let mut b = Bytes::from(LONG.to_vec());
|
let mut b = Bytes::from(LONG.to_vec());
|
||||||
b.clear();
|
b.clear();
|
||||||
|
@ -4113,12 +4114,12 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bytes_vec() {
|
fn bytes_vec() {
|
||||||
let bv = BytesVec::copy_from_slice(&LONG[..]);
|
let bv = BytesVec::copy_from_slice(LONG);
|
||||||
// SharedVec size is 32
|
// SharedVec size is 32
|
||||||
assert_eq!(bv.capacity(), mem::size_of::<SharedVec>() * 9);
|
assert_eq!(bv.capacity(), mem::size_of::<SharedVec>() * 9);
|
||||||
assert_eq!(bv.len(), 263);
|
assert_eq!(bv.len(), 263);
|
||||||
assert_eq!(bv.as_ref().len(), 263);
|
assert_eq!(bv.as_ref().len(), 263);
|
||||||
assert_eq!(bv.as_ref(), &LONG[..]);
|
assert_eq!(bv.as_ref(), LONG);
|
||||||
|
|
||||||
let mut bv = BytesVec::copy_from_slice(&b"hello"[..]);
|
let mut bv = BytesVec::copy_from_slice(&b"hello"[..]);
|
||||||
assert_eq!(bv.capacity(), mem::size_of::<SharedVec>());
|
assert_eq!(bv.capacity(), mem::size_of::<SharedVec>());
|
||||||
|
|
|
@ -177,7 +177,7 @@ fn inline() {
|
||||||
a.truncate(8);
|
a.truncate(8);
|
||||||
assert!(a.is_inline());
|
assert!(a.is_inline());
|
||||||
|
|
||||||
let mut a = BytesVec::copy_from_slice(&vec![b'*'; 35]).freeze();
|
let mut a = BytesVec::copy_from_slice(vec![b'*'; 35]).freeze();
|
||||||
let b = a.split_to(8);
|
let b = a.split_to(8);
|
||||||
assert!(b.is_inline());
|
assert!(b.is_inline());
|
||||||
}
|
}
|
||||||
|
@ -444,6 +444,12 @@ fn split_off_to_at_gt_len() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(
|
||||||
|
clippy::cmp_owned,
|
||||||
|
clippy::redundant_slicing,
|
||||||
|
clippy::iter_cloned_collect,
|
||||||
|
clippy::needless_borrow
|
||||||
|
)]
|
||||||
fn fns_defined_for_bytes() {
|
fn fns_defined_for_bytes() {
|
||||||
let mut bytes = Bytes::from(&b"hello world"[..]);
|
let mut bytes = Bytes::from(&b"hello world"[..]);
|
||||||
let _ = bytes.as_ptr();
|
let _ = bytes.as_ptr();
|
||||||
|
@ -452,7 +458,7 @@ fn fns_defined_for_bytes() {
|
||||||
assert!(bytes > "g");
|
assert!(bytes > "g");
|
||||||
assert!(bytes > "g".to_string());
|
assert!(bytes > "g".to_string());
|
||||||
assert!(bytes > "g".as_bytes().to_vec());
|
assert!(bytes > "g".as_bytes().to_vec());
|
||||||
assert!(bytes > Bytes::from(&"g"[..]));
|
assert!(bytes > Bytes::from("g"));
|
||||||
assert!("g" > bytes);
|
assert!("g" > bytes);
|
||||||
assert!("g".to_string() > bytes);
|
assert!("g".to_string() > bytes);
|
||||||
assert!("g".as_bytes().to_vec() > bytes);
|
assert!("g".as_bytes().to_vec() > bytes);
|
||||||
|
@ -494,6 +500,11 @@ fn fns_defined_for_bytes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(
|
||||||
|
clippy::iter_cloned_collect,
|
||||||
|
clippy::redundant_slicing,
|
||||||
|
clippy::needless_borrow
|
||||||
|
)]
|
||||||
fn fns_defined_for_bytes_mut() {
|
fn fns_defined_for_bytes_mut() {
|
||||||
let mut bytes = BytesMut::from(&b"hello world"[..]);
|
let mut bytes = BytesMut::from(&b"hello world"[..]);
|
||||||
let _ = bytes.as_ptr();
|
let _ = bytes.as_ptr();
|
||||||
|
@ -555,6 +566,7 @@ fn fns_defined_for_bytes_mut() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::redundant_slicing)]
|
||||||
fn fns_defined_for_bytes_vec() {
|
fn fns_defined_for_bytes_vec() {
|
||||||
// BytesVec
|
// BytesVec
|
||||||
let mut bytes = BytesVec::copy_from_slice(&b"hello world"[..]);
|
let mut bytes = BytesVec::copy_from_slice(&b"hello world"[..]);
|
||||||
|
@ -572,13 +584,13 @@ fn fns_defined_for_bytes_vec() {
|
||||||
assert_eq!("hello world", bytes);
|
assert_eq!("hello world", bytes);
|
||||||
assert_eq!("hello world".as_bytes().to_vec(), bytes);
|
assert_eq!("hello world".as_bytes().to_vec(), bytes);
|
||||||
assert_eq!("hello world".to_string(), bytes);
|
assert_eq!("hello world".to_string(), bytes);
|
||||||
assert_eq!(&"hello world"[..], bytes);
|
assert_eq!("hello world", bytes);
|
||||||
|
|
||||||
// Iterator
|
// Iterator
|
||||||
let v: Vec<u8> = (&bytes).iter().cloned().collect();
|
let v: Vec<u8> = bytes.iter().cloned().collect();
|
||||||
assert_eq!(&v[..], bytes);
|
assert_eq!(&v[..], bytes);
|
||||||
|
|
||||||
let v: Vec<u8> = bytes.as_ref().iter().cloned().collect();
|
let v: Vec<u8> = bytes.as_ref().to_vec();
|
||||||
assert_eq!(&v[..], bytes);
|
assert_eq!(&v[..], bytes);
|
||||||
|
|
||||||
let v: Vec<u8> = bytes.iter().cloned().collect();
|
let v: Vec<u8> = bytes.iter().cloned().collect();
|
||||||
|
@ -978,7 +990,7 @@ fn bytes_vec() {
|
||||||
bytes.with_bytes_mut(|buf| {
|
bytes.with_bytes_mut(|buf| {
|
||||||
*buf = BytesMut::from(b"12345".to_vec());
|
*buf = BytesMut::from(b"12345".to_vec());
|
||||||
});
|
});
|
||||||
assert_eq!(bytes, &"12345"[..]);
|
assert_eq!(bytes, "12345");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -44,6 +44,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::redundant_clone)]
|
||||||
fn connect_error_clone() {
|
fn connect_error_clone() {
|
||||||
let _ =
|
let _ =
|
||||||
ConnectError::Resolver(io::Error::new(io::ErrorKind::Other, "test")).clone();
|
ConnectError::Resolver(io::Error::new(io::ErrorKind::Other, "test")).clone();
|
||||||
|
|
|
@ -271,9 +271,7 @@ mod tests {
|
||||||
assert_eq!(*connect.get_ref(), "www.rust-lang.org");
|
assert_eq!(*connect.get_ref(), "www.rust-lang.org");
|
||||||
connect = connect.set_port(80);
|
connect = connect.set_port(80);
|
||||||
assert_eq!(connect.port(), 80);
|
assert_eq!(connect.port(), 80);
|
||||||
|
assert!(connect.addrs().next().is_none());
|
||||||
let addrs: Vec<_> = connect.addrs().collect();
|
|
||||||
assert!(addrs.is_empty());
|
|
||||||
|
|
||||||
let addr: SocketAddr = "127.0.0.1:8080".parse().unwrap();
|
let addr: SocketAddr = "127.0.0.1:8080".parse().unwrap();
|
||||||
connect = connect.set_addrs(vec![addr]);
|
connect = connect.set_addrs(vec![addr]);
|
||||||
|
@ -292,9 +290,7 @@ mod tests {
|
||||||
assert_eq!(addrs.len(), 2);
|
assert_eq!(addrs.len(), 2);
|
||||||
assert!(addrs.contains(&addr));
|
assert!(addrs.contains(&addr));
|
||||||
assert!(addrs.contains(&addr2));
|
assert!(addrs.contains(&addr2));
|
||||||
|
assert!(connect.addrs().next().is_none());
|
||||||
let addrs: Vec<_> = connect.addrs().collect();
|
|
||||||
assert!(addrs.is_empty());
|
|
||||||
|
|
||||||
connect = connect.set_addrs(vec![addr]);
|
connect = connect.set_addrs(vec![addr]);
|
||||||
assert_eq!(format!("{}", connect), "www.rust-lang.org:80");
|
assert_eq!(format!("{}", connect), "www.rust-lang.org:80");
|
||||||
|
|
|
@ -576,6 +576,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::needless_borrow)]
|
||||||
fn test_basics() {
|
fn test_basics() {
|
||||||
let m = HeaderMap::default();
|
let m = HeaderMap::default();
|
||||||
assert!(m.is_empty());
|
assert!(m.is_empty());
|
||||||
|
@ -599,8 +600,7 @@ mod tests {
|
||||||
HeaderValue::from_static("text")
|
HeaderValue::from_static("text")
|
||||||
);
|
);
|
||||||
|
|
||||||
let keys: Vec<_> = m.keys().collect();
|
assert!(m.keys().any(|x| x == CONTENT_TYPE));
|
||||||
assert!(keys.contains(&&CONTENT_TYPE));
|
|
||||||
m.remove("content-type");
|
m.remove("content-type");
|
||||||
assert!(m.is_empty());
|
assert!(m.is_empty());
|
||||||
}
|
}
|
||||||
|
|
|
@ -751,6 +751,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::op_ref, clippy::cmp_owned, deprecated)]
|
||||||
fn test_basics() {
|
fn test_basics() {
|
||||||
assert!(HeaderValue::from_str("").unwrap().is_empty());
|
assert!(HeaderValue::from_str("").unwrap().is_empty());
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ntex-codec = "0.6.2"
|
ntex-codec = "0.6.2"
|
||||||
ntex-bytes = "0.1.14"
|
ntex-bytes = "0.1.18"
|
||||||
ntex-util = "0.2.0"
|
ntex-util = "0.2.0"
|
||||||
ntex-service = "1.0.0"
|
ntex-service = "1.0.0"
|
||||||
|
|
||||||
|
|
|
@ -541,7 +541,7 @@ mod tests {
|
||||||
|
|
||||||
assert!(st
|
assert!(st
|
||||||
.io()
|
.io()
|
||||||
.encode(Bytes::from_static(b"test"), &mut BytesCodec)
|
.encode(Bytes::from_static(b"test"), &BytesCodec)
|
||||||
.is_ok());
|
.is_ok());
|
||||||
let buf = client.read().await.unwrap();
|
let buf = client.read().await.unwrap();
|
||||||
assert_eq!(buf, Bytes::from_static(b"test"));
|
assert_eq!(buf, Bytes::from_static(b"test"));
|
||||||
|
@ -567,10 +567,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
state
|
state
|
||||||
.io()
|
.io()
|
||||||
.encode(
|
.encode(Bytes::from_static(b"GET /test HTTP/1\r\n\r\n"), &BytesCodec)
|
||||||
Bytes::from_static(b"GET /test HTTP/1\r\n\r\n"),
|
|
||||||
&mut BytesCodec,
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
let _ = disp.await;
|
let _ = disp.await;
|
||||||
|
@ -619,10 +616,7 @@ mod tests {
|
||||||
let (disp, state) = Dispatcher::debug(server, BytesCodec, Srv(counter.clone()));
|
let (disp, state) = Dispatcher::debug(server, BytesCodec, Srv(counter.clone()));
|
||||||
state
|
state
|
||||||
.io()
|
.io()
|
||||||
.encode(
|
.encode(Bytes::from_static(b"GET /test HTTP/1\r\n\r\n"), &BytesCodec)
|
||||||
Bytes::from_static(b"GET /test HTTP/1\r\n\r\n"),
|
|
||||||
&mut BytesCodec,
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
let _ = disp.await;
|
let _ = disp.await;
|
||||||
|
@ -764,7 +758,6 @@ mod tests {
|
||||||
assert_eq!(&data.lock().unwrap().borrow()[..], &[0, 1]);
|
assert_eq!(&data.lock().unwrap().borrow()[..], &[0, 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
#[ntex::test]
|
#[ntex::test]
|
||||||
async fn test_unhandled_data() {
|
async fn test_unhandled_data() {
|
||||||
let handled = Arc::new(AtomicBool::new(false));
|
let handled = Arc::new(AtomicBool::new(false));
|
||||||
|
|
|
@ -2,8 +2,7 @@ use std::{any, io, task::Context, task::Poll};
|
||||||
|
|
||||||
use ntex_bytes::BytesVec;
|
use ntex_bytes::BytesVec;
|
||||||
|
|
||||||
use super::io::Flags;
|
use super::{io::Flags, Filter, IoRef, ReadStatus, WriteStatus};
|
||||||
use super::{Filter, IoRef, ReadStatus, WriteStatus};
|
|
||||||
|
|
||||||
/// Default `Io` filter
|
/// Default `Io` filter
|
||||||
pub struct Base(IoRef);
|
pub struct Base(IoRef);
|
||||||
|
@ -117,36 +116,45 @@ impl NullFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Filter for NullFilter {
|
impl Filter for NullFilter {
|
||||||
|
#[inline]
|
||||||
fn query(&self, _: any::TypeId) -> Option<Box<dyn any::Any>> {
|
fn query(&self, _: any::TypeId) -> Option<Box<dyn any::Any>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn poll_shutdown(&self) -> Poll<io::Result<()>> {
|
fn poll_shutdown(&self) -> Poll<io::Result<()>> {
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn poll_read_ready(&self, _: &mut Context<'_>) -> Poll<ReadStatus> {
|
fn poll_read_ready(&self, _: &mut Context<'_>) -> Poll<ReadStatus> {
|
||||||
Poll::Ready(ReadStatus::Terminate)
|
Poll::Ready(ReadStatus::Terminate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn poll_write_ready(&self, _: &mut Context<'_>) -> Poll<WriteStatus> {
|
fn poll_write_ready(&self, _: &mut Context<'_>) -> Poll<WriteStatus> {
|
||||||
Poll::Ready(WriteStatus::Terminate)
|
Poll::Ready(WriteStatus::Terminate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn get_read_buf(&self) -> Option<BytesVec> {
|
fn get_read_buf(&self) -> Option<BytesVec> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn get_write_buf(&self) -> Option<BytesVec> {
|
fn get_write_buf(&self) -> Option<BytesVec> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn release_read_buf(&self, _: BytesVec) {}
|
fn release_read_buf(&self, _: BytesVec) {}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn process_read_buf(&self, _: &IoRef, _: usize) -> io::Result<(usize, usize)> {
|
fn process_read_buf(&self, _: &IoRef, _: usize) -> io::Result<(usize, usize)> {
|
||||||
Ok((0, 0))
|
Ok((0, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn release_write_buf(&self, _: BytesVec) -> Result<(), io::Error> {
|
fn release_write_buf(&self, _: BytesVec) -> Result<(), io::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -335,6 +335,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[ntex::test]
|
#[ntex::test]
|
||||||
|
#[allow(clippy::unit_cmp)]
|
||||||
async fn on_disconnect() {
|
async fn on_disconnect() {
|
||||||
let (client, server) = IoTest::create();
|
let (client, server) = IoTest::create();
|
||||||
let state = Io::new(server);
|
let state = Io::new(server);
|
||||||
|
|
|
@ -82,3 +82,91 @@ where
|
||||||
req.add_filter(self.filter.clone())
|
req.add_filter(self.filter.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use ntex_bytes::{Bytes, BytesVec};
|
||||||
|
use ntex_codec::BytesCodec;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use crate::{filter::NullFilter, testing::IoTest};
|
||||||
|
|
||||||
|
#[ntex::test]
|
||||||
|
async fn test_utils() {
|
||||||
|
let (client, server) = IoTest::create();
|
||||||
|
client.remote_buffer_cap(1024);
|
||||||
|
client.write("REQ");
|
||||||
|
|
||||||
|
let svc = seal(fn_service(|io: IoBoxed| async move {
|
||||||
|
let t = io.recv(&BytesCodec).await.unwrap().unwrap();
|
||||||
|
assert_eq!(t, b"REQ".as_ref());
|
||||||
|
io.send(Bytes::from_static(b"RES"), &BytesCodec)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
Ok::<_, ()>(())
|
||||||
|
}))
|
||||||
|
.create(())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let _ = svc.call(Io::new(server)).await;
|
||||||
|
|
||||||
|
let buf = client.read().await.unwrap();
|
||||||
|
assert_eq!(buf, b"RES".as_ref());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
struct NullFilterFactory;
|
||||||
|
|
||||||
|
impl<F: Filter> FilterFactory<F> for NullFilterFactory {
|
||||||
|
type Filter = crate::filter::NullFilter;
|
||||||
|
type Error = std::convert::Infallible;
|
||||||
|
type Future = Ready<Io<Self::Filter>, Self::Error>;
|
||||||
|
|
||||||
|
fn create(self, st: Io<F>) -> Self::Future {
|
||||||
|
st.map_filter(|_| Ok(NullFilter)).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[ntex::test]
|
||||||
|
async fn test_utils_filter() {
|
||||||
|
let (_, server) = IoTest::create();
|
||||||
|
let svc = pipeline_factory(
|
||||||
|
filter::<_, crate::filter::Base>(NullFilterFactory)
|
||||||
|
.map_err(|_| ())
|
||||||
|
.map_init_err(|_| ()),
|
||||||
|
)
|
||||||
|
.and_then(seal(fn_service(|io: IoBoxed| async move {
|
||||||
|
let _ = io.recv(&BytesCodec).await;
|
||||||
|
Ok::<_, ()>(())
|
||||||
|
})))
|
||||||
|
.create(())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let _ = svc.call(Io::new(server)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[ntex::test]
|
||||||
|
async fn test_null_filter() {
|
||||||
|
assert!(NullFilter.query(std::any::TypeId::of::<()>()).is_none());
|
||||||
|
assert!(NullFilter.poll_shutdown().is_ready());
|
||||||
|
assert_eq!(
|
||||||
|
ntex_util::future::poll_fn(|cx| NullFilter.poll_read_ready(cx)).await,
|
||||||
|
crate::ReadStatus::Terminate
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
ntex_util::future::poll_fn(|cx| NullFilter.poll_write_ready(cx)).await,
|
||||||
|
crate::WriteStatus::Terminate
|
||||||
|
);
|
||||||
|
assert_eq!(NullFilter.get_read_buf(), None);
|
||||||
|
assert_eq!(NullFilter.get_write_buf(), None);
|
||||||
|
assert!(NullFilter.release_write_buf(BytesVec::new()).is_ok());
|
||||||
|
NullFilter.release_read_buf(BytesVec::new());
|
||||||
|
|
||||||
|
let (_, server) = IoTest::create();
|
||||||
|
let io = Io::new(server);
|
||||||
|
assert_eq!(
|
||||||
|
NullFilter.process_read_buf(&io.get_ref(), 10).unwrap(),
|
||||||
|
(0, 0)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -771,6 +771,7 @@ mod tests {
|
||||||
assert_eq!(tree.find(&mut Path::new("/2345/sdg")), Some(1));
|
assert_eq!(tree.find(&mut Path::new("/2345/sdg")), Some(1));
|
||||||
assert_eq!(tree.find(&mut Path::new("/user/2345/sdg")), Some(1));
|
assert_eq!(tree.find(&mut Path::new("/user/2345/sdg")), Some(1));
|
||||||
|
|
||||||
|
#[allow(clippy::needless_borrow)]
|
||||||
let re = ResourceDef::new(&("/user*".to_string()));
|
let re = ResourceDef::new(&("/user*".to_string()));
|
||||||
let tree = Tree::new(&re, 1);
|
let tree = Tree::new(&re, 1);
|
||||||
assert_eq!(tree.find(&mut Path::new("/user/profile")), Some(1));
|
assert_eq!(tree.find(&mut Path::new("/user/profile")), Some(1));
|
||||||
|
@ -956,31 +957,31 @@ mod tests {
|
||||||
fn test_resource_path() {
|
fn test_resource_path() {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let resource = ResourceDef::new("/user/{item1}/test");
|
let resource = ResourceDef::new("/user/{item1}/test");
|
||||||
assert!(resource.resource_path(&mut s, &mut (&["user1"]).iter()));
|
assert!(resource.resource_path(&mut s, &mut ["user1"].iter()));
|
||||||
assert_eq!(s, "/user/user1/test");
|
assert_eq!(s, "/user/user1/test");
|
||||||
|
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let resource = ResourceDef::new("/user/{item1}/{item2}/test");
|
let resource = ResourceDef::new("/user/{item1}/{item2}/test");
|
||||||
assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).iter()));
|
assert!(resource.resource_path(&mut s, &mut ["item", "item2"].iter()));
|
||||||
assert_eq!(s, "/user/item/item2/test");
|
assert_eq!(s, "/user/item/item2/test");
|
||||||
|
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let resource = ResourceDef::new("/user/{item1}/{item2}");
|
let resource = ResourceDef::new("/user/{item1}/{item2}");
|
||||||
assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).iter()));
|
assert!(resource.resource_path(&mut s, &mut ["item", "item2"].iter()));
|
||||||
assert_eq!(s, "/user/item/item2");
|
assert_eq!(s, "/user/item/item2");
|
||||||
|
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let resource = ResourceDef::new("/user/{item1}/{item2}/");
|
let resource = ResourceDef::new("/user/{item1}/{item2}/");
|
||||||
assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).iter()));
|
assert!(resource.resource_path(&mut s, &mut ["item", "item2"].iter()));
|
||||||
assert_eq!(s, "/user/item/item2/");
|
assert_eq!(s, "/user/item/item2/");
|
||||||
|
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
assert!(!resource.resource_path(&mut s, &mut (&["item"]).iter()));
|
assert!(!resource.resource_path(&mut s, &mut ["item"].iter()));
|
||||||
|
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
assert!(resource.resource_path(&mut s, &mut (&["item", "item2"]).iter()));
|
assert!(resource.resource_path(&mut s, &mut ["item", "item2"].iter()));
|
||||||
assert_eq!(s, "/user/item/item2/");
|
assert_eq!(s, "/user/item/item2/");
|
||||||
assert!(!resource.resource_path(&mut s, &mut (&["item"]).iter()));
|
assert!(!resource.resource_path(&mut s, &mut ["item"].iter()));
|
||||||
|
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
assert!(resource.resource_path(&mut s, &mut vec!["item", "item2"].into_iter()));
|
assert!(resource.resource_path(&mut s, &mut vec!["item", "item2"].into_iter()));
|
||||||
|
|
|
@ -69,15 +69,15 @@ mod glommio {
|
||||||
F: Future + 'static,
|
F: Future + 'static,
|
||||||
F::Output: 'static,
|
F::Output: 'static,
|
||||||
{
|
{
|
||||||
let ptr = crate::CB.with(|cb| (&cb.borrow().0)());
|
let ptr = crate::CB.with(|cb| (cb.borrow().0)());
|
||||||
JoinHandle {
|
JoinHandle {
|
||||||
fut: Either::Left(
|
fut: Either::Left(
|
||||||
glomm_io::spawn_local(async move {
|
glomm_io::spawn_local(async move {
|
||||||
if let Some(ptr) = ptr {
|
if let Some(ptr) = ptr {
|
||||||
let new_ptr = crate::CB.with(|cb| (&cb.borrow().1)(ptr));
|
let new_ptr = crate::CB.with(|cb| (cb.borrow().1)(ptr));
|
||||||
glomm_io::executor().yield_now().await;
|
glomm_io::executor().yield_now().await;
|
||||||
let res = f.await;
|
let res = f.await;
|
||||||
crate::CB.with(|cb| (&cb.borrow().2)(new_ptr));
|
crate::CB.with(|cb| (cb.borrow().2)(new_ptr));
|
||||||
res
|
res
|
||||||
} else {
|
} else {
|
||||||
glomm_io::executor().yield_now().await;
|
glomm_io::executor().yield_now().await;
|
||||||
|
@ -170,12 +170,12 @@ mod tokio {
|
||||||
where
|
where
|
||||||
F: Future + 'static,
|
F: Future + 'static,
|
||||||
{
|
{
|
||||||
let ptr = crate::CB.with(|cb| (&cb.borrow().0)());
|
let ptr = crate::CB.with(|cb| (cb.borrow().0)());
|
||||||
tok_io::task::spawn_local(async move {
|
tok_io::task::spawn_local(async move {
|
||||||
if let Some(ptr) = ptr {
|
if let Some(ptr) = ptr {
|
||||||
let new_ptr = crate::CB.with(|cb| (&cb.borrow().1)(ptr));
|
let new_ptr = crate::CB.with(|cb| (cb.borrow().1)(ptr));
|
||||||
let res = f.await;
|
let res = f.await;
|
||||||
crate::CB.with(|cb| (&cb.borrow().2)(new_ptr));
|
crate::CB.with(|cb| (cb.borrow().2)(new_ptr));
|
||||||
res
|
res
|
||||||
} else {
|
} else {
|
||||||
f.await
|
f.await
|
||||||
|
@ -224,13 +224,13 @@ mod asyncstd {
|
||||||
where
|
where
|
||||||
F: Future + 'static,
|
F: Future + 'static,
|
||||||
{
|
{
|
||||||
let ptr = crate::CB.with(|cb| (&cb.borrow().0)());
|
let ptr = crate::CB.with(|cb| (cb.borrow().0)());
|
||||||
JoinHandle {
|
JoinHandle {
|
||||||
fut: async_std::task::spawn_local(async move {
|
fut: async_std::task::spawn_local(async move {
|
||||||
if let Some(ptr) = ptr {
|
if let Some(ptr) = ptr {
|
||||||
let new_ptr = crate::CB.with(|cb| (&cb.borrow().1)(ptr));
|
let new_ptr = crate::CB.with(|cb| (cb.borrow().1)(ptr));
|
||||||
let res = f.await;
|
let res = f.await;
|
||||||
crate::CB.with(|cb| (&cb.borrow().2)(new_ptr));
|
crate::CB.with(|cb| (cb.borrow().2)(new_ptr));
|
||||||
res
|
res
|
||||||
} else {
|
} else {
|
||||||
f.await
|
f.await
|
||||||
|
|
|
@ -125,18 +125,19 @@ mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::unit_cmp)]
|
||||||
fn either() {
|
fn either() {
|
||||||
let mut e = Either::<(), ()>::Left(());
|
let mut e = Either::<(), ()>::Left(());
|
||||||
assert_eq!(e.is_left(), true);
|
assert!(e.is_left());
|
||||||
assert_eq!(e.is_right(), false);
|
assert!(!e.is_right());
|
||||||
assert!(e.left().is_some());
|
assert!(e.left().is_some());
|
||||||
assert!(e.right().is_none());
|
assert!(e.right().is_none());
|
||||||
e.as_ref();
|
e.as_ref();
|
||||||
e.as_mut();
|
e.as_mut();
|
||||||
|
|
||||||
let e = Either::<(), ()>::Right(());
|
let e = Either::<(), ()>::Right(());
|
||||||
assert_eq!(e.is_left(), false);
|
assert!(!e.is_left());
|
||||||
assert_eq!(e.is_right(), true);
|
assert!(e.is_right());
|
||||||
assert!(e.left().is_none());
|
assert!(e.left().is_none());
|
||||||
assert!(e.right().is_some());
|
assert!(e.right().is_some());
|
||||||
|
|
||||||
|
|
|
@ -302,6 +302,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[ntex_macros::rt_test2]
|
#[ntex_macros::rt_test2]
|
||||||
|
#[allow(clippy::redundant_clone)]
|
||||||
async fn test_newtransform() {
|
async fn test_newtransform() {
|
||||||
let inner = Rc::new(Inner {
|
let inner = Rc::new(Inner {
|
||||||
ready: Cell::new(false),
|
ready: Cell::new(false),
|
||||||
|
|
|
@ -124,7 +124,7 @@ mod tests {
|
||||||
fn call(&self, _: ()) -> Self::Future<'_> {
|
fn call(&self, _: ()) -> Self::Future<'_> {
|
||||||
let fut = crate::time::sleep(self.0);
|
let fut = crate::time::sleep(self.0);
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let _ = fut.await;
|
fut.await;
|
||||||
Ok::<_, ()>(())
|
Ok::<_, ()>(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,7 +241,7 @@ mod tests {
|
||||||
fn call(&self, _: ()) -> Self::Future<'_> {
|
fn call(&self, _: ()) -> Self::Future<'_> {
|
||||||
let fut = crate::time::sleep(self.0);
|
let fut = crate::time::sleep(self.0);
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let _ = fut.await;
|
fut.await;
|
||||||
Ok::<_, SrvError>(())
|
Ok::<_, SrvError>(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -352,7 +352,7 @@ mod tests {
|
||||||
.clone()
|
.clone()
|
||||||
.v3(fn_factory(|| async { Ok::<_, ()>(Srv2) }))
|
.v3(fn_factory(|| async { Ok::<_, ()>(Srv2) }))
|
||||||
.clone();
|
.clone();
|
||||||
let service = factory.create(&()).await.unwrap();
|
let service = factory.create(&()).await.unwrap().clone();
|
||||||
|
|
||||||
assert!(lazy(|cx| service.poll_ready(cx)).await.is_ready());
|
assert!(lazy(|cx| service.poll_ready(cx)).await.is_ready());
|
||||||
assert!(lazy(|cx| service.poll_shutdown(cx)).await.is_ready());
|
assert!(lazy(|cx| service.poll_shutdown(cx)).await.is_ready());
|
||||||
|
|
|
@ -426,14 +426,10 @@ mod tests {
|
||||||
|
|
||||||
fn json_eq(err: JsonPayloadError, other: JsonPayloadError) -> bool {
|
fn json_eq(err: JsonPayloadError, other: JsonPayloadError) -> bool {
|
||||||
match err {
|
match err {
|
||||||
JsonPayloadError::Payload(PayloadError::Overflow) => match other {
|
JsonPayloadError::Payload(PayloadError::Overflow) => {
|
||||||
JsonPayloadError::Payload(PayloadError::Overflow) => true,
|
matches!(other, JsonPayloadError::Payload(PayloadError::Overflow))
|
||||||
_ => false,
|
}
|
||||||
},
|
JsonPayloadError::ContentType => matches!(other, JsonPayloadError::ContentType),
|
||||||
JsonPayloadError::ContentType => match other {
|
|
||||||
JsonPayloadError::ContentType => true,
|
|
||||||
_ => false,
|
|
||||||
},
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -752,10 +752,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_unhandled(&self) -> bool {
|
fn is_unhandled(&self) -> bool {
|
||||||
match self {
|
matches!(self, PayloadType::Stream(_))
|
||||||
PayloadType::Stream(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -767,10 +764,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn eof(&self) -> bool {
|
fn eof(&self) -> bool {
|
||||||
match *self {
|
matches!(*self, PayloadItem::Eof)
|
||||||
PayloadItem::Eof => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -953,7 +953,7 @@ mod tests {
|
||||||
|
|
||||||
spawn_h1(server, |mut req: Request| async move {
|
spawn_h1(server, |mut req: Request| async move {
|
||||||
let mut p = req.take_payload();
|
let mut p = req.take_payload();
|
||||||
while let Some(_) = stream_recv(&mut p).await {}
|
while (stream_recv(&mut p).await).is_some() {}
|
||||||
Ok::<_, io::Error>(Response::Ok().finish())
|
Ok::<_, io::Error>(Response::Ok().finish())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -775,10 +775,8 @@ mod tests {
|
||||||
.route(
|
.route(
|
||||||
"/test",
|
"/test",
|
||||||
web::get().to(|req: HttpRequest| async move {
|
web::get().to(|req: HttpRequest| async move {
|
||||||
HttpResponse::Ok().body(format!(
|
HttpResponse::Ok()
|
||||||
"{}",
|
.body(format!("{}", req.url_for("youtube", ["12345"]).unwrap()))
|
||||||
req.url_for("youtube", &["12345"]).unwrap()
|
|
||||||
))
|
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -164,10 +164,8 @@ mod tests {
|
||||||
.route(
|
.route(
|
||||||
"/test",
|
"/test",
|
||||||
web::get().to(|req: HttpRequest| async move {
|
web::get().to(|req: HttpRequest| async move {
|
||||||
HttpResponse::Ok().body(format!(
|
HttpResponse::Ok()
|
||||||
"{}",
|
.body(format!("{}", req.url_for("youtube", ["12345"]).unwrap()))
|
||||||
req.url_for("youtube", &["12345"]).unwrap()
|
|
||||||
))
|
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -408,14 +408,14 @@ mod tests {
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
req.url_for("unknown", &["test"]),
|
req.url_for("unknown", ["test"]),
|
||||||
Err(crate::web::error::UrlGenerationError::ResourceNotFound)
|
Err(crate::web::error::UrlGenerationError::ResourceNotFound)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
req.url_for("index", &["test"]),
|
req.url_for("index", ["test"]),
|
||||||
Err(crate::web::error::UrlGenerationError::NotEnoughElements)
|
Err(crate::web::error::UrlGenerationError::NotEnoughElements)
|
||||||
);
|
);
|
||||||
let url = req.url_for("index", &["test", "html"]);
|
let url = req.url_for("index", ["test", "html"]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
url.ok().unwrap().as_str(),
|
url.ok().unwrap().as_str(),
|
||||||
"http://www.rust-lang.org/user/test.html"
|
"http://www.rust-lang.org/user/test.html"
|
||||||
|
@ -456,7 +456,7 @@ mod tests {
|
||||||
// assert!(rmap.has_resource("https://youtube.com/watch/unknown"));
|
// assert!(rmap.has_resource("https://youtube.com/watch/unknown"));
|
||||||
|
|
||||||
let req = TestRequest::default().rmap(rmap).to_http_request();
|
let req = TestRequest::default().rmap(rmap).to_http_request();
|
||||||
let url = req.url_for("youtube", &["oHg5SJYRHA0"]);
|
let url = req.url_for("youtube", ["oHg5SJYRHA0"]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
url.ok().unwrap().as_str(),
|
url.ok().unwrap().as_str(),
|
||||||
"https://youtube.com/watch/oHg5SJYRHA0"
|
"https://youtube.com/watch/oHg5SJYRHA0"
|
||||||
|
|
|
@ -1239,7 +1239,7 @@ mod tests {
|
||||||
"/",
|
"/",
|
||||||
web::get().to(|req: HttpRequest| async move {
|
web::get().to(|req: HttpRequest| async move {
|
||||||
HttpResponse::Ok().body(
|
HttpResponse::Ok().body(
|
||||||
req.url_for("youtube", &["xxxxxx"])
|
req.url_for("youtube", ["xxxxxx"])
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_str()
|
.as_str()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
|
@ -1264,7 +1264,7 @@ mod tests {
|
||||||
web::scope("/b").service(web::resource("/c/{stuff}").name("c").route(
|
web::scope("/b").service(web::resource("/c/{stuff}").name("c").route(
|
||||||
web::get().to(|req: HttpRequest| async move {
|
web::get().to(|req: HttpRequest| async move {
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.body(format!("{}", req.url_for("c", &["12345"]).unwrap()))
|
.body(format!("{}", req.url_for("c", ["12345"]).unwrap()))
|
||||||
}),
|
}),
|
||||||
)),
|
)),
|
||||||
)))
|
)))
|
||||||
|
|
|
@ -942,7 +942,7 @@ mod tests {
|
||||||
.origin("test-origin")
|
.origin("test-origin")
|
||||||
.max_frame_size(100)
|
.max_frame_size(100)
|
||||||
.server_mode()
|
.server_mode()
|
||||||
.protocols(&["v1", "v2"])
|
.protocols(["v1", "v2"])
|
||||||
.set_header_if_none(header::CONTENT_TYPE, "json")
|
.set_header_if_none(header::CONTENT_TYPE, "json")
|
||||||
.set_header_if_none(header::CONTENT_TYPE, "text")
|
.set_header_if_none(header::CONTENT_TYPE, "text")
|
||||||
.cookie(Cookie::build("cookie1", "value1").finish())
|
.cookie(Cookie::build("cookie1", "value1").finish())
|
||||||
|
@ -952,7 +952,7 @@ mod tests {
|
||||||
"test-origin"
|
"test-origin"
|
||||||
);
|
);
|
||||||
assert_eq!(builder.inner.as_ref().unwrap().max_size, 100);
|
assert_eq!(builder.inner.as_ref().unwrap().max_size, 100);
|
||||||
assert_eq!(builder.inner.as_ref().unwrap().server_mode, true);
|
assert!(builder.inner.as_ref().unwrap().server_mode);
|
||||||
assert_eq!(builder.protocols, Some("v1,v2".to_string()));
|
assert_eq!(builder.protocols, Some("v1,v2".to_string()));
|
||||||
|
|
||||||
let client = builder.finish().unwrap();
|
let client = builder.finish().unwrap();
|
||||||
|
|
|
@ -228,10 +228,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_none(frm: &Result<Option<(bool, OpCode, Option<Bytes>)>, ProtocolError>) -> bool {
|
fn is_none(frm: &Result<Option<(bool, OpCode, Option<Bytes>)>, ProtocolError>) -> bool {
|
||||||
match *frm {
|
matches!(*frm, Ok(None))
|
||||||
Ok(None) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract(frm: Result<Option<(bool, OpCode, Option<Bytes>)>, ProtocolError>) -> F {
|
fn extract(frm: Result<Option<(bool, OpCode, Option<Bytes>)>, ProtocolError>) -> F {
|
||||||
|
@ -315,7 +312,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_frame_no_mask() {
|
fn test_parse_frame_no_mask() {
|
||||||
let mut buf = BytesMut::from(&[0b0000_0001u8, 0b0000_0001u8][..]);
|
let mut buf = BytesMut::from(&[0b0000_0001u8, 0b0000_0001u8][..]);
|
||||||
buf.extend(&[1u8]);
|
buf.extend([1u8]);
|
||||||
|
|
||||||
assert!(Parser::parse(&mut buf, true, 1024).is_err());
|
assert!(Parser::parse(&mut buf, true, 1024).is_err());
|
||||||
|
|
||||||
|
@ -328,7 +325,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_frame_max_size() {
|
fn test_parse_frame_max_size() {
|
||||||
let mut buf = BytesMut::from(&[0b0000_0001u8, 0b0000_0010u8][..]);
|
let mut buf = BytesMut::from(&[0b0000_0001u8, 0b0000_0010u8][..]);
|
||||||
buf.extend(&[1u8, 1u8]);
|
buf.extend([1u8, 1u8]);
|
||||||
|
|
||||||
assert!(Parser::parse(&mut buf, true, 1).is_err());
|
assert!(Parser::parse(&mut buf, true, 1).is_err());
|
||||||
|
|
||||||
|
|
|
@ -773,15 +773,13 @@ async fn test_client_cookie_handling() {
|
||||||
})
|
})
|
||||||
.map_err(|_| Error::new(IoError::from(ErrorKind::NotFound)));
|
.map_err(|_| Error::new(IoError::from(ErrorKind::NotFound)));
|
||||||
|
|
||||||
if let Err(e) = res {
|
res?;
|
||||||
Err(e)
|
|
||||||
} else {
|
|
||||||
// Send some cookies back
|
// Send some cookies back
|
||||||
Ok::<_, Error>(
|
Ok::<_, Error>(
|
||||||
HttpResponse::Ok().cookie(cookie1).cookie(cookie2).finish(),
|
HttpResponse::Ok().cookie(cookie1).cookie(cookie2).finish(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
|
@ -499,14 +499,10 @@ async fn test_ws_transport() {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// start websocket service
|
// start websocket service
|
||||||
loop {
|
while let Some(item) =
|
||||||
if let Some(item) =
|
|
||||||
io.recv(&BytesCodec).await.map_err(|e| e.into_inner())?
|
io.recv(&BytesCodec).await.map_err(|e| e.into_inner())?
|
||||||
{
|
{
|
||||||
io.send(item.freeze(), &BytesCodec).await.unwrap()
|
io.send(item.freeze(), &BytesCodec).await.unwrap()
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok::<_, io::Error>(())
|
Ok::<_, io::Error>(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,17 +337,17 @@ async fn test_content_length() {
|
||||||
|
|
||||||
{
|
{
|
||||||
for i in 0..4 {
|
for i in 0..4 {
|
||||||
let req = srv.request(Method::GET, &format!("/{}", i));
|
let req = srv.request(Method::GET, format!("/{}", i));
|
||||||
let response = req.send().await.unwrap();
|
let response = req.send().await.unwrap();
|
||||||
assert_eq!(response.headers().get(&header), None);
|
assert_eq!(response.headers().get(&header), None);
|
||||||
|
|
||||||
let req = srv.request(Method::HEAD, &format!("/{}", i));
|
let req = srv.request(Method::HEAD, format!("/{}", i));
|
||||||
let response = req.send().await.unwrap();
|
let response = req.send().await.unwrap();
|
||||||
assert_eq!(response.headers().get(&header), None);
|
assert_eq!(response.headers().get(&header), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 4..6 {
|
for i in 4..6 {
|
||||||
let req = srv.request(Method::GET, &format!("/{}", i));
|
let req = srv.request(Method::GET, format!("/{}", i));
|
||||||
let response = req.send().await.unwrap();
|
let response = req.send().await.unwrap();
|
||||||
assert_eq!(response.headers().get(&header), Some(&value));
|
assert_eq!(response.headers().get(&header), Some(&value));
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,14 +259,10 @@ async fn test_transport() {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// start websocket service
|
// start websocket service
|
||||||
loop {
|
while let Some(item) =
|
||||||
if let Some(item) =
|
|
||||||
io.recv(&BytesCodec).await.map_err(|e| e.into_inner())?
|
io.recv(&BytesCodec).await.map_err(|e| e.into_inner())?
|
||||||
{
|
{
|
||||||
io.send(item.freeze(), &BytesCodec).await.unwrap()
|
io.send(item.freeze(), &BytesCodec).await.unwrap()
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok::<_, io::Error>(())
|
Ok::<_, io::Error>(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue