sweep most unwraps from ethcore crate, dapps crate (#2762)

* sweep most unwraps from ethcore crate

* purge unwrap from dapps server

* whitespace

[ci:none]
This commit is contained in:
Robert Habermeier
2016-10-20 23:41:15 +02:00
committed by Gav Wood
parent 866ab9c7a3
commit 96f4c10453
31 changed files with 150 additions and 80 deletions

View File

@@ -19,6 +19,7 @@
use std::io::Write;
use hyper::{header, server, Decoder, Encoder, Next};
use hyper::net::HttpStream;
use hyper::mime::Mime;
use hyper::status::StatusCode;
use util::version;
@@ -29,22 +30,22 @@ use handlers::add_security_headers;
pub struct ContentHandler {
code: StatusCode,
content: String,
mimetype: String,
mimetype: Mime,
write_pos: usize,
safe_to_embed_at_port: Option<u16>,
}
impl ContentHandler {
pub fn ok(content: String, mimetype: String) -> Self {
pub fn ok(content: String, mimetype: Mime) -> Self {
Self::new(StatusCode::Ok, content, mimetype)
}
pub fn not_found(content: String, mimetype: String) -> Self {
pub fn not_found(content: String, mimetype: Mime) -> Self {
Self::new(StatusCode::NotFound, content, mimetype)
}
pub fn html(code: StatusCode, content: String, embeddable_at: Option<u16>) -> Self {
Self::new_embeddable(code, content, "text/html".into(), embeddable_at)
Self::new_embeddable(code, content, mime!(Text/Html), embeddable_at)
}
pub fn error(code: StatusCode, title: &str, message: &str, details: Option<&str>) -> Self {
@@ -61,11 +62,11 @@ impl ContentHandler {
), embeddable_at)
}
pub fn new(code: StatusCode, content: String, mimetype: String) -> Self {
pub fn new(code: StatusCode, content: String, mimetype: Mime) -> Self {
Self::new_embeddable(code, content, mimetype, None)
}
pub fn new_embeddable(code: StatusCode, content: String, mimetype: String, embeddable_at: Option<u16>) -> Self {
pub fn new_embeddable(code: StatusCode, content: String, mimetype: Mime, embeddable_at: Option<u16>) -> Self {
ContentHandler {
code: code,
content: content,
@@ -87,7 +88,7 @@ impl server::Handler<HttpStream> for ContentHandler {
fn on_response(&mut self, res: &mut server::Response) -> Next {
res.set_status(self.code);
res.headers_mut().set(header::ContentType(self.mimetype.parse().unwrap()));
res.headers_mut().set(header::ContentType(self.mimetype.clone()));
add_security_headers(&mut res.headers_mut(), self.safe_to_embed_at_port.clone());
Next::write()
}