use Buffered Readers and Writers
This commit is contained in:
		| @@ -2,7 +2,7 @@ | ||||
| //! | ||||
| //! These are requests that a `hyper::Server` receives, and include its method, | ||||
| //! target URI, headers, and message body. | ||||
| use std::io::{Reader, IoResult}; | ||||
| use std::io::{Reader, BufferedReader, IoResult}; | ||||
| use std::io::net::ip::SocketAddr; | ||||
| use std::io::net::tcp::TcpStream; | ||||
|  | ||||
| @@ -26,7 +26,7 @@ pub struct Request { | ||||
|     pub uri: RequestUri, | ||||
|     /// The version of HTTP for this request. | ||||
|     pub version: HttpVersion, | ||||
|     body: HttpReader<TcpStream> | ||||
|     body: HttpReader<BufferedReader<TcpStream>> | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -35,13 +35,14 @@ impl Request { | ||||
|     /// Create a new Request, reading the StartLine and Headers so they are | ||||
|     /// immediately useful. | ||||
|     pub fn new(mut tcp: TcpStream) -> HttpResult<Request> { | ||||
|         let remote_addr = try_io!(tcp.peer_name()); | ||||
|         let mut tcp = BufferedReader::new(tcp); | ||||
|         let (method, uri, version) = try!(read_request_line(&mut tcp)); | ||||
|         let mut headers = try!(Headers::from_raw(&mut tcp)); | ||||
|  | ||||
|         debug!("{} {} {}", method, uri, version); | ||||
|         debug!("{}", headers); | ||||
|  | ||||
|         let remote_addr = try_io!(tcp.peer_name()); | ||||
|  | ||||
|         // TODO: handle Transfer-Encoding | ||||
|         let body = if headers.has::<ContentLength>() { | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| //! | ||||
| //! These are responses sent by a `hyper::Server` to clients, after | ||||
| //! receiving a request. | ||||
| use std::io::IoResult; | ||||
| use std::io::{BufferedWriter, IoResult}; | ||||
| use std::io::net::tcp::TcpStream; | ||||
|  | ||||
| use header; | ||||
| @@ -21,7 +21,7 @@ pub struct Response { | ||||
|     pub version: version::HttpVersion, | ||||
|  | ||||
|     headers_written: bool, // TODO: can this check be moved to compile time? | ||||
|     body: TcpStream | ||||
|     body: BufferedWriter<TcpStream>, // TODO: use a HttpWriter from rfc7230 | ||||
| } | ||||
|  | ||||
| impl Response { | ||||
| @@ -33,7 +33,7 @@ impl Response { | ||||
|             version: version::Http11, | ||||
|             headers: header::Headers::new(), | ||||
|             headers_written: false, | ||||
|             body: tcp | ||||
|             body: BufferedWriter::new(tcp) | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -56,9 +56,9 @@ impl Response { | ||||
|     } | ||||
|  | ||||
|     /// Flushes all writing of a response to the client. | ||||
|     pub fn end(&mut self) -> IoResult<()> { | ||||
|         try!(self.flush()); | ||||
|         self.body.close_write() | ||||
|     pub fn end(mut self) -> IoResult<()> { | ||||
|         debug!("ending"); | ||||
|         self.flush() | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user