mirror of
https://github.com/actix/actix-extras.git
synced 2024-12-04 20:11:55 +01:00
update tests
This commit is contained in:
parent
0143e18fe9
commit
c800bf55f5
@ -98,10 +98,10 @@ pub enum ParseError {
|
|||||||
Timeout,
|
Timeout,
|
||||||
/// An `io::Error` that occurred while trying to read or write to a network stream.
|
/// An `io::Error` that occurred while trying to read or write to a network stream.
|
||||||
#[fail(display="IO error: {}", _0)]
|
#[fail(display="IO error: {}", _0)]
|
||||||
Io(IoError),
|
Io(#[cause] IoError),
|
||||||
/// Parsing a field as string failed
|
/// Parsing a field as string failed
|
||||||
#[fail(display="UTF8 error: {}", _0)]
|
#[fail(display="UTF8 error: {}", _0)]
|
||||||
Utf8(Utf8Error),
|
Utf8(#[cause] Utf8Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return `BadRequest` for `ParseError`
|
/// Return `BadRequest` for `ParseError`
|
||||||
|
21
src/ws.rs
21
src/ws.rs
@ -26,18 +26,13 @@
|
|||||||
//! payload: Payload, ctx: &mut HttpContext<Self>) -> RouteResult<Self>
|
//! payload: Payload, ctx: &mut HttpContext<Self>) -> RouteResult<Self>
|
||||||
//! {
|
//! {
|
||||||
//! // WebSocket handshake
|
//! // WebSocket handshake
|
||||||
//! match ws::handshake(&req) {
|
//! let resp = ws::handshake(&req)?;
|
||||||
//! Ok(resp) => {
|
|
||||||
//! // Send handshake response to peer
|
//! // Send handshake response to peer
|
||||||
//! ctx.start(resp);
|
//! ctx.start(resp);
|
||||||
//! // Map Payload into WsStream
|
//! // Map Payload into WsStream
|
||||||
//! ctx.add_stream(ws::WsStream::new(payload));
|
//! ctx.add_stream(ws::WsStream::new(payload));
|
||||||
//! // Start ws messages processing
|
//! // Start ws messages processing
|
||||||
//! Reply::async(WsRoute)
|
//! Reply::async(WsRoute)
|
||||||
//! },
|
|
||||||
//! Err(err) =>
|
|
||||||
//! Reply::reply(err)
|
|
||||||
//! }
|
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
@ -345,21 +340,21 @@ mod tests {
|
|||||||
|
|
||||||
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
||||||
Version::HTTP_11, HeaderMap::new(), String::new());
|
Version::HTTP_11, HeaderMap::new(), String::new());
|
||||||
assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap());
|
assert_eq!(WsHandshakeError::NoWebsocketUpgrade, handshake(&req).err().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(header::UPGRADE,
|
headers.insert(header::UPGRADE,
|
||||||
header::HeaderValue::from_static("test"));
|
header::HeaderValue::from_static("test"));
|
||||||
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
||||||
Version::HTTP_11, headers, String::new());
|
Version::HTTP_11, headers, String::new());
|
||||||
assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap());
|
assert_eq!(WsHandshakeError::NoWebsocketUpgrade, handshake(&req).err().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(header::UPGRADE,
|
headers.insert(header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"));
|
header::HeaderValue::from_static("websocket"));
|
||||||
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
||||||
Version::HTTP_11, headers, String::new());
|
Version::HTTP_11, headers, String::new());
|
||||||
assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap());
|
assert_eq!(WsHandshakeError::NoConnectionUpgrade, handshake(&req).err().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(header::UPGRADE,
|
headers.insert(header::UPGRADE,
|
||||||
@ -368,7 +363,7 @@ mod tests {
|
|||||||
header::HeaderValue::from_static("upgrade"));
|
header::HeaderValue::from_static("upgrade"));
|
||||||
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
||||||
Version::HTTP_11, headers, String::new());
|
Version::HTTP_11, headers, String::new());
|
||||||
assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap());
|
assert_eq!(WsHandshakeError::NoVersionHeader, handshake(&req).err().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(header::UPGRADE,
|
headers.insert(header::UPGRADE,
|
||||||
@ -379,7 +374,7 @@ mod tests {
|
|||||||
header::HeaderValue::from_static("5"));
|
header::HeaderValue::from_static("5"));
|
||||||
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
||||||
Version::HTTP_11, headers, String::new());
|
Version::HTTP_11, headers, String::new());
|
||||||
assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap());
|
assert_eq!(WsHandshakeError::UnsupportedVersion, handshake(&req).err().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(header::UPGRADE,
|
headers.insert(header::UPGRADE,
|
||||||
@ -390,7 +385,7 @@ mod tests {
|
|||||||
header::HeaderValue::from_static("13"));
|
header::HeaderValue::from_static("13"));
|
||||||
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
||||||
Version::HTTP_11, headers, String::new());
|
Version::HTTP_11, headers, String::new());
|
||||||
assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap());
|
assert_eq!(WsHandshakeError::BadWebsocketKey, handshake(&req).err().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(header::UPGRADE,
|
headers.insert(header::UPGRADE,
|
||||||
@ -403,6 +398,6 @@ mod tests {
|
|||||||
header::HeaderValue::from_static("13"));
|
header::HeaderValue::from_static("13"));
|
||||||
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
||||||
Version::HTTP_11, headers, String::new());
|
Version::HTTP_11, headers, String::new());
|
||||||
assert_eq!(WsHandshakeError::GetMethodRequired, handshake(&req).err().unwrap());
|
assert_eq!(StatusCode::SWITCHING_PROTOCOLS, handshake(&req).unwrap().status());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user