Skip to content

Commit d6fb9fe

Browse files
committed
updated all dependencies to the latest and greatest
1 parent 7fed8bb commit d6fb9fe

File tree

8 files changed

+267
-255
lines changed

8 files changed

+267
-255
lines changed

Cargo.toml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
name = "websocket"
44
version = "0.17.2"
5-
authors = ["cyderize <admin@cyderize.org>"]
5+
authors = ["cyderize <admin@cyderize.org>", "Michael Eden <themichaeleden@gmail.com>"]
66

77
description = "A WebSocket (RFC6455) library for Rust."
88

@@ -17,16 +17,14 @@ keywords = ["websocket", "websockets", "rfc6455"]
1717
license = "MIT"
1818

1919
[dependencies]
20-
hyper = ">=0.7, <0.10"
21-
mio = "0.5.1"
22-
unicase = "1.0.1"
23-
openssl = "0.7.6"
24-
url = "1.0"
25-
rustc-serialize = "0.3.16"
26-
bitflags = "0.7"
27-
rand = "0.3.12"
28-
byteorder = "1.0"
29-
net2 = "0.2.17"
20+
hyper = "^0.10"
21+
unicase = "^1.0"
22+
openssl = "^0.9.10"
23+
url = "^1.0"
24+
rustc-serialize = "^0.3"
25+
bitflags = "^0.8"
26+
rand = "^0.3"
27+
byteorder = "^1.0"
3028

3129
[features]
3230
nightly = ["hyper/nightly"]

