From 2f606c88bd91e5e36dee4c6db00c3117b1adf067 Mon Sep 17 00:00:00 2001 From: Brandon Sanderson 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 { /// 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 HttpReader { } } +impl fmt::Debug for HttpReader { + 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 Read for HttpReader { fn read(&mut self, buf: &mut [u8]) -> io::Result { match *self { @@ -305,6 +318,17 @@ impl Write for HttpWriter { } } +impl fmt::Debug for HttpWriter { + 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,