Skip to content

Commit 38ed6c6

Browse files
author
Michael Eden
authored
Fix server incoming client iterator. (#106)
This should also fix the autobahn tests for the server Fixes #104
1 parent 06be5a1 commit 38ed6c6

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

examples/autobahn-server.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use websocket::message::Type;
88
fn main() {
99
let server = Server::bind("127.0.0.1:9002").unwrap();
1010

11-
for connection in server {
11+
for connection in server.filter_map(Result::ok) {
12+
1213
thread::spawn(move || {
1314
let client = connection.accept().unwrap();
1415

examples/hyper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() {
3030
// Start listening for WebSocket connections
3131
let ws_server = Server::bind("127.0.0.1:2794").unwrap();
3232

33-
for connection in ws_server {
33+
for connection in ws_server.filter_map(Result::ok) {
3434
// Spawn a new thread for each connection.
3535
thread::spawn(move || {
3636
if !connection.protocols().contains(&"rust-websocket".to_string()) {

examples/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use websocket::message::Type;
77
fn main() {
88
let server = Server::bind("127.0.0.1:2794").unwrap();
99

10-
for request in server {
10+
for request in server.filter_map(Result::ok) {
1111
// Spawn a new thread for each connection.
1212
thread::spawn(move || {
1313
if !request.protocols().contains(&"rust-websocket".to_string()) {

src/server/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl OptionalSslAcceptor for SslAcceptor {}
6565
///
6666
///let server = Server::bind("127.0.0.1:1234").unwrap();
6767
///
68-
///for connection in server {
68+
///for connection in server.filter_map(Result::ok) {
6969
/// // Spawn a new thread for each connection.
7070
/// thread::spawn(move || {
7171
/// let mut client = connection.accept().unwrap();
@@ -109,7 +109,7 @@ impl OptionalSslAcceptor for SslAcceptor {}
109109
///
110110
///let server = Server::bind_secure("127.0.0.1:1234", acceptor).unwrap();
111111
///
112-
///for connection in server {
112+
///for connection in server.filter_map(Result::ok) {
113113
/// // Spawn a new thread for each connection.
114114
/// thread::spawn(move || {
115115
/// let mut client = connection.accept().unwrap();
@@ -220,10 +220,10 @@ impl Server<SslAcceptor> {
220220

221221
#[cfg(feature="ssl")]
222222
impl Iterator for Server<SslAcceptor> {
223-
type Item = WsUpgrade<SslStream<TcpStream>>;
223+
type Item = AcceptResult<SslStream<TcpStream>>;
224224

225225
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
226-
self.accept().ok()
226+
Some(self.accept())
227227
}
228228
}
229229

@@ -265,9 +265,9 @@ impl Server<NoSslAcceptor> {
265265
}
266266

267267
impl Iterator for Server<NoSslAcceptor> {
268-
type Item = WsUpgrade<TcpStream>;
268+
type Item = AcceptResult<TcpStream>;
269269

270270
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
271-
self.accept().ok()
271+
Some(self.accept())
272272
}
273273
}

src/server/upgrade/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub mod from_hyper;
3131
///
3232
/// This struct represents bytes that have already been read in from the stream.
3333
/// A slice of valid data in this buffer can be obtained by: `&buf[pos..cap]`.
34+
#[derive(Debug)]
3435
pub struct Buffer {
3536
/// the contents of the buffered stream data
3637
pub buf: Vec<u8>,
@@ -415,7 +416,7 @@ fn validate(
415416
fn check_connection_header(headers: &Vec<ConnectionOption>) -> bool {
416417
for header in headers {
417418
if let &ConnectionOption::ConnectionHeader(ref h) = header {
418-
if h as &str == "upgrade" {
419+
if UniCase(h as &str) == UniCase("upgrade") {
419420
return true;
420421
}
421422
}

0 commit comments

Comments
 (0)