src/client/builder.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ use hyper::header::{
2323
ProtocolName,
2424
};
2525
use unicase::UniCase;
26-
use openssl::ssl::error::SslError;
26+
use openssl::error::ErrorStack as SslError;
2727
use openssl::ssl::{
2828
SslContext,
2929
SslMethod,
3030
SslStream,
31+
SslConnector,
32+
SslConnectorBuilder,
3133
};
3234
use header::extensions::Extension;
3335
use header::{
@@ -73,23 +75,21 @@ macro_rules! upsert_header {
7375

7476
/// Build clients with a builder-style API
7577
#[derive(Clone, Debug)]
76-
pub struct ClientBuilder<'u, 's> {
78+
pub struct ClientBuilder<'u> {
7779
url: Cow<'u, Url>,
7880
version: HttpVersion,
7981
headers: Headers,
8082
version_set: bool,
8183
key_set: bool,
82-
ssl_context: Option<Cow<'s, SslContext>>,
8384
}
8485

85-
impl<'u, 's> ClientBuilder<'u, 's> {
86+
impl<'u> ClientBuilder<'u> {
8687
pub fn new(url: Cow<'u, Url>) -> Self {
8788
ClientBuilder {
8889
url: url,
8990
version: HttpVersion::Http11,
9091
version_set: false,
9192
key_set: false,
92-
ssl_context: None,
9393
headers: Headers::new(),
9494
}
9595
}
@@ -184,11 +184,6 @@ impl<'u, 's> ClientBuilder<'u, 's> {
184184
self
185185
}
186186

187-
pub fn ssl_context(mut self, context: &'s SslContext) -> Self {
188-
self.ssl_context = Some(Cow::Borrowed(context));
189-
self
190-
}
191-
192187
fn establish_tcp(&mut self, secure: Option<bool>) -> WebSocketResult<TcpStream> {
193188
let port = match (self.url.port(), secure) {
194189
(Some(port), _) => port,
@@ -206,20 +201,30 @@ impl<'u, 's> ClientBuilder<'u, 's> {
206201
Ok(tcp_stream)
207202
}
208203

209-
fn wrap_ssl(&self, tcp_stream: TcpStream) -> Result<SslStream<TcpStream>, SslError> {
210-
let context = match self.ssl_context {
211-
Some(ref ctx) => Cow::Borrowed(ctx.as_ref()),
212-
None => Cow::Owned(try!(SslContext::new(SslMethod::Tlsv1))),
204+
fn wrap_ssl(&self,
205+
tcp_stream: TcpStream,
206+
connector: Option<SslConnector>
207+
) -> WebSocketResult<SslStream<TcpStream>> {
208+
let host = match self.url.host_str() {
209+
Some(h) => h,
210+
None => return Err(WebSocketError::WebSocketUrlError(WSUrlErrorKind::NoHostName)),
211+
};
212+
let connector = match connector {
213+
Some(c) => c,
214+
None => try!(SslConnectorBuilder::new(SslMethod::tls())).build(),
213215
};
214216

215-
SslStream::connect(&*context, tcp_stream)
217+
let ssl_stream = try!(connector.connect(host, tcp_stream));
218+
Ok(ssl_stream)
216219
}
217220

218-
pub fn connect(&mut self) -> WebSocketResult<Client<BoxedNetworkStream>> {
221+
pub fn connect(&mut self,
222+
ssl_config: Option<SslConnector>
223+
) -> WebSocketResult<Client<BoxedNetworkStream>> {
219224
let tcp_stream = try!(self.establish_tcp(None));
220225

221226
let boxed_stream = if self.url.scheme() == "wss" {
222-
BoxedNetworkStream(Box::new(try!(self.wrap_ssl(tcp_stream))))
227+
BoxedNetworkStream(Box::new(try!(self.wrap_ssl(tcp_stream, ssl_config))))
223228
} else {
224229
BoxedNetworkStream(Box::new(tcp_stream))
225230
};
@@ -233,10 +238,12 @@ impl<'u, 's> ClientBuilder<'u, 's> {
233238
self.connect_on(tcp_stream)
234239
}
235240

236-
pub fn connect_secure(&mut self) -> WebSocketResult<Client<SslStream<TcpStream>>> {
241+
pub fn connect_secure(&mut self,
242+
ssl_config: Option<SslConnector>
243+
) -> WebSocketResult<Client<SslStream<TcpStream>>> {
237244
let tcp_stream = try!(self.establish_tcp(Some(true)));
238245

239-
let ssl_stream = try!(self.wrap_ssl(tcp_stream));
246+
let ssl_stream = try!(self.wrap_ssl(tcp_stream, ssl_config));
240247

241248
self.connect_on(ssl_stream)
242249
}
@@ -291,7 +298,7 @@ impl<'u, 's> ClientBuilder<'u, 's> {
291298
WebSocketError::RequestError("Request Sec-WebSocket-Key was invalid")
292299
));
293300

294-
if response.headers.get() != Some(&(WebSocketAccept::new(key))) {
301+
if response.headers.get() != Some(&(try!(WebSocketAccept::new(key)))) {
295302
return Err(WebSocketError::ResponseError("Sec-WebSocket-Accept is invalid"));
296303
}
297304

src/client/mod.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Contains the WebSocket client.
22
extern crate url;
3-
extern crate net2;
43

54
use std::borrow::{
65
Cow,
@@ -22,7 +21,6 @@ use openssl::ssl::{
2221
SslMethod,
2322
SslStream,
2423
};
25-
use openssl::ssl::error::SslError;
2624
use hyper::buffer::BufReader;
2725
use hyper::status::StatusCode;
2826
use hyper::http::h1::parse_response;
@@ -37,7 +35,6 @@ use hyper::header::{
3735
ProtocolName,
3836
};
3937
use unicase::UniCase;
40-
use self::net2::TcpStreamExt;
4138

4239
use ws;
4340
use ws::sender::Sender as SenderTrait;
@@ -157,25 +154,20 @@ impl<S> Client<S>
157154
self.stream.as_tcp().set_nodelay(nodelay)
158155
}
159156

160-
/// See `TcpStream.set_keepalive()`.
161-
pub fn set_keepalive(&mut self, delay_in_ms: Option<u32>) -> IoResult<()> {
162-
TcpStreamExt::set_keepalive_ms(self.stream.as_tcp(), delay_in_ms)
163-
}
164-
165157
/// Changes whether the stream is in nonblocking mode.
166158
pub fn set_nonblocking(&self, nonblocking: bool) -> IoResult<()> {
167159
self.stream.as_tcp().set_nonblocking(nonblocking)
168160
}
169161
}
170162

171-
impl<'u, 'p, 'e, 's, S> Client<S>
163+
impl<'u, S> Client<S>
172164
where S: Stream,
173165
{
174-
pub fn from_url(address: &'u Url) -> ClientBuilder<'u, 's> {
166+
pub fn from_url(address: &'u Url) -> ClientBuilder<'u> {
175167
ClientBuilder::new(Cow::Borrowed(address))
176168
}
177169

178-
pub fn build(address: &str) -> Result<ClientBuilder<'u, 's>, ParseError> {
170+
pub fn build(address: &str) -> Result<ClientBuilder<'u>, ParseError> {
179171
let url = try!(Url::parse(address));
180172
Ok(ClientBuilder::new(Cow::Owned(url)))
181173
}

src/header/accept.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::fmt::{self, Debug};
55
use std::str::FromStr;
66
use serialize::base64::{ToBase64, FromBase64, STANDARD};
77
use header::WebSocketKey;
8-
use openssl::crypto::hash::{self, hash};
8+
use openssl::hash::{self, hash};
9+
use openssl::error::ErrorStack as SslError;
910
use result::{WebSocketResult, WebSocketError};
1011

1112
static MAGIC_GUID: &'static str = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
@@ -49,18 +50,18 @@ impl FromStr for WebSocketAccept {
4950

5051
impl WebSocketAccept {
5152
/// Create a new WebSocketAccept from the given WebSocketKey
52-
pub fn new(key: &WebSocketKey) -> WebSocketAccept {
53+
pub fn new(key: &WebSocketKey) -> Result<WebSocketAccept, SslError> {
5354
let serialized = key.serialize();
5455
let mut concat_key = String::with_capacity(serialized.len() + 36);
5556
concat_key.push_str(&serialized[..]);
5657
concat_key.push_str(MAGIC_GUID);
57-
let output = hash(hash::Type::SHA1, concat_key.as_bytes());
58+
let output = try!(hash(hash::MessageDigest::sha1(), concat_key.as_bytes()));
5859
let mut iter = output.into_iter();
5960
let mut bytes = [0u8; 20];
6061
for i in bytes.iter_mut() {
6162
*i = iter.next().unwrap();
6263
}
63-
WebSocketAccept(bytes)
64+
Ok(WebSocketAccept(bytes))
6465
}
6566
/// Return the Base64 encoding of this WebSocketAccept
6667
pub fn serialize(&self) -> String {

0 commit comments

Comments
 (0)