Skip to content

Commit 2f606c8

Browse files
committed
feat(http): Implement Debug for HttpReader/Writer.
Also derives it for Responses, since that's easy now.
1 parent ad797b0 commit 2f606c8

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/client/response.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use version;
1414
use HttpResult;
1515

1616
/// A response for a client request to a remote server.
17+
#[derive(Debug)]
1718
pub struct Response<S = HttpStream> {
1819
/// The status from the server.
1920
pub status: status::StatusCode,

src/http.rs

+24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use std::borrow::{Cow, ToOwned};
33
use std::cmp::min;
44
use std::io::{self, Read, Write, BufRead};
5+
use std::fmt;
56

67
use httparse;
78

@@ -60,6 +61,18 @@ impl<R: Read> HttpReader<R> {
6061
}
6162
}
6263

64+
impl<R> fmt::Debug for HttpReader<R> {
65+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
66+
match *self {
67+
SizedReader(_,rem) => write!(fmt, "SizedReader(remaining={:?})", rem),
68+
ChunkedReader(_, None) => write!(fmt, "ChunkedReader(chunk_remaining=unknown)"),
69+
ChunkedReader(_, Some(rem)) => write!(fmt, "ChunkedReader(chunk_remaining={:?})", rem),
70+
EofReader(_) => write!(fmt, "EofReader"),
71+
EmptyReader(_) => write!(fmt, "EmptyReader"),
72+
}
73+
}
74+
}
75+
6376
impl<R: Read> Read for HttpReader<R> {
6477
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
6578
match *self {
@@ -305,6 +318,17 @@ impl<W: Write> Write for HttpWriter<W> {
305318
}
306319
}
307320

321+
impl<W: Write> fmt::Debug for HttpWriter<W> {
322+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
323+
match *self {
324+
ThroughWriter(_) => write!(fmt, "ThroughWriter"),
325+
ChunkedWriter(_) => write!(fmt, "ChunkedWriter"),
326+
SizedWriter(_, rem) => write!(fmt, "SizedWriter(remaining={:?})", rem),
327+
EmptyWriter(_) => write!(fmt, "EmptyWriter"),
328+
}
329+
}
330+
}
331+
308332
const MAX_HEADERS: usize = 100;
309333

310334
/// Parses a request into an Incoming message head.

src/server/response.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use net::{Fresh, Streaming};
1515
use version;
1616

1717
/// The outgoing half for a Tcp connection, created by a `Server` and given to a `Handler`.
18+
#[derive(Debug)]
1819
pub struct Response<'a, W = Fresh> {
1920
/// The HTTP version of this response.
2021
pub version: version::HttpVersion,

0 commit comments

Comments
 (0)