1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

Use encoding_rs crate instead of unmaintained encoding crate (#922)

* Use encoding_rs crate instead of unmaintained encoding crate

* Update changelog
This commit is contained in:
messense
2019-06-18 14:43:25 +08:00
committed by Nikolay Kim
parent d7780d53c9
commit 313ac48765
8 changed files with 57 additions and 45 deletions

View File

@ -1,5 +1,11 @@
# Changes
## [0.2.5] - unreleased
### Changed
* Use `encoding_rs` crate instead of unmaintained `encoding` crate
## [0.2.4] - 2019-06-16
### Fixed
@ -83,7 +89,7 @@
## [0.1.1] - 2019-04-19
### Changes
### Changed
* Cookie::max_age() accepts value in seconds

View File

@ -58,7 +58,7 @@ byteorder = "1.2"
copyless = "0.1.2"
derive_more = "0.15.0"
either = "1.5.2"
encoding = "0.2"
encoding_rs = "0.8"
futures = "0.1.25"
hashbrown = "0.5.0"
h2 = "0.1.16"

View File

@ -1,9 +1,7 @@
use std::cell::{Ref, RefMut};
use std::str;
use encoding::all::UTF_8;
use encoding::label::encoding_from_whatwg_label;
use encoding::EncodingRef;
use encoding_rs::{Encoding, UTF_8};
use http::header;
use mime::Mime;
@ -59,10 +57,12 @@ pub trait HttpMessage: Sized {
/// Get content type encoding
///
/// UTF-8 is used by default, If request charset is not set.
fn encoding(&self) -> Result<EncodingRef, ContentTypeError> {
fn encoding(&self) -> Result<&'static Encoding, ContentTypeError> {
if let Some(mime_type) = self.mime_type()? {
if let Some(charset) = mime_type.get_param("charset") {
if let Some(enc) = encoding_from_whatwg_label(charset.as_str()) {
if let Some(enc) =
Encoding::for_label_no_replacement(charset.as_str().as_bytes())
{
Ok(enc)
} else {
Err(ContentTypeError::UnknownEncoding)
@ -166,8 +166,7 @@ where
#[cfg(test)]
mod tests {
use bytes::Bytes;
use encoding::all::ISO_8859_2;
use encoding::Encoding;
use encoding_rs::ISO_8859_2;
use mime;
use super::*;
@ -223,7 +222,7 @@ mod tests {
"application/json; charset=ISO-8859-2",
)
.finish();
assert_eq!(ISO_8859_2.name(), req.encoding().unwrap().name());
assert_eq!(ISO_8859_2, req.encoding().unwrap());
}
#[test]