From 4888604ab8b6a9c88dbf8fd8a29c49264608c1eb Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 5 Dec 2018 12:46:25 -0800 Subject: [PATCH] Remove the unused EncodingDecoder The project "encoding" appears to be unmaintained, and hasn't received an update since 2017. Unfortunately the "encoding" artifacts on crates.io do not contain the licenses for the project, which adds difficulty in auditing dependencies. Since "tiny-http" doesn't actually use the EncodingDecoder, this patch removes it and it's dependency on "encoding" in order to avoid complications resolving the "tiny-http" dependency story. Instead, I would suggest investigating migrating over to https://docs.rs/encoding_rs/0.8.13/encoding_rs/, which appears to be actively maintained by Mozilla. If this patch is accepted, would it be possible to get a release as well? --- Cargo.toml | 1 - src/lib.rs | 2 -- src/util/encoding_decoder.rs | 59 ------------------------------------ src/util/mod.rs | 2 -- 4 files changed, 64 deletions(-) delete mode 100644 src/util/encoding_decoder.rs diff --git a/Cargo.toml b/Cargo.toml index aaf8eb176..65b98b705 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ ssl = ["openssl"] [dependencies] ascii = "0.8" chunked_transfer = "0.3" -encoding = "0.2" openssl = { version = "0.10", optional = true } url = "1.7" chrono = "0.4" diff --git a/src/lib.rs b/src/lib.rs index a768c80b6..9ec7c796e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,7 +112,6 @@ extern crate log; extern crate ascii; extern crate chunked_transfer; -extern crate encoding; extern crate url; extern crate chrono; @@ -142,7 +141,6 @@ mod common; mod request; mod response; -#[allow(dead_code)] // TODO: remove when everything is implemented mod util; /// The main class of this library. diff --git a/src/util/encoding_decoder.rs b/src/util/encoding_decoder.rs deleted file mode 100644 index 1adbae3b1..000000000 --- a/src/util/encoding_decoder.rs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2015 The tiny-http Contributors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use std::io::Result as IoResult; -use std::io::{Cursor, Read}; -use encoding::{DecoderTrap, Encoding}; - -// TODO: for the moment the first call to read() reads the whole -// underlying reader at once and decodes it - -pub struct EncodingDecoder { - reader: R, - encoding: &'static Encoding, - content: Option>>, -} - -impl EncodingDecoder where R: Read { - pub fn new(reader: R, encoding: &'static Encoding) -> EncodingDecoder { - EncodingDecoder { - reader: reader, - encoding: encoding, - content: None, - } - } -} - -impl Read for EncodingDecoder where R: Read { - fn read(&mut self, buf: &mut [u8]) -> IoResult { - if self.content.is_none() { - let mut data = Vec::with_capacity(0); - try!(self.reader.read_to_end(&mut data)); - - let result = match self.encoding.decode(&data, DecoderTrap::Strict) { - Ok(s) => s, - Err(_) => panic!(), // FIXME: return Err(old_io::standard_error(old_io::InvalidInput)) - }; - - self.content = Some(Cursor::new(result.into_bytes())); - } - - if let Some(ref mut content) = self.content { - content.read(buf) - - } else { - unreachable!(); - } - } -} diff --git a/src/util/mod.rs b/src/util/mod.rs index e80f920db..0e6e71f50 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -13,7 +13,6 @@ // limitations under the License. pub use self::custom_stream::CustomStream; -pub use self::encoding_decoder::EncodingDecoder; pub use self::equal_reader::EqualReader; pub use self::messages_queue::MessagesQueue; pub use self::refined_tcp_stream::RefinedTcpStream; @@ -24,7 +23,6 @@ pub use self::task_pool::TaskPool; use std::str::FromStr; mod custom_stream; -mod encoding_decoder; mod equal_reader; mod messages_queue; mod refined_tcp_stream;