mirror of
https://github.com/actix/actix-web.git
synced 2024-12-30 12:00:38 +00:00
clippy warnings
This commit is contained in:
parent
f3a73d7dde
commit
a7a062fb68
2 changed files with 75 additions and 72 deletions
|
@ -3,7 +3,7 @@ use encoding::all::UTF_8;
|
||||||
use encoding::label::encoding_from_whatwg_label;
|
use encoding::label::encoding_from_whatwg_label;
|
||||||
use encoding::types::{DecoderTrap, Encoding};
|
use encoding::types::{DecoderTrap, Encoding};
|
||||||
use encoding::EncodingRef;
|
use encoding::EncodingRef;
|
||||||
use futures::{Future, Poll, Stream, Async};
|
use futures::{Async, Future, Poll, Stream};
|
||||||
use http::{header, HeaderMap};
|
use http::{header, HeaderMap};
|
||||||
use http_range::HttpRange;
|
use http_range::HttpRange;
|
||||||
use mime::Mime;
|
use mime::Mime;
|
||||||
|
@ -12,8 +12,8 @@ use serde_urlencoded;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use error::{
|
use error::{
|
||||||
ContentTypeError, HttpRangeError, ParseError, PayloadError, UrlencodedError,
|
ContentTypeError, HttpRangeError, ParseError, PayloadError, ReadlinesError,
|
||||||
ReadlinesError
|
UrlencodedError,
|
||||||
};
|
};
|
||||||
use header::Header;
|
use header::Header;
|
||||||
use json::JsonBody;
|
use json::JsonBody;
|
||||||
|
@ -261,7 +261,7 @@ pub trait HttpMessage {
|
||||||
let boundary = Multipart::boundary(self.headers());
|
let boundary = Multipart::boundary(self.headers());
|
||||||
Multipart::new(boundary, self)
|
Multipart::new(boundary, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return stream of lines.
|
/// Return stream of lines.
|
||||||
fn readlines(self) -> Readlines<Self>
|
fn readlines(self) -> Readlines<Self>
|
||||||
where
|
where
|
||||||
|
@ -295,7 +295,7 @@ where
|
||||||
checked_buff: true,
|
checked_buff: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Change max line size. By default max size is 256Kb
|
/// Change max line size. By default max size is 256Kb
|
||||||
pub fn limit(mut self, limit: usize) -> Self {
|
pub fn limit(mut self, limit: usize) -> Self {
|
||||||
self.limit = limit;
|
self.limit = limit;
|
||||||
|
@ -309,31 +309,31 @@ where
|
||||||
{
|
{
|
||||||
type Item = String;
|
type Item = String;
|
||||||
type Error = ReadlinesError;
|
type Error = ReadlinesError;
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
||||||
let encoding = self.req.encoding()?;
|
let encoding = self.req.encoding()?;
|
||||||
// check if there is a newline in the buffer
|
// check if there is a newline in the buffer
|
||||||
if !self.checked_buff {
|
if !self.checked_buff {
|
||||||
let mut found: Option<usize> = None;
|
let mut found: Option<usize> = None;
|
||||||
for (ind, b) in self.buff.iter().enumerate() {
|
for (ind, b) in self.buff.iter().enumerate() {
|
||||||
if *b == '\n' as u8 {
|
if *b == b'\n' {
|
||||||
found = Some(ind);
|
found = Some(ind);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(ind) = found {
|
if let Some(ind) = found {
|
||||||
// check if line is longer than limit
|
// check if line is longer than limit
|
||||||
if ind+1 > self.limit {
|
if ind + 1 > self.limit {
|
||||||
return Err(ReadlinesError::LimitOverflow);
|
return Err(ReadlinesError::LimitOverflow);
|
||||||
}
|
}
|
||||||
let enc: *const Encoding = encoding as *const Encoding;
|
let enc: *const Encoding = encoding as *const Encoding;
|
||||||
let line = if enc == UTF_8 {
|
let line = if enc == UTF_8 {
|
||||||
str::from_utf8(&self.buff.split_to(ind+1))
|
str::from_utf8(&self.buff.split_to(ind + 1))
|
||||||
.map_err(|_| ReadlinesError::EncodingError)?
|
.map_err(|_| ReadlinesError::EncodingError)?
|
||||||
.to_owned()
|
.to_owned()
|
||||||
} else {
|
} else {
|
||||||
encoding
|
encoding
|
||||||
.decode(&self.buff.split_to(ind+1), DecoderTrap::Strict)
|
.decode(&self.buff.split_to(ind + 1), DecoderTrap::Strict)
|
||||||
.map_err(|_| ReadlinesError::EncodingError)?
|
.map_err(|_| ReadlinesError::EncodingError)?
|
||||||
};
|
};
|
||||||
return Ok(Async::Ready(Some(line)));
|
return Ok(Async::Ready(Some(line)));
|
||||||
|
@ -346,24 +346,24 @@ where
|
||||||
// check if there is a newline in bytes
|
// check if there is a newline in bytes
|
||||||
let mut found: Option<usize> = None;
|
let mut found: Option<usize> = None;
|
||||||
for (ind, b) in bytes.iter().enumerate() {
|
for (ind, b) in bytes.iter().enumerate() {
|
||||||
if *b == '\n' as u8 {
|
if *b == b'\n' {
|
||||||
found = Some(ind);
|
found = Some(ind);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(ind) = found {
|
if let Some(ind) = found {
|
||||||
// check if line is longer than limit
|
// check if line is longer than limit
|
||||||
if ind+1 > self.limit {
|
if ind + 1 > self.limit {
|
||||||
return Err(ReadlinesError::LimitOverflow);
|
return Err(ReadlinesError::LimitOverflow);
|
||||||
}
|
}
|
||||||
let enc: *const Encoding = encoding as *const Encoding;
|
let enc: *const Encoding = encoding as *const Encoding;
|
||||||
let line = if enc == UTF_8 {
|
let line = if enc == UTF_8 {
|
||||||
str::from_utf8(&bytes.split_to(ind+1))
|
str::from_utf8(&bytes.split_to(ind + 1))
|
||||||
.map_err(|_| ReadlinesError::EncodingError)?
|
.map_err(|_| ReadlinesError::EncodingError)?
|
||||||
.to_owned()
|
.to_owned()
|
||||||
} else {
|
} else {
|
||||||
encoding
|
encoding
|
||||||
.decode(&bytes.split_to(ind+1), DecoderTrap::Strict)
|
.decode(&bytes.split_to(ind + 1), DecoderTrap::Strict)
|
||||||
.map_err(|_| ReadlinesError::EncodingError)?
|
.map_err(|_| ReadlinesError::EncodingError)?
|
||||||
};
|
};
|
||||||
// extend buffer with rest of the bytes;
|
// extend buffer with rest of the bytes;
|
||||||
|
@ -373,10 +373,10 @@ where
|
||||||
}
|
}
|
||||||
self.buff.extend_from_slice(&bytes);
|
self.buff.extend_from_slice(&bytes);
|
||||||
Ok(Async::NotReady)
|
Ok(Async::NotReady)
|
||||||
},
|
}
|
||||||
Ok(Async::NotReady) => Ok(Async::NotReady),
|
Ok(Async::NotReady) => Ok(Async::NotReady),
|
||||||
Ok(Async::Ready(None)) => {
|
Ok(Async::Ready(None)) => {
|
||||||
if self.buff.len() == 0 {
|
if self.buff.is_empty() {
|
||||||
return Ok(Async::Ready(None));
|
return Ok(Async::Ready(None));
|
||||||
}
|
}
|
||||||
if self.buff.len() > self.limit {
|
if self.buff.len() > self.limit {
|
||||||
|
@ -393,8 +393,8 @@ where
|
||||||
.map_err(|_| ReadlinesError::EncodingError)?
|
.map_err(|_| ReadlinesError::EncodingError)?
|
||||||
};
|
};
|
||||||
self.buff.clear();
|
self.buff.clear();
|
||||||
return Ok(Async::Ready(Some(line)))
|
Ok(Async::Ready(Some(line)))
|
||||||
},
|
}
|
||||||
Err(e) => Err(ReadlinesError::from(e)),
|
Err(e) => Err(ReadlinesError::from(e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -805,29 +805,35 @@ mod tests {
|
||||||
_ => unreachable!("error"),
|
_ => unreachable!("error"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_readlines() {
|
fn test_readlines() {
|
||||||
let mut req = HttpRequest::default();
|
let mut req = HttpRequest::default();
|
||||||
req.payload_mut().unread_data(Bytes::from_static(
|
req.payload_mut().unread_data(Bytes::from_static(
|
||||||
b"Lorem Ipsum is simply dummy text of the printing and typesetting\n\
|
b"Lorem Ipsum is simply dummy text of the printing and typesetting\n\
|
||||||
industry. Lorem Ipsum has been the industry's standard dummy\n\
|
industry. Lorem Ipsum has been the industry's standard dummy\n\
|
||||||
Contrary to popular belief, Lorem Ipsum is not simply random text."
|
Contrary to popular belief, Lorem Ipsum is not simply random text.",
|
||||||
));
|
));
|
||||||
let mut r = Readlines::new(req);
|
let mut r = Readlines::new(req);
|
||||||
match r.poll().ok().unwrap() {
|
match r.poll().ok().unwrap() {
|
||||||
Async::Ready(Some(s)) => assert_eq!(s,
|
Async::Ready(Some(s)) => assert_eq!(
|
||||||
"Lorem Ipsum is simply dummy text of the printing and typesetting\n"),
|
s,
|
||||||
|
"Lorem Ipsum is simply dummy text of the printing and typesetting\n"
|
||||||
|
),
|
||||||
_ => unreachable!("error"),
|
_ => unreachable!("error"),
|
||||||
}
|
}
|
||||||
match r.poll().ok().unwrap() {
|
match r.poll().ok().unwrap() {
|
||||||
Async::Ready(Some(s)) => assert_eq!(s,
|
Async::Ready(Some(s)) => assert_eq!(
|
||||||
"industry. Lorem Ipsum has been the industry's standard dummy\n"),
|
s,
|
||||||
|
"industry. Lorem Ipsum has been the industry's standard dummy\n"
|
||||||
|
),
|
||||||
_ => unreachable!("error"),
|
_ => unreachable!("error"),
|
||||||
}
|
}
|
||||||
match r.poll().ok().unwrap() {
|
match r.poll().ok().unwrap() {
|
||||||
Async::Ready(Some(s)) => assert_eq!(s,
|
Async::Ready(Some(s)) => assert_eq!(
|
||||||
"Contrary to popular belief, Lorem Ipsum is not simply random text."),
|
s,
|
||||||
|
"Contrary to popular belief, Lorem Ipsum is not simply random text."
|
||||||
|
),
|
||||||
_ => unreachable!("error"),
|
_ => unreachable!("error"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -615,54 +615,51 @@ impl<H: IntoHttpHandler> Handler<signal::Signal> for HttpServer<H> {
|
||||||
/// Commands from accept threads
|
/// Commands from accept threads
|
||||||
impl<H: IntoHttpHandler> StreamHandler<ServerCommand, ()> for HttpServer<H> {
|
impl<H: IntoHttpHandler> StreamHandler<ServerCommand, ()> for HttpServer<H> {
|
||||||
fn handle(&mut self, msg: Result<Option<ServerCommand>, ()>, _: &mut Context<Self>) {
|
fn handle(&mut self, msg: Result<Option<ServerCommand>, ()>, _: &mut Context<Self>) {
|
||||||
match msg {
|
if let Ok(Some(ServerCommand::WorkerDied(idx, socks))) = msg {
|
||||||
Ok(Some(ServerCommand::WorkerDied(idx, socks))) => {
|
let mut found = false;
|
||||||
let mut found = false;
|
for i in 0..self.workers.len() {
|
||||||
for i in 0..self.workers.len() {
|
if self.workers[i].0 == idx {
|
||||||
if self.workers[i].0 == idx {
|
self.workers.swap_remove(i);
|
||||||
self.workers.swap_remove(i);
|
found = true;
|
||||||
found = true;
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if found {
|
|
||||||
error!("Worker has died {:?}, restarting", idx);
|
|
||||||
let (tx, rx) = mpsc::unbounded::<Conn<net::TcpStream>>();
|
|
||||||
|
|
||||||
let mut new_idx = self.workers.len();
|
|
||||||
'found: loop {
|
|
||||||
for i in 0..self.workers.len() {
|
|
||||||
if self.workers[i].0 == new_idx {
|
|
||||||
new_idx += 1;
|
|
||||||
continue 'found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
let ka = self.keep_alive;
|
|
||||||
let factory = Arc::clone(&self.factory);
|
|
||||||
let settings =
|
|
||||||
ServerSettings::new(Some(socks[0].addr), &self.host, false);
|
|
||||||
|
|
||||||
let addr = Arbiter::start(move |ctx: &mut Context<_>| {
|
|
||||||
let apps: Vec<_> = (*factory)()
|
|
||||||
.into_iter()
|
|
||||||
.map(|h| h.into_handler(settings.clone()))
|
|
||||||
.collect();
|
|
||||||
ctx.add_message_stream(rx);
|
|
||||||
Worker::new(apps, socks, ka)
|
|
||||||
});
|
|
||||||
for item in &self.accept {
|
|
||||||
let _ = item.1.send(Command::Worker(new_idx, tx.clone()));
|
|
||||||
let _ = item.0.set_readiness(mio::Ready::readable());
|
|
||||||
}
|
|
||||||
|
|
||||||
self.workers.push((new_idx, addr));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
|
if found {
|
||||||
|
error!("Worker has died {:?}, restarting", idx);
|
||||||
|
let (tx, rx) = mpsc::unbounded::<Conn<net::TcpStream>>();
|
||||||
|
|
||||||
|
let mut new_idx = self.workers.len();
|
||||||
|
'found: loop {
|
||||||
|
for i in 0..self.workers.len() {
|
||||||
|
if self.workers[i].0 == new_idx {
|
||||||
|
new_idx += 1;
|
||||||
|
continue 'found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let ka = self.keep_alive;
|
||||||
|
let factory = Arc::clone(&self.factory);
|
||||||
|
let settings =
|
||||||
|
ServerSettings::new(Some(socks[0].addr), &self.host, false);
|
||||||
|
|
||||||
|
let addr = Arbiter::start(move |ctx: &mut Context<_>| {
|
||||||
|
let apps: Vec<_> = (*factory)()
|
||||||
|
.into_iter()
|
||||||
|
.map(|h| h.into_handler(settings.clone()))
|
||||||
|
.collect();
|
||||||
|
ctx.add_message_stream(rx);
|
||||||
|
Worker::new(apps, socks, ka)
|
||||||
|
});
|
||||||
|
for item in &self.accept {
|
||||||
|
let _ = item.1.send(Command::Worker(new_idx, tx.clone()));
|
||||||
|
let _ = item.0.set_readiness(mio::Ready::readable());
|
||||||
|
}
|
||||||
|
|
||||||
|
self.workers.push((new_idx, addr));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue