feat(http): add get_ref methods to Encoder and Decoder
This commit is contained in:
		| @@ -98,6 +98,12 @@ pub struct BufReader<'a, R: io::Read + 'a> { | ||||
|     reader: &'a mut R | ||||
| } | ||||
|  | ||||
| impl<'a, R: io::Read + 'a> BufReader<'a, R> { | ||||
|     pub fn get_ref(&self) -> &R { | ||||
|         self.reader | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<'a, R: io::Read> Read for BufReader<'a, R> { | ||||
|     fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | ||||
|         trace!("BufReader.read self={}, buf={}", self.buf.len(), buf.len()); | ||||
|   | ||||
| @@ -44,6 +44,15 @@ enum Trans<'a, T: Read + 'a> { | ||||
|     Buf(self::buffer::BufReader<'a, T>) | ||||
| } | ||||
|  | ||||
| impl<'a, T: Read + 'a> Trans<'a, T> { | ||||
|     fn get_ref(&self) -> &T { | ||||
|         match *self { | ||||
|             Trans::Port(ref t) => &*t, | ||||
|             Trans::Buf(ref buf) => buf.get_ref() | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<'a, T: Read + 'a> Read for Trans<'a, T> { | ||||
|     fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | ||||
|         match *self { | ||||
| @@ -62,12 +71,27 @@ impl<'a, T: Read> Decoder<'a, T> { | ||||
|     fn h1(decoder: &'a mut h1::Decoder, transport: Trans<'a, T>) -> Decoder<'a, T> { | ||||
|         Decoder(DecoderImpl::H1(decoder, transport)) | ||||
|     } | ||||
|  | ||||
|     /// Get a reference to the transport. | ||||
|     pub fn get_ref(&self) -> &T { | ||||
|         match self.0 { | ||||
|             DecoderImpl::H1(_, ref transport) => transport.get_ref() | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<'a, T: Transport> Encoder<'a, T> { | ||||
|     fn h1(encoder: &'a mut h1::Encoder, transport: &'a mut T) -> Encoder<'a, T> { | ||||
|         Encoder(EncoderImpl::H1(encoder, transport)) | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /// Get a reference to the transport. | ||||
|     pub fn get_ref(&self) -> &T { | ||||
|         match self.0 { | ||||
|             EncoderImpl::H1(_, ref transport) => &*transport | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<'a, T: Read> Read for Decoder<'a, T> { | ||||
|   | ||||
							
								
								
									
										11
									
								
								src/net.rs
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/net.rs
									
									
									
									
									
								
							| @@ -53,11 +53,6 @@ pub enum Blocked { | ||||
|     Write, | ||||
| } | ||||
|  | ||||
| impl Transport for HttpStream { | ||||
|     fn take_socket_error(&mut self) -> io::Result<()> { | ||||
|         self.0.take_socket_error() | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// Accepts sockets asynchronously. | ||||
| pub trait Accept: Evented { | ||||
| @@ -73,6 +68,12 @@ pub trait Accept: Evented { | ||||
| #[derive(Debug)] | ||||
| pub struct HttpStream(pub TcpStream); | ||||
|  | ||||
| impl Transport for HttpStream { | ||||
|     fn take_socket_error(&mut self) -> io::Result<()> { | ||||
|         self.0.take_socket_error() | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl Read for HttpStream { | ||||
|     #[inline] | ||||
|     fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | ||||
|   | ||||
| @@ -2,7 +2,6 @@ | ||||
| //! | ||||
| //! These are requests that a `hyper::Server` receives, and include its method, | ||||
| //! target URI, headers, and message body. | ||||
| //use std::net::SocketAddr; | ||||
|  | ||||
| use version::HttpVersion; | ||||
| use method::Method; | ||||
| @@ -16,7 +15,6 @@ pub fn new(incoming: RequestHead) -> Request { | ||||
|     debug!("{:#?}", headers); | ||||
|  | ||||
|     Request { | ||||
|         //remote_addr: addr, | ||||
|         method: method, | ||||
|         uri: uri, | ||||
|         headers: headers, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user