summaryrefslogtreecommitdiffstats
path: root/ipfs-api/src/header.rs
diff options
context:
space:
mode:
authorFerris Tseng <ferristseng@fastmail.fm>2017-11-02 12:13:40 -0400
committerFerris Tseng <ferristseng@fastmail.fm>2017-11-02 12:13:40 -0400
commit07f9bac5a02e8d430e6b0549f24169c0b5a8933a (patch)
tree081a861a58ca3468ab6890720daed15d13c79c77 /ipfs-api/src/header.rs
parent4a894700617d8dc42ae6eaca25e3647cf1f178d9 (diff)
add better handling for stream errors; implement filestore calls
Diffstat (limited to 'ipfs-api/src/header.rs')
-rw-r--r--ipfs-api/src/header.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/ipfs-api/src/header.rs b/ipfs-api/src/header.rs
new file mode 100644
index 0000000..32941cc
--- /dev/null
+++ b/ipfs-api/src/header.rs
@@ -0,0 +1,44 @@
+// Copyright 2017 rust-ipfs-api Developers
+//
+// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
+// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
+// http://opensource.org/licenses/MIT>, at your option. This file may not be
+// copied, modified, or distributed except according to those terms.
+//
+
+use hyper;
+use hyper::header::{self, Header, Raw};
+use std::fmt;
+
+
+#[derive(Debug, Clone, Copy)]
+pub enum Trailer {
+ StreamError,
+}
+
+impl Header for Trailer {
+ fn header_name() -> &'static str {
+ "Trailer"
+ }
+
+ fn parse_header(raw: &Raw) -> hyper::Result<Trailer> {
+ if let Some(bytes) = raw.one() {
+ let value = String::from_utf8_lossy(bytes);
+
+ match value.as_ref() {
+ "X-Stream-Error" => Ok(Trailer::StreamError),
+ _ => Err(hyper::Error::Header),
+ }
+ } else {
+ Err(hyper::Error::Header)
+ }
+ }
+
+ fn fmt_header(&self, f: &mut header::Formatter) -> fmt::Result {
+ let value = match *self {
+ Trailer::StreamError => "X-Stream-Error",
+ };
+
+ f.fmt_line(&value)
+ }
+}