refactor(uri): make ByteStr an implementation detail of uri

This commit is contained in:
Yazad Daruvala
2017-06-23 21:52:56 -07:00
parent 579d360f51
commit 3021cd9dd8
6 changed files with 11 additions and 22 deletions

View File

@@ -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 {

View File

@@ -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)]

View File

@@ -1,45 +0,0 @@
use std::ops::Deref;
use std::str;
use bytes::Bytes;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ByteStr(Bytes);
impl ByteStr {
pub unsafe fn from_utf8_unchecked(slice: Bytes) -> ByteStr {
ByteStr(slice)
}
pub fn from_static(s: &'static str) -> ByteStr {
ByteStr(Bytes::from_static(s.as_bytes()))
}
pub fn slice(&self, from: usize, to: usize) -> ByteStr {
assert!(self.as_str().is_char_boundary(from));
assert!(self.as_str().is_char_boundary(to));
ByteStr(self.0.slice(from, to))
}
pub fn slice_to(&self, idx: usize) -> ByteStr {
assert!(self.as_str().is_char_boundary(idx));
ByteStr(self.0.slice_to(idx))
}
pub fn as_str(&self) -> &str {
unsafe { str::from_utf8_unchecked(self.0.as_ref()) }
}
}
impl Deref for ByteStr {
type Target = str;
fn deref(&self) -> &str {
self.as_str()
}
}
impl<'a> From<&'a str> for ByteStr {
fn from(s: &'a str) -> ByteStr {
ByteStr(Bytes::from(s))
}
}