No .expect on mime types
This commit is contained in:
parent
eb327338e8
commit
d005410e1a
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1603,6 +1603,7 @@ dependencies = [
|
|||||||
"ethcore 1.6.0",
|
"ethcore 1.6.0",
|
||||||
"ethcore-util 1.6.0",
|
"ethcore-util 1.6.0",
|
||||||
"hyper 0.10.0-a.0 (git+https://github.com/ethcore/hyper)",
|
"hyper 0.10.0-a.0 (git+https://github.com/ethcore/hyper)",
|
||||||
|
"mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"multihash 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"multihash 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rlp 0.1.0",
|
"rlp 0.1.0",
|
||||||
]
|
]
|
||||||
|
@ -9,6 +9,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
|||||||
ethcore = { path = "../ethcore" }
|
ethcore = { path = "../ethcore" }
|
||||||
ethcore-util = { path = "../util" }
|
ethcore-util = { path = "../util" }
|
||||||
rlp = { path = "../util/rlp" }
|
rlp = { path = "../util/rlp" }
|
||||||
|
mime = "0.2"
|
||||||
hyper = { default-features = false, git = "https://github.com/ethcore/hyper" }
|
hyper = { default-features = false, git = "https://github.com/ethcore/hyper" }
|
||||||
cid = "~0.2.0"
|
cid = "0.2"
|
||||||
multihash = "~0.5.0"
|
multihash = "0.5"
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate mime;
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
extern crate multihash;
|
extern crate multihash;
|
||||||
extern crate cid;
|
extern crate cid;
|
||||||
@ -58,11 +60,18 @@ impl Handler<HttpStream> for IpfsHandler {
|
|||||||
|
|
||||||
match *self.out() {
|
match *self.out() {
|
||||||
OctetStream(ref bytes) => {
|
OctetStream(ref bytes) => {
|
||||||
let headers = res.headers_mut();
|
use mime::{Mime, TopLevel, SubLevel};
|
||||||
|
|
||||||
headers.set(ContentLength(bytes.len() as u64));
|
// `OctetStream` is not a valid variant, so need to construct
|
||||||
headers.set(ContentType("application/octet-stream".parse()
|
// the type manually.
|
||||||
.expect("Static content type; qed")));
|
let content_type = Mime(
|
||||||
|
TopLevel::Application,
|
||||||
|
SubLevel::Ext("octet-stream".into()),
|
||||||
|
vec![]
|
||||||
|
);
|
||||||
|
|
||||||
|
res.headers_mut().set(ContentLength(bytes.len() as u64));
|
||||||
|
res.headers_mut().set(ContentType(content_type));
|
||||||
|
|
||||||
Next::write()
|
Next::write()
|
||||||
},
|
},
|
||||||
@ -70,8 +79,7 @@ impl Handler<HttpStream> for IpfsHandler {
|
|||||||
res.set_status(StatusCode::NotFound);
|
res.set_status(StatusCode::NotFound);
|
||||||
|
|
||||||
res.headers_mut().set(ContentLength(reason.len() as u64));
|
res.headers_mut().set(ContentLength(reason.len() as u64));
|
||||||
res.headers_mut().set(ContentType("text/plain".parse()
|
res.headers_mut().set(ContentType(mime!(Text/Plain)));
|
||||||
.expect("Static content type; qed")));
|
|
||||||
|
|
||||||
Next::write()
|
Next::write()
|
||||||
},
|
},
|
||||||
@ -79,8 +87,7 @@ impl Handler<HttpStream> for IpfsHandler {
|
|||||||
res.set_status(StatusCode::BadRequest);
|
res.set_status(StatusCode::BadRequest);
|
||||||
|
|
||||||
res.headers_mut().set(ContentLength(reason.len() as u64));
|
res.headers_mut().set(ContentLength(reason.len() as u64));
|
||||||
res.headers_mut().set(ContentType("text/plain".parse()
|
res.headers_mut().set(ContentType(mime!(Text/Plain)));
|
||||||
.expect("Static content type; qed")));
|
|
||||||
|
|
||||||
Next::write()
|
Next::write()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user