From 2f606c88bd91e5e36dee4c6db00c3117b1adf067 Mon Sep 17 00:00:00 2001
From: Brandon Sanderson <bas.bsanders@gmail.com>
Date: Wed, 8 Apr 2015 17:51:18 -0700
Subject: [PATCH] feat(http): Implement Debug for HttpReader/Writer.

Also derives it for Responses, since that's easy now.
---
 src/client/response.rs |  1 +
 src/http.rs            | 24 ++++++++++++++++++++++++
 src/server/response.rs |  1 +
 3 files changed, 26 insertions(+)

diff --git a/src/client/response.rs b/src/client/response.rs
index fcc0646833..9b9cd19e39 100644
--- a/src/client/response.rs
+++ b/src/client/response.rs
@@ -14,6 +14,7 @@ use version;
 use HttpResult;
 
 /// A response for a client request to a remote server.
+#[derive(Debug)]
 pub struct Response<S = HttpStream> {
     /// The status from the server.
     pub status: status::StatusCode,
diff --git a/src/http.rs b/src/http.rs
index 13b8104dd3..3f00ec00f3 100644
--- a/src/http.rs
+++ b/src/http.rs
@@ -2,6 +2,7 @@
 use std::borrow::{Cow, ToOwned};
 use std::cmp::min;
 use std::io::{self, Read, Write, BufRead};
+use std::fmt;
 
 use httparse;
 
@@ -60,6 +61,18 @@ impl<R: Read> HttpReader<R> {
     }
 }
 
+impl<R> fmt::Debug for HttpReader<R> {
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
+            SizedReader(_,rem) => write!(fmt, "SizedReader(remaining={:?})", rem),
+            ChunkedReader(_, None) => write!(fmt, "ChunkedReader(chunk_remaining=unknown)"),
+            ChunkedReader(_, Some(rem)) => write!(fmt, "ChunkedReader(chunk_remaining={:?})", rem),
+            EofReader(_) => write!(fmt, "EofReader"),
+            EmptyReader(_) => write!(fmt, "EmptyReader"),
+        }
+    }
+}
+
 impl<R: Read> Read for HttpReader<R> {
     fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
         match *self {
@@ -305,6 +318,17 @@ impl<W: Write> Write for HttpWriter<W> {
     }
 }
 
+impl<W: Write> fmt::Debug for HttpWriter<W> {
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
+            ThroughWriter(_) => write!(fmt, "ThroughWriter"),
+            ChunkedWriter(_) => write!(fmt, "ChunkedWriter"),
+            SizedWriter(_, rem) => write!(fmt, "SizedWriter(remaining={:?})", rem),
+            EmptyWriter(_) => write!(fmt, "EmptyWriter"),
+        }
+    }
+}
+
 const MAX_HEADERS: usize = 100;
 
 /// Parses a request into an Incoming message head.
diff --git a/src/server/response.rs b/src/server/response.rs
index c23efb3235..16bcfc72a1 100644
--- a/src/server/response.rs
+++ b/src/server/response.rs
@@ -15,6 +15,7 @@ use net::{Fresh, Streaming};
 use version;
 
 /// The outgoing half for a Tcp connection, created by a `Server` and given to a `Handler`.
+#[derive(Debug)]
 pub struct Response<'a, W = Fresh> {
     /// The HTTP version of this response.
     pub version: version::HttpVersion,