1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-09-01 01:16:59 +02:00

clippy warnings; fmt

This commit is contained in:
Nikolay Kim
2018-04-28 22:55:47 -07:00
parent a38c3985f6
commit de49796fd1
67 changed files with 988 additions and 1866 deletions

View File

@@ -1,8 +1,8 @@
use bytes::{Bytes, BytesMut};
use encoding::EncodingRef;
use encoding::all::UTF_8;
use encoding::label::encoding_from_whatwg_label;
use encoding::types::{DecoderTrap, Encoding};
use encoding::EncodingRef;
use futures::{Future, Poll, Stream};
use http::{header, HeaderMap};
use http_range::HttpRange;
@@ -96,10 +96,8 @@ pub trait HttpMessage {
/// `size` is full size of response (file).
fn range(&self, size: u64) -> Result<Vec<HttpRange>, HttpRangeError> {
if let Some(range) = self.headers().get(header::RANGE) {
HttpRange::parse(
unsafe { str::from_utf8_unchecked(range.as_bytes()) },
size,
).map_err(|e| e.into())
HttpRange::parse(unsafe { str::from_utf8_unchecked(range.as_bytes()) }, size)
.map_err(|e| e.into())
} else {
Ok(Vec::new())
}
@@ -325,10 +323,7 @@ where
));
}
self.fut
.as_mut()
.expect("UrlEncoded could not be used second time")
.poll()
self.fut.as_mut().expect("UrlEncoded could not be used second time").poll()
}
}
@@ -385,8 +380,7 @@ where
if req.content_type().to_lowercase() != "application/x-www-form-urlencoded" {
return Err(UrlencodedError::ContentType);
}
let encoding = req.encoding()
.map_err(|_| UrlencodedError::ContentType)?;
let encoding = req.encoding().map_err(|_| UrlencodedError::ContentType)?;
// future
let limit = self.limit;
@@ -415,18 +409,15 @@ where
self.fut = Some(Box::new(fut));
}
self.fut
.as_mut()
.expect("UrlEncoded could not be used second time")
.poll()
self.fut.as_mut().expect("UrlEncoded could not be used second time").poll()
}
}
#[cfg(test)]
mod tests {
use super::*;
use encoding::Encoding;
use encoding::all::ISO_8859_2;
use encoding::Encoding;
use futures::Async;
use http::{Method, Uri, Version};
use httprequest::HttpRequest;
@@ -488,19 +479,13 @@ mod tests {
#[test]
fn test_encoding_error() {
let req = TestRequest::with_header("content-type", "applicatjson").finish();
assert_eq!(
Some(ContentTypeError::ParseError),
req.encoding().err()
);
assert_eq!(Some(ContentTypeError::ParseError), req.encoding().err());
let req = TestRequest::with_header(
"content-type",
"application/json; charset=kkkttktk",
).finish();
assert_eq!(
Some(ContentTypeError::UnknownEncoding),
req.encoding().err()
);
assert_eq!(Some(ContentTypeError::UnknownEncoding), req.encoding().err());
}
#[test]
@@ -621,8 +606,7 @@ mod tests {
"application/x-www-form-urlencoded",
).header(header::CONTENT_LENGTH, "11")
.finish();
req.payload_mut()
.unread_data(Bytes::from_static(b"hello=world"));
req.payload_mut().unread_data(Bytes::from_static(b"hello=world"));
let result = req.urlencoded::<Info>().poll().ok().unwrap();
assert_eq!(
@@ -637,8 +621,7 @@ mod tests {
"application/x-www-form-urlencoded; charset=utf-8",
).header(header::CONTENT_LENGTH, "11")
.finish();
req.payload_mut()
.unread_data(Bytes::from_static(b"hello=world"));
req.payload_mut().unread_data(Bytes::from_static(b"hello=world"));
let result = req.urlencoded().poll().ok().unwrap();
assert_eq!(
@@ -664,16 +647,14 @@ mod tests {
}
let mut req = HttpRequest::default();
req.payload_mut()
.unread_data(Bytes::from_static(b"test"));
req.payload_mut().unread_data(Bytes::from_static(b"test"));
match req.body().poll().ok().unwrap() {
Async::Ready(bytes) => assert_eq!(bytes, Bytes::from_static(b"test")),
_ => unreachable!("error"),
}
let mut req = HttpRequest::default();
req.payload_mut()
.unread_data(Bytes::from_static(b"11111111111111"));
req.payload_mut().unread_data(Bytes::from_static(b"11111111111111"));
match req.body().limit(5).poll().err().unwrap() {
PayloadError::Overflow => (),
_ => unreachable!("error"),