refactor(uri): make ByteStr an implementation detail of uri
This commit is contained in:
		
							
								
								
									
										3
									
								
								src/common/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/common/mod.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| pub use self::str::ByteStr; | ||||
|  | ||||
| mod str; | ||||
| @@ -5,7 +5,7 @@ use httparse; | ||||
| use bytes::{BytesMut, Bytes}; | ||||
|  | ||||
| use header::{self, Headers, ContentLength, TransferEncoding}; | ||||
| use http::{ByteStr, MessageHead, RawStatus, Http1Transaction, ParseResult, ServerTransaction, ClientTransaction, RequestLine}; | ||||
| use http::{MessageHead, RawStatus, Http1Transaction, ParseResult, ServerTransaction, ClientTransaction, RequestLine}; | ||||
| use http::h1::{Encoder, Decoder, date}; | ||||
| use method::Method; | ||||
| use status::StatusCode; | ||||
| @@ -54,10 +54,10 @@ impl Http1Transaction for ServerTransaction { | ||||
|         let slice = buf.split_to(len).freeze(); | ||||
|         let path = slice.slice(path.0, path.1); | ||||
|         // path was found to be utf8 by httparse | ||||
|         let path = unsafe { ByteStr::from_utf8_unchecked(path) }; | ||||
|         let path = try!(unsafe { ::uri::from_utf8_unchecked(path) }); | ||||
|         let subject = RequestLine( | ||||
|             method, | ||||
|             try!(::uri::from_byte_str(path)), | ||||
|             path, | ||||
|         ); | ||||
|  | ||||
|         headers.extend(HeadersAsBytesIter { | ||||
|   | ||||
| @@ -15,7 +15,6 @@ use version::HttpVersion::{Http10, Http11}; | ||||
| pub use self::conn::{Conn, KeepAlive, KA}; | ||||
| pub use self::body::{Body, TokioBody}; | ||||
| pub use self::chunk::Chunk; | ||||
| pub use self::str::ByteStr; | ||||
|  | ||||
| mod body; | ||||
| mod chunk; | ||||
| @@ -23,23 +22,9 @@ mod conn; | ||||
| mod io; | ||||
| mod h1; | ||||
| //mod h2; | ||||
| mod str; | ||||
| pub mod request; | ||||
| pub mod response; | ||||
|  | ||||
| /* | ||||
| macro_rules! nonblocking { | ||||
|     ($e:expr) => ({ | ||||
|         match $e { | ||||
|             Ok(n) => Ok(Some(n)), | ||||
|             Err(e) => match e.kind() { | ||||
|                 stdio::ErrorKind::WouldBlock => Ok(None), | ||||
|                 _ => Err(e) | ||||
|             } | ||||
|         } | ||||
|     }); | ||||
| } | ||||
| */ | ||||
|  | ||||
| /// An Incoming Message head. Includes request/status line, and headers. | ||||
| #[derive(Clone, Debug, Default, PartialEq)] | ||||
|   | ||||
| @@ -37,6 +37,7 @@ extern crate unicase; | ||||
| extern crate test; | ||||
|  | ||||
|  | ||||
| mod common; | ||||
| pub use uri::Uri; | ||||
| pub use client::Client; | ||||
| pub use error::{Result, Error}; | ||||
|   | ||||
| @@ -2,8 +2,8 @@ use std::error::Error as StdError; | ||||
| use std::fmt::{Display, self}; | ||||
| use std::str::{self, FromStr}; | ||||
|  | ||||
| use http::ByteStr; | ||||
| use bytes::{BufMut, BytesMut}; | ||||
| use ::common::ByteStr; | ||||
| use bytes::{BufMut, Bytes, BytesMut}; | ||||
|  | ||||
| /// The Request-URI of a Request's StartLine. | ||||
| /// | ||||
| @@ -297,8 +297,8 @@ impl Display for Uri { | ||||
|     } | ||||
| } | ||||
|  | ||||
| pub fn from_byte_str(s: ByteStr) -> Result<Uri, UriError> { | ||||
|     Uri::new(s) | ||||
| pub unsafe fn from_utf8_unchecked(slice: Bytes) -> Result<Uri, UriError> { | ||||
|     Uri::new(ByteStr::from_utf8_unchecked(slice)) | ||||
| } | ||||
|  | ||||
| pub fn scheme_and_authority(uri: &Uri) -> Option<Uri> { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user