mirror of
https://github.com/fafhrd91/actix-web
synced 2025-09-02 01:31:57 +02:00
clippy warnings; fmt
This commit is contained in:
@@ -94,13 +94,17 @@ pub struct Pause {
|
||||
impl Pause {
|
||||
/// Create message with pause duration parameter
|
||||
pub fn new(time: Duration) -> Pause {
|
||||
Pause { time: Some(time) }
|
||||
Pause {
|
||||
time: Some(time),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Pause {
|
||||
fn default() -> Pause {
|
||||
Pause { time: None }
|
||||
Pause {
|
||||
time: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,8 +431,7 @@ impl ClientConnector {
|
||||
} else {
|
||||
0
|
||||
};
|
||||
self.acquired_per_host
|
||||
.insert(key.clone(), per_host + 1);
|
||||
self.acquired_per_host.insert(key.clone(), per_host + 1);
|
||||
}
|
||||
|
||||
fn release_key(&mut self, key: &Key) {
|
||||
@@ -439,8 +442,7 @@ impl ClientConnector {
|
||||
return;
|
||||
};
|
||||
if per_host > 1 {
|
||||
self.acquired_per_host
|
||||
.insert(key.clone(), per_host - 1);
|
||||
self.acquired_per_host.insert(key.clone(), per_host - 1);
|
||||
} else {
|
||||
self.acquired_per_host.remove(key);
|
||||
}
|
||||
@@ -516,9 +518,7 @@ impl ClientConnector {
|
||||
fn collect_periodic(&mut self, ctx: &mut Context<Self>) {
|
||||
self.collect(true);
|
||||
// re-schedule next collect period
|
||||
ctx.run_later(Duration::from_secs(1), |act, ctx| {
|
||||
act.collect_periodic(ctx)
|
||||
});
|
||||
ctx.run_later(Duration::from_secs(1), |act, ctx| act.collect_periodic(ctx));
|
||||
|
||||
// send stats
|
||||
let stats = mem::replace(&mut self.stats, ClientConnectorStats::default());
|
||||
@@ -570,7 +570,7 @@ impl ClientConnector {
|
||||
}
|
||||
|
||||
fn wait_for(
|
||||
&mut self, key: Key, wait: Duration, conn_timeout: Duration
|
||||
&mut self, key: Key, wait: Duration, conn_timeout: Duration,
|
||||
) -> oneshot::Receiver<Result<Connection, ClientConnectorError>> {
|
||||
// connection is not available, wait
|
||||
let (tx, rx) = oneshot::channel();
|
||||
@@ -583,10 +583,7 @@ impl ClientConnector {
|
||||
wait,
|
||||
conn_timeout,
|
||||
};
|
||||
self.waiters
|
||||
.entry(key)
|
||||
.or_insert_with(VecDeque::new)
|
||||
.push_back(waiter);
|
||||
self.waiters.entry(key).or_insert_with(VecDeque::new).push_back(waiter);
|
||||
rx
|
||||
}
|
||||
}
|
||||
@@ -810,7 +807,7 @@ impl fut::ActorFuture for Maintenance {
|
||||
type Actor = ClientConnector;
|
||||
|
||||
fn poll(
|
||||
&mut self, act: &mut ClientConnector, ctx: &mut Context<ClientConnector>
|
||||
&mut self, act: &mut ClientConnector, ctx: &mut Context<ClientConnector>,
|
||||
) -> Poll<Self::Item, Self::Error> {
|
||||
// check pause duration
|
||||
let done = if let Some(Some(ref pause)) = act.paused {
|
||||
@@ -1105,10 +1102,7 @@ impl Pool {
|
||||
if self.to_close.borrow().is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(mem::replace(
|
||||
&mut *self.to_close.borrow_mut(),
|
||||
Vec::new(),
|
||||
))
|
||||
Some(mem::replace(&mut *self.to_close.borrow_mut(), Vec::new()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1116,10 +1110,7 @@ impl Pool {
|
||||
if self.to_release.borrow().is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(mem::replace(
|
||||
&mut *self.to_release.borrow_mut(),
|
||||
Vec::new(),
|
||||
))
|
||||
Some(mem::replace(&mut *self.to_release.borrow_mut(), Vec::new()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -18,9 +18,9 @@ use error::Error;
|
||||
use error::PayloadError;
|
||||
use header::ContentEncoding;
|
||||
use httpmessage::HttpMessage;
|
||||
use server::WriterState;
|
||||
use server::encoding::PayloadStream;
|
||||
use server::shared::SharedBytes;
|
||||
use server::WriterState;
|
||||
|
||||
/// A set of errors that can occur during request sending and response reading
|
||||
#[derive(Fail, Debug)]
|
||||
@@ -80,7 +80,7 @@ impl SendRequest {
|
||||
}
|
||||
|
||||
pub(crate) fn with_connector(
|
||||
req: ClientRequest, conn: Addr<Unsync, ClientConnector>
|
||||
req: ClientRequest, conn: Addr<Unsync, ClientConnector>,
|
||||
) -> SendRequest {
|
||||
SendRequest {
|
||||
req,
|
||||
@@ -269,11 +269,7 @@ impl Pipeline {
|
||||
#[inline]
|
||||
fn parse(&mut self) -> Poll<ClientResponse, HttpResponseParserError> {
|
||||
if let Some(ref mut conn) = self.conn {
|
||||
match self.parser
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.parse(conn, &mut self.parser_buf)
|
||||
{
|
||||
match self.parser.as_mut().unwrap().parse(conn, &mut self.parser_buf) {
|
||||
Ok(Async::Ready(resp)) => {
|
||||
// check content-encoding
|
||||
if self.should_decompress {
|
||||
@@ -469,9 +465,7 @@ impl Pipeline {
|
||||
}
|
||||
|
||||
// flush io but only if we need to
|
||||
match self.writer
|
||||
.poll_completed(self.conn.as_mut().unwrap(), false)
|
||||
{
|
||||
match self.writer.poll_completed(self.conn.as_mut().unwrap(), false) {
|
||||
Ok(Async::Ready(_)) => {
|
||||
if self.disconnected
|
||||
|| (self.body_completed && self.writer.is_completed())
|
||||
|
@@ -499,10 +499,7 @@ impl ClientRequestBuilder {
|
||||
jar.add(cookie.into_owned());
|
||||
self.cookies = Some(jar)
|
||||
} else {
|
||||
self.cookies
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.add(cookie.into_owned());
|
||||
self.cookies.as_mut().unwrap().add(cookie.into_owned());
|
||||
}
|
||||
self
|
||||
}
|
||||
@@ -594,11 +591,7 @@ impl ClientRequestBuilder {
|
||||
if self.default_headers {
|
||||
// enable br only for https
|
||||
let https = if let Some(parts) = parts(&mut self.request, &self.err) {
|
||||
parts
|
||||
.uri
|
||||
.scheme_part()
|
||||
.map(|s| s == &uri::Scheme::HTTPS)
|
||||
.unwrap_or(true)
|
||||
parts.uri.scheme_part().map(|s| s == &uri::Scheme::HTTPS).unwrap_or(true)
|
||||
} else {
|
||||
true
|
||||
};
|
||||
@@ -610,9 +603,7 @@ impl ClientRequestBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
let mut request = self.request
|
||||
.take()
|
||||
.expect("cannot reuse request builder");
|
||||
let mut request = self.request.take().expect("cannot reuse request builder");
|
||||
|
||||
// set cookies
|
||||
if let Some(ref mut jar) = self.cookies {
|
||||
@@ -657,9 +648,7 @@ impl ClientRequestBuilder {
|
||||
S: Stream<Item = Bytes, Error = E> + 'static,
|
||||
E: Into<Error>,
|
||||
{
|
||||
self.body(Body::Streaming(Box::new(
|
||||
stream.map_err(|e| e.into()),
|
||||
)))
|
||||
self.body(Body::Streaming(Box::new(stream.map_err(|e| e.into()))))
|
||||
}
|
||||
|
||||
/// Set an empty body and generate `ClientRequest`
|
||||
@@ -682,7 +671,7 @@ impl ClientRequestBuilder {
|
||||
|
||||
#[inline]
|
||||
fn parts<'a>(
|
||||
parts: &'a mut Option<ClientRequest>, err: &Option<HttpError>
|
||||
parts: &'a mut Option<ClientRequest>, err: &Option<HttpError>,
|
||||
) -> Option<&'a mut ClientRequest> {
|
||||
if err.is_some() {
|
||||
return None;
|
||||
|
@@ -103,12 +103,7 @@ impl ClientResponse {
|
||||
|
||||
impl fmt::Debug for ClientResponse {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let res = writeln!(
|
||||
f,
|
||||
"\nClientResponse {:?} {}",
|
||||
self.version(),
|
||||
self.status()
|
||||
);
|
||||
let res = writeln!(f, "\nClientResponse {:?} {}", self.version(), self.status());
|
||||
let _ = writeln!(f, " headers:");
|
||||
for (key, val) in self.headers().iter() {
|
||||
let _ = writeln!(f, " {:?}: {:?}", key, val);
|
||||
@@ -138,14 +133,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_debug() {
|
||||
let resp = ClientResponse::new(ClientMessage::default());
|
||||
resp.as_mut().headers.insert(
|
||||
header::COOKIE,
|
||||
HeaderValue::from_static("cookie1=value1"),
|
||||
);
|
||||
resp.as_mut().headers.insert(
|
||||
header::COOKIE,
|
||||
HeaderValue::from_static("cookie2=value2"),
|
||||
);
|
||||
resp.as_mut()
|
||||
.headers
|
||||
.insert(header::COOKIE, HeaderValue::from_static("cookie1=value1"));
|
||||
resp.as_mut()
|
||||
.headers
|
||||
.insert(header::COOKIE, HeaderValue::from_static("cookie2=value2"));
|
||||
|
||||
let dbg = format!("{:?}", resp);
|
||||
assert!(dbg.contains("ClientResponse"));
|
||||
|
@@ -114,10 +114,7 @@ impl HttpClientWriter {
|
||||
self.buffer,
|
||||
"{} {} {:?}\r",
|
||||
msg.method(),
|
||||
msg.uri()
|
||||
.path_and_query()
|
||||
.map(|u| u.as_str())
|
||||
.unwrap_or("/"),
|
||||
msg.uri().path_and_query().map(|u| u.as_str()).unwrap_or("/"),
|
||||
msg.version()
|
||||
)?;
|
||||
|
||||
@@ -253,10 +250,8 @@ fn content_encoder(buf: SharedBytes, req: &mut ClientRequest) -> ContentEncoder
|
||||
}
|
||||
let mut b = BytesMut::new();
|
||||
let _ = write!(b, "{}", bytes.len());
|
||||
req.headers_mut().insert(
|
||||
CONTENT_LENGTH,
|
||||
HeaderValue::try_from(b.freeze()).unwrap(),
|
||||
);
|
||||
req.headers_mut()
|
||||
.insert(CONTENT_LENGTH, HeaderValue::try_from(b.freeze()).unwrap());
|
||||
TransferEncoding::eof(buf)
|
||||
}
|
||||
Body::Streaming(_) | Body::Actor(_) => {
|
||||
@@ -279,10 +274,8 @@ fn content_encoder(buf: SharedBytes, req: &mut ClientRequest) -> ContentEncoder
|
||||
};
|
||||
|
||||
if encoding.is_compression() {
|
||||
req.headers_mut().insert(
|
||||
CONTENT_ENCODING,
|
||||
HeaderValue::from_static(encoding.as_str()),
|
||||
);
|
||||
req.headers_mut()
|
||||
.insert(CONTENT_ENCODING, HeaderValue::from_static(encoding.as_str()));
|
||||
}
|
||||
|
||||
req.replace_body(body);
|
||||
|
Reference in New Issue
Block a user