diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index d7cd42f6..ab81bbcd 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,5 +1,12 @@ # Changes +## [0.2.9] - 2019-08-xx + +### Changed + +* Dropped the `byteorder`-dependency in favor of `stdlib`-implementation + + ## [0.2.8] - 2019-08-01 ### Added diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 50b52d12..5cf5cafc 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -57,7 +57,6 @@ actix-threadpool = "0.1.1" base64 = "0.10" bitflags = "1.0" bytes = "0.4" -byteorder = "1.2" copyless = "0.1.4" derive_more = "0.15.0" either = "1.5.2" diff --git a/actix-http/src/ws/frame.rs b/actix-http/src/ws/frame.rs index 652746b8..46e9f36d 100644 --- a/actix-http/src/ws/frame.rs +++ b/actix-http/src/ws/frame.rs @@ -1,4 +1,5 @@ -use byteorder::{ByteOrder, LittleEndian, NetworkEndian}; +use std::convert::TryFrom; + use bytes::{BufMut, Bytes, BytesMut}; use log::debug; use rand; @@ -48,14 +49,16 @@ impl Parser { if chunk_len < 4 { return Ok(None); } - let len = NetworkEndian::read_uint(&src[idx..], 2) as usize; + let len = usize::from(u16::from_be_bytes( + TryFrom::try_from(&src[idx..idx + 2]).unwrap(), + )); idx += 2; len } else if len == 127 { if chunk_len < 10 { return Ok(None); } - let len = NetworkEndian::read_uint(&src[idx..], 8); + let len = u64::from_be_bytes(TryFrom::try_from(&src[idx..idx + 8]).unwrap()); if len > max_size as u64 { return Err(ProtocolError::Overflow); } @@ -75,10 +78,10 @@ impl Parser { return Ok(None); } - let mask: &[u8] = &src[idx..idx + 4]; - let mask_u32 = LittleEndian::read_u32(mask); + let mask = + u32::from_le_bytes(TryFrom::try_from(&src[idx..idx + 4]).unwrap()); idx += 4; - Some(mask_u32) + Some(mask) } else { None }; @@ -137,7 +140,7 @@ impl Parser { /// Parse the payload of a close frame. pub fn parse_close_payload(payload: &[u8]) -> Option { if payload.len() >= 2 { - let raw_code = NetworkEndian::read_u16(payload); + let raw_code = u16::from_be_bytes(TryFrom::try_from(&payload[..2]).unwrap()); let code = CloseCode::from(raw_code); let description = if payload.len() > 2 { Some(String::from_utf8_lossy(&payload[2..]).into()) @@ -201,10 +204,7 @@ impl Parser { let payload = match reason { None => Vec::new(), Some(reason) => { - let mut code_bytes = [0; 2]; - NetworkEndian::write_u16(&mut code_bytes, reason.code.into()); - - let mut payload = Vec::from(&code_bytes[..]); + let mut payload = Into::::into(reason.code).to_be_bytes().to_vec(); if let Some(description) = reason.description { payload.extend(description.as_bytes()); } diff --git a/actix-http/src/ws/mask.rs b/actix-http/src/ws/mask.rs index 15737541..9f730403 100644 --- a/actix-http/src/ws/mask.rs +++ b/actix-http/src/ws/mask.rs @@ -105,7 +105,6 @@ fn align_buf(buf: &mut [u8]) -> (ShortSlice, &mut [u64], ShortSlice) { #[cfg(test)] mod tests { use super::apply_mask; - use byteorder::{ByteOrder, LittleEndian}; /// A safe unoptimized mask application. fn apply_mask_fallback(buf: &mut [u8], mask: &[u8; 4]) { @@ -117,7 +116,7 @@ mod tests { #[test] fn test_apply_mask() { let mask = [0x6d, 0xb6, 0xb2, 0x80]; - let mask_u32: u32 = LittleEndian::read_u32(&mask); + let mask_u32 = u32::from_le_bytes(mask); let unmasked = vec![ 0xf3, 0x00, 0x01, 0x02, 0x03, 0x80, 0x81, 0x82, 0xff, 0xfe, 0x00, 0x17,