fix(client): GET and HEAD shouldn't add Transfer-Encoding
Also adds an EmptyWriter, used for GET and HEAD requests, which will return an io::ShortWrite error if the user ever tries to write to a GET or HEAD request. Closes #77
This commit is contained in:
51
src/mock.rs
51
src/mock.rs
@@ -1,20 +1,55 @@
|
||||
use std::io::IoResult;
|
||||
use std::fmt;
|
||||
use std::io::{IoResult, MemReader, MemWriter};
|
||||
use std::io::net::ip::{SocketAddr, ToSocketAddr};
|
||||
|
||||
use net::{NetworkStream, NetworkConnector};
|
||||
|
||||
#[deriving(Clone, PartialEq, Show)]
|
||||
pub struct MockStream;
|
||||
pub struct MockStream {
|
||||
pub read: MemReader,
|
||||
pub write: MemWriter,
|
||||
}
|
||||
|
||||
impl Clone for MockStream {
|
||||
fn clone(&self) -> MockStream {
|
||||
MockStream {
|
||||
read: MemReader::new(self.read.get_ref().to_vec()),
|
||||
write: MemWriter::from_vec(self.write.get_ref().to_vec()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for MockStream {
|
||||
fn eq(&self, other: &MockStream) -> bool {
|
||||
self.read.get_ref() == other.read.get_ref() &&
|
||||
self.write.get_ref() == other.write.get_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Show for MockStream {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "MockStream {{ read: {}, write: {} }}",
|
||||
self.read.get_ref(), self.write.get_ref())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl MockStream {
|
||||
pub fn new() -> MockStream {
|
||||
MockStream {
|
||||
read: MemReader::new(vec![]),
|
||||
write: MemWriter::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Reader for MockStream {
|
||||
fn read(&mut self, _buf: &mut [u8]) -> IoResult<uint> {
|
||||
unimplemented!()
|
||||
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
|
||||
self.read.read(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl Writer for MockStream {
|
||||
fn write(&mut self, _msg: &[u8]) -> IoResult<()> {
|
||||
unimplemented!()
|
||||
fn write(&mut self, msg: &[u8]) -> IoResult<()> {
|
||||
self.write.write(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +62,6 @@ impl NetworkStream for MockStream {
|
||||
|
||||
impl NetworkConnector for MockStream {
|
||||
fn connect<To: ToSocketAddr>(_addr: To, _scheme: &str) -> IoResult<MockStream> {
|
||||
Ok(MockStream)
|
||||
Ok(MockStream::new())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user