Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ language: rust

script:
- cargo build
- cargo build --features ssl
- cargo test
- cargo test --features ssl
- cargo bench --no-run
- cargo bench --no-run --features ssl

after_success: |
[ $TRAVIS_BRANCH = master ] &&
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ name = "hyper"
version = "0.0.1"
authors = ["Sean McArthur <sean.monstar@gmail.com>"]

[features]

ssl = ["openssl"]

[dependencies.url]
git = "https://github.com/servo/rust-url"

[dependencies.openssl]
git = "https://github.com/sfackler/rust-openssl"
optional = true

[dependencies.mime]
git = "https://github.com/hyperium/mime.rs"
Expand Down
1 change: 0 additions & 1 deletion src/client/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use version;
use HttpResult;
use client::Response;


/// A client request to a remote server.
pub struct Request<W> {
/// The target URI for this request.
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![feature(macro_rules, phase, default_type_params, if_let, slicing_syntax,
tuple_indexing)]
tuple_indexing, globs)]
#![deny(missing_docs)]
#![deny(warnings)]
#![experimental]
Expand Down Expand Up @@ -129,14 +129,16 @@
extern crate serialize;
extern crate time;
extern crate url;
extern crate openssl;
#[phase(plugin,link)] extern crate log;
#[cfg(test)] extern crate test;
extern crate "unsafe-any" as uany;
extern crate "move-acceptor" as macceptor;
extern crate typeable;
extern crate cookie;

#[cfg(feature = "ssl")]
extern crate openssl;

pub use std::io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr, Port};
pub use mimewrapper::mime;
pub use url::Url;
Expand Down
29 changes: 23 additions & 6 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,30 @@ use std::any::{Any, AnyRefExt};
use std::boxed::BoxAny;
use std::fmt;
use std::intrinsics::TypeId;
use std::io::{IoResult, IoError, ConnectionAborted, InvalidInput, OtherIoError,
Stream, Listener, Acceptor};
use std::io::{IoResult, IoError, InvalidInput, Stream, Listener, Acceptor};
use std::io::net::ip::{SocketAddr, ToSocketAddr};
use std::io::net::tcp::{TcpStream, TcpListener, TcpAcceptor};
use std::mem::{mod, transmute, transmute_copy};
use std::raw::{mod, TraitObject};
use std::sync::{Arc, Mutex};

use uany::UncheckedBoxAnyDowncast;
use typeable::Typeable;
use openssl::ssl::{SslStream, SslContext, Sslv23};
use openssl::ssl::error::{SslError, StreamError, OpenSslErrors, SslSessionClosed};

use self::HttpStream::{Http, Https};
use self::HttpStream::Http;

#[cfg(feature = "ssl")]
use self::HttpStream::Https;

#[cfg(feature = "ssl")]
use self::sslhelpers::*;

#[cfg(feature = "ssl")]
mod sslhelpers {
pub use openssl::ssl::{SslStream, SslContext, Sslv23};
pub use openssl::ssl::error::{SslError, StreamError, OpenSslErrors, SslSessionClosed};
pub use std::sync::{Arc, Mutex};
pub use std::io::{ConnectionAborted, OtherIoError};
}

/// The write-status indicating headers have not been written.
pub struct Fresh;
Expand Down Expand Up @@ -176,6 +186,7 @@ pub enum HttpStream {
/// A stream over the HTTP protocol.
Http(TcpStream),
/// A stream over the HTTP protocol, protected by SSL.
#[cfg(feature = "ssl")]
// You may be asking wtf an Arc and Mutex? That's because SslStream
// doesn't implement Clone, and we need Clone to use the stream for
// both the Request and Response.
Expand All @@ -188,6 +199,7 @@ impl Reader for HttpStream {
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
match *self {
Http(ref mut inner) => inner.read(buf),
#[cfg(feature = "ssl")]
Https(ref mut inner, _) => inner.lock().read(buf)
}
}
Expand All @@ -198,13 +210,15 @@ impl Writer for HttpStream {
fn write(&mut self, msg: &[u8]) -> IoResult<()> {
match *self {
Http(ref mut inner) => inner.write(msg),
#[cfg(feature = "ssl")]
Https(ref mut inner, _) => inner.lock().write(msg)
}
}
#[inline]
fn flush(&mut self) -> IoResult<()> {
match *self {
Http(ref mut inner) => inner.flush(),
#[cfg(feature = "ssl")]
Https(ref mut inner, _) => inner.lock().flush(),
}
}
Expand All @@ -215,6 +229,7 @@ impl NetworkStream for HttpStream {
fn peer_name(&mut self) -> IoResult<SocketAddr> {
match *self {
Http(ref mut inner) => inner.peer_name(),
#[cfg(feature = "ssl")]
Https(_, addr) => Ok(addr)
}
}
Expand All @@ -227,6 +242,7 @@ impl NetworkConnector for HttpStream {
debug!("http scheme");
Ok(Http(try!(TcpStream::connect(addr))))
},
#[cfg(feature = "ssl")]
"https" => {
debug!("https scheme");
let mut stream = try!(TcpStream::connect(addr));
Expand All @@ -248,6 +264,7 @@ impl NetworkConnector for HttpStream {
}
}

#[cfg(feature = "ssl")]
fn lift_ssl_error(ssl: SslError) -> IoError {
match ssl {
StreamError(err) => err,
Expand Down