add bits to deal with Upgrade requests

This commit is contained in:
Sean McArthur
2014-09-24 17:31:56 -07:00
parent 68e2278339
commit 0ab52c9009
9 changed files with 314 additions and 60 deletions

View File

@@ -65,6 +65,11 @@ impl Response {
body: body,
})
}
/// Unwraps the Request to return the NetworkStream underneath.
pub fn unwrap(self) -> Box<NetworkStream + Send> {
self.body.unwrap().unwrap()
}
}
impl Reader for Response {
@@ -73,3 +78,33 @@ impl Reader for Response {
self.body.read(buf)
}
}
#[cfg(test)]
mod tests {
use std::boxed::BoxAny;
use std::io::BufferedReader;
use header::Headers;
use http::EofReader;
use mock::MockStream;
use net::NetworkStream;
use status;
use version;
use super::Response;
#[test]
fn test_unwrap() {
let res = Response {
status: status::Ok,
headers: Headers::new(),
version: version::Http11,
body: EofReader(BufferedReader::new(box MockStream as Box<NetworkStream + Send>))
};
let b = res.unwrap().downcast::<MockStream>().unwrap();
assert_eq!(b, box MockStream);
}
}