mirror of
https://github.com/actix/actix-extras.git
synced 2025-06-26 02:19:22 +02:00
rustfmt 0.7
This commit is contained in:
@ -8,8 +8,10 @@ use std::{fmt, io, mem, time};
|
||||
use actix::actors::{Connect as ResolveConnect, Connector, ConnectorError};
|
||||
use actix::fut::WrapFuture;
|
||||
use actix::registry::ArbiterService;
|
||||
use actix::{fut, Actor, ActorFuture, ActorResponse, Arbiter, AsyncContext, Context,
|
||||
ContextFutureSpawner, Handler, Message, Recipient, Supervised, Syn};
|
||||
use actix::{
|
||||
fut, Actor, ActorFuture, ActorResponse, Arbiter, AsyncContext, Context,
|
||||
ContextFutureSpawner, Handler, Message, Recipient, Supervised, Syn,
|
||||
};
|
||||
|
||||
use futures::task::{current as current_task, Task};
|
||||
use futures::unsync::oneshot;
|
||||
@ -429,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) {
|
||||
@ -441,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);
|
||||
}
|
||||
@ -518,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());
|
||||
@ -1107,10 +1105,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()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1118,10 +1113,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()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,10 @@ mod request;
|
||||
mod response;
|
||||
mod writer;
|
||||
|
||||
pub use self::connector::{ClientConnector, ClientConnectorError, ClientConnectorStats,
|
||||
Connect, Connection, Pause, Resume};
|
||||
pub use self::connector::{
|
||||
ClientConnector, ClientConnectorError, ClientConnectorStats, Connect, Connection,
|
||||
Pause, Resume,
|
||||
};
|
||||
pub(crate) use self::parser::{HttpResponseParser, HttpResponseParserError};
|
||||
pub use self::pipeline::{SendRequest, SendRequestError};
|
||||
pub use self::request::{ClientRequest, ClientRequestBuilder};
|
||||
|
@ -270,7 +270,8 @@ impl Pipeline {
|
||||
#[inline]
|
||||
fn parse(&mut self) -> Poll<ClientResponse, HttpResponseParserError> {
|
||||
if let Some(ref mut conn) = self.conn {
|
||||
match self.parser
|
||||
match self
|
||||
.parser
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.parse(conn, &mut self.parser_buf)
|
||||
@ -311,7 +312,8 @@ impl Pipeline {
|
||||
let mut need_run = false;
|
||||
|
||||
// need write?
|
||||
match self.poll_write()
|
||||
match self
|
||||
.poll_write()
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("{}", e)))?
|
||||
{
|
||||
Async::NotReady => need_run = true,
|
||||
@ -325,7 +327,8 @@ impl Pipeline {
|
||||
// need read?
|
||||
if self.parser.is_some() {
|
||||
loop {
|
||||
match self.parser
|
||||
match self
|
||||
.parser
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.parse_payload(conn, &mut self.parser_buf)?
|
||||
@ -469,7 +472,8 @@ impl Pipeline {
|
||||
}
|
||||
|
||||
// flush io but only if we need to
|
||||
match self.writer
|
||||
match self
|
||||
.writer
|
||||
.poll_completed(self.conn.as_mut().unwrap(), false)
|
||||
{
|
||||
Ok(Async::Ready(_)) => {
|
||||
|
@ -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
|
||||
}
|
||||
@ -610,9 +607,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 +652,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`
|
||||
|
@ -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"));
|
||||
|
@ -12,8 +12,9 @@ use flate2::write::{DeflateEncoder, GzEncoder};
|
||||
#[cfg(feature = "flate2")]
|
||||
use flate2::Compression;
|
||||
use futures::{Async, Poll};
|
||||
use http::header::{HeaderValue, CONNECTION, CONTENT_ENCODING, CONTENT_LENGTH, DATE,
|
||||
TRANSFER_ENCODING};
|
||||
use http::header::{
|
||||
HeaderValue, CONNECTION, CONTENT_ENCODING, CONTENT_LENGTH, DATE, TRANSFER_ENCODING,
|
||||
};
|
||||
use http::{HttpTryFrom, Version};
|
||||
use time::{self, Duration};
|
||||
use tokio_io::AsyncWrite;
|
||||
@ -253,10 +254,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(_) => {
|
||||
|
Reference in New Issue
Block a user