diff options
author | Teddy Wing | 2020-07-04 02:55:33 +0200 |
---|---|---|
committer | Teddy Wing | 2020-07-04 02:55:33 +0200 |
commit | 3914b2189069783e6d538f2d742525284c8951c2 (patch) | |
tree | fd5b88d70d4ffed4d5cc1fb21db06def9d4d5f1f | |
parent | cdad0271c909c90e800a7e9dd95658b143475d15 (diff) | |
download | fastcgi-conduit-3914b2189069783e6d538f2d742525284c8951c2.tar.bz2 |
server: Rename `Error::WriteError` to `Error::Write` and remove context
Since we don't actually need any additional context here, we can remove
it. Since that allows us to avoid calling `context()` with the
`WriteError` context selector, we can then safely rename `WriteError` to
`Write`.
-rw-r--r-- | src/server.rs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/server.rs b/src/server.rs index e3e5d9a..2b70c0d 100644 --- a/src/server.rs +++ b/src/server.rs @@ -13,8 +13,8 @@ const HTTP_VERSION: &'static str = "HTTP/1.1"; #[derive(Debug, Snafu)] pub enum Error { - #[snafu(display("{}", source))] - WriteError { source: io::Error }, + #[snafu(context(false))] + Write { source: io::Error }, #[snafu(display("Couldn't build request: {}", source))] RequestBuilder { source: request::Error }, @@ -35,7 +35,7 @@ impl Server { // TODO: log // Ignore write errors as clients will have closed the // connection by this point. - Err(Error::WriteError { .. }) => (), + Err(Error::Write { .. }) => (), Err(Error::RequestBuilder { .. }) => internal_server_error(&mut raw_request.stdout()), @@ -70,21 +70,20 @@ where H: Handler + 'static + Sync HTTP_VERSION, head.status.as_str(), head.status.canonical_reason().unwrap_or("UNKNOWN"), - ) - .context(WriteError)?; + )?; for (name, value) in head.headers.iter() { - write!(&mut stdout, "{}: ", name).context(WriteError)?; - stdout.write(value.as_bytes()).context(WriteError)?; - stdout.write(b"\r\n").context(WriteError)?; + write!(&mut stdout, "{}: ", name)?; + stdout.write(value.as_bytes())?; + stdout.write(b"\r\n")?; } - stdout.write(b"\r\n").context(WriteError)?; + stdout.write(b"\r\n")?; match body { - conduit::Body::Static(slice) => stdout.write(slice).map(|_| ()).context(WriteError)?, - conduit::Body::Owned(vec) => stdout.write(&vec).map(|_| ()).context(WriteError)?, - conduit::Body::File(mut file) => io::copy(&mut file, &mut stdout).map(|_| ()).context(WriteError)?, + conduit::Body::Static(slice) => stdout.write(slice).map(|_| ())?, + conduit::Body::Owned(vec) => stdout.write(&vec).map(|_| ())?, + conduit::Body::File(mut file) => io::copy(&mut file, &mut stdout).map(|_| ())?, }; Ok(()) |