Skip to content

Commit

Permalink
Merge #142
Browse files Browse the repository at this point in the history
142: Bump dependencies r=frewsxcv a=Eijebong
  • Loading branch information
bors[bot] committed Mar 28, 2018
2 parents 2543158 + 4f61e9f commit 3c31366
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 33 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "tiny_http"
version = "0.5.9"
version = "0.6.0"
authors = ["pierre.krieger1708@gmail.com",
"Corey Farwell <coreyf@rwell.org>"]
description = "Low level HTTP server library"
Expand All @@ -14,14 +14,14 @@ default = []
ssl = ["openssl"]

[dependencies]
ascii = "0.7"
ascii = "0.8"
chunked_transfer = "0.3"
encoding = "0.2"
openssl = { version = "0.7", optional = true }
url = "0.2"
chrono = "0.2.15"
log = "0.3"
openssl = { version = "0.10", optional = true }
url = "1.7"
chrono = "0.4"
log = "0.4"

[dev-dependencies]
rustc-serialize = "0.3"
sha1 = "0.2.0"
sha1 = "0.6.0"
2 changes: 1 addition & 1 deletion src/client.rs
Expand Up @@ -235,7 +235,7 @@ impl Iterator for ClientConnection {
{
let connection_header = rq.headers().iter()
.find(|h| h.field.equiv(&"Connection"))
.map(|h| AsRef::<str>::as_ref(h.value.as_ref()));
.map(|h| h.value.as_str());

let lowercase = connection_header.map(|h| h.to_ascii_lowercase());

Expand Down
8 changes: 4 additions & 4 deletions src/common.rs
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use ascii::{AsciiString, AsciiStr};
use ascii::{AsciiString, AsciiStr, FromAsciiError};
use std::ascii::AsciiExt;
use std::fmt::{self, Display, Formatter};
use std::str::{FromStr};
Expand Down Expand Up @@ -232,7 +232,7 @@ impl Display for Header {
pub struct HeaderField(AsciiString);

impl HeaderField {
pub fn from_bytes<B>(bytes: B) -> Result<HeaderField, B> where B: Into<Vec<u8>> + AsRef<[u8]> {
pub fn from_bytes<B>(bytes: B) -> Result<HeaderField, FromAsciiError<B>> where B: Into<Vec<u8>> + AsRef<[u8]> {
AsciiString::from_ascii(bytes).map(HeaderField)
}

Expand Down Expand Up @@ -432,12 +432,12 @@ impl From<(u8, u8)> for HTTPVersion {
}
/// Represents the current date, expressed in RFC 1123 format, e.g. Sun, 06 Nov 1994 08:49:37 GMT
pub struct HTTPDate {
d: DateTime<UTC>
d: DateTime<Utc>
}

impl HTTPDate {
pub fn new() -> HTTPDate {
HTTPDate {d: UTC::now(),}
HTTPDate {d: Utc::now(),}
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/lib.rs
Expand Up @@ -257,27 +257,26 @@ impl Server {
let ssl: Option<SslContext> = match config.ssl {
#[cfg(feature = "ssl")]
Some(mut config) => {
use std::io::Cursor;
use openssl::ssl;
use openssl::x509::X509;
use openssl::crypto::pkey::PKey;
use openssl::ssl::SSL_VERIFY_NONE;
use openssl::pkey::PKey;
use openssl::ssl::SslVerifyMode;

let mut ctxt = try!(SslContext::new(ssl::SslMethod::Sslv23));
let mut ctxt = try!(SslContext::builder(ssl::SslMethod::tls()));
try!(ctxt.set_cipher_list("DEFAULT"));
let certificate = try!(X509::from_pem(&mut Cursor::new(&config.certificate[..])));
let certificate = try!(X509::from_pem(&config.certificate[..]));
try!(ctxt.set_certificate(&certificate));
let private_key = try!(PKey::private_key_from_pem(&mut Cursor::new(&config.private_key[..])));
let private_key = try!(PKey::private_key_from_pem(&config.private_key[..]));
try!(ctxt.set_private_key(&private_key));
ctxt.set_verify(SSL_VERIFY_NONE, None);
ctxt.set_verify(SslVerifyMode::NONE);
try!(ctxt.check_private_key());

// let's wipe the certificate and private key from memory, because we're
// better safe than sorry
for b in &mut config.certificate { *b = 0; }
for b in &mut config.private_key { *b = 0; }

Some(ctxt)
Some(ctxt.build())
},
#[cfg(not(feature = "ssl"))]
Some(_) => return Err("Building a server with SSL requires enabling the `ssl` feature \
Expand Down Expand Up @@ -306,9 +305,10 @@ impl Server {
},
#[cfg(feature = "ssl")]
Some(ref ssl) => {
let ssl = openssl::ssl::Ssl::new(ssl).expect("Couldn't create ssl");
// trying to apply SSL over the connection
// if an error occurs, we just close the socket and resume listening
let sock = match openssl::ssl::SslStream::accept(ssl, sock) {
let sock = match ssl.accept(sock) {
Ok(s) => s,
Err(_) => continue
};
Expand Down
4 changes: 2 additions & 2 deletions src/request.rs
Expand Up @@ -132,7 +132,7 @@ pub fn new_request<R, W>(secure: bool, method: Method, path: String,

// true if the client sent a `Expect: 100-continue` header
let expects_continue = {
match headers.iter().find(|h: &&Header| h.field.equiv(&"Expect")).map(|h| AsRef::<str>::as_ref(h.value.as_ref())) {
match headers.iter().find(|h: &&Header| h.field.equiv(&"Expect")).map(|h| h.value.as_str()) {
None => false,
Some(v) if v.eq_ignore_ascii_case("100-continue")
=> true,
Expand All @@ -142,7 +142,7 @@ pub fn new_request<R, W>(secure: bool, method: Method, path: String,

// true if the client sent a `Connection: upgrade` header
let connection_upgrade = {
match headers.iter().find(|h: &&Header| h.field.equiv(&"Connection")).map(|h| AsRef::<str>::as_ref(h.value.as_ref())) {
match headers.iter().find(|h: &&Header| h.field.equiv(&"Connection")).map(|h| h.value.as_str()) {
Some(v) if v.to_ascii_lowercase().contains("upgrade")
=> true,
_ => false
Expand Down
2 changes: 1 addition & 1 deletion src/response.rs
Expand Up @@ -102,7 +102,7 @@ fn write_message_header<W>(mut writer: W, http_version: &HTTPVersion,
for header in headers.iter() {
try!(writer.write_all(header.field.as_str().as_ref()));
try!(write!(&mut writer, ": "));
try!(writer.write_all(header.value.as_ref().as_ref()));
try!(writer.write_all(header.value.as_str().as_ref()));
try!(write!(&mut writer, "\r\n"));
}

Expand Down
20 changes: 11 additions & 9 deletions src/util/refined_tcp_stream.rs
Expand Up @@ -16,6 +16,8 @@ use std::io::{Read, Write};
use std::io::Result as IoResult;
use std::net::{SocketAddr, TcpStream, Shutdown};

#[cfg(feature = "ssl")]
use std::sync::{Arc, Mutex};
#[cfg(feature = "ssl")]
use openssl::ssl::SslStream;

Expand All @@ -28,7 +30,7 @@ pub struct RefinedTcpStream {
pub enum Stream {
Http(TcpStream),
#[cfg(feature = "ssl")]
Https(SslStream<TcpStream>),
Https(Arc<Mutex<SslStream<TcpStream>>>),
}

impl From<TcpStream> for Stream {
Expand All @@ -42,7 +44,7 @@ impl From<TcpStream> for Stream {
impl From<SslStream<TcpStream>> for Stream {
#[inline]
fn from(stream: SslStream<TcpStream>) -> Stream {
Stream::Https(stream)
Stream::Https(Arc::new(Mutex::new(stream)))
}
}

Expand All @@ -55,7 +57,7 @@ impl RefinedTcpStream {
let read = match stream {
Stream::Http(ref stream) => Stream::Http(stream.try_clone().unwrap()),
#[cfg(feature = "ssl")]
Stream::Https(ref stream) => Stream::Https(stream.try_clone().unwrap()),
Stream::Https(ref stream) => Stream::Https(stream.clone()),
};

let read = RefinedTcpStream {
Expand Down Expand Up @@ -87,7 +89,7 @@ impl RefinedTcpStream {
match self.stream {
Stream::Http(ref mut stream) => stream.peer_addr(),
#[cfg(feature = "ssl")]
Stream::Https(ref mut stream) => stream.get_ref().peer_addr(),
Stream::Https(ref mut stream) => stream.lock().unwrap().get_ref().peer_addr(),
}
}
}
Expand All @@ -99,7 +101,7 @@ impl Drop for RefinedTcpStream {
// ignoring outcome
Stream::Http(ref mut stream) => stream.shutdown(Shutdown::Read).ok(),
#[cfg(feature = "ssl")]
Stream::Https(ref mut stream) => stream.get_mut().shutdown(Shutdown::Read).ok(),
Stream::Https(ref mut stream) => stream.lock().unwrap().get_mut().shutdown(Shutdown::Read).ok(),
};
}

Expand All @@ -108,7 +110,7 @@ impl Drop for RefinedTcpStream {
// ignoring outcome
Stream::Http(ref mut stream) => stream.shutdown(Shutdown::Write).ok(),
#[cfg(feature = "ssl")]
Stream::Https(ref mut stream) => stream.get_mut().shutdown(Shutdown::Write).ok(),
Stream::Https(ref mut stream) => stream.lock().unwrap().get_mut().shutdown(Shutdown::Write).ok(),
};
}
}
Expand All @@ -119,7 +121,7 @@ impl Read for RefinedTcpStream {
match self.stream {
Stream::Http(ref mut stream) => stream.read(buf),
#[cfg(feature = "ssl")]
Stream::Https(ref mut stream) => stream.read(buf),
Stream::Https(ref mut stream) => stream.lock().unwrap().read(buf),
}
}
}
Expand All @@ -129,15 +131,15 @@ impl Write for RefinedTcpStream {
match self.stream {
Stream::Http(ref mut stream) => stream.write(buf),
#[cfg(feature = "ssl")]
Stream::Https(ref mut stream) => stream.write(buf),
Stream::Https(ref mut stream) => stream.lock().unwrap().write(buf),
}
}

fn flush(&mut self) -> IoResult<()> {
match self.stream {
Stream::Http(ref mut stream) => stream.flush(),
#[cfg(feature = "ssl")]
Stream::Https(ref mut stream) => stream.flush(),
Stream::Https(ref mut stream) => stream.lock().unwrap().flush(),
}
}
}

0 comments on commit 3c31366

Please sign in to comment.