Skip to content

Commit

Permalink
feat(http): Implement Debug for HttpReader/Writer.
Browse files Browse the repository at this point in the history
Also derives it for Responses, since that's easy now.
  • Loading branch information
brandonson committed Apr 9, 2015
1 parent ad797b0 commit 2f606c8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/client/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/server/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2f606c8

Please sign in to comment.