style(lib): address most clippy lints
This commit is contained in:
committed by
Sean McArthur
parent
0f13719873
commit
0eaf304644
@@ -292,7 +292,7 @@ impl Opts {
|
||||
} else {
|
||||
self.request_body
|
||||
.map(Body::from)
|
||||
.unwrap_or_else(|| Body::empty())
|
||||
.unwrap_or_else(Body::empty)
|
||||
};
|
||||
let mut req = Request::new(body);
|
||||
*req.method_mut() = self.request_method.clone();
|
||||
@@ -355,5 +355,5 @@ fn spawn_server(rt: &mut tokio::runtime::Runtime, opts: &Opts) -> SocketAddr {
|
||||
panic!("server error: {}", err);
|
||||
}
|
||||
});
|
||||
return addr;
|
||||
addr
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ fn throughput_fixedsize_large_payload(b: &mut test::Bencher) {
|
||||
#[bench]
|
||||
fn throughput_fixedsize_many_chunks(b: &mut test::Bencher) {
|
||||
bench_server!(b, ("content-length", "1000000"), || {
|
||||
static S: &'static [&'static [u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
|
||||
static S: &[&[u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
|
||||
Body::wrap_stream(stream::iter(S.iter()).map(|&s| Ok::<_, String>(s)))
|
||||
})
|
||||
}
|
||||
@@ -127,7 +127,7 @@ fn throughput_chunked_large_payload(b: &mut test::Bencher) {
|
||||
#[bench]
|
||||
fn throughput_chunked_many_chunks(b: &mut test::Bencher) {
|
||||
bench_server!(b, ("transfer-encoding", "chunked"), || {
|
||||
static S: &'static [&'static [u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
|
||||
static S: &[&[u8]] = &[&[b'x'; 1_000] as &[u8]; 1_000] as _;
|
||||
Body::wrap_stream(stream::iter(S.iter()).map(|&s| Ok::<_, String>(s)))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ use futures_util::future::join;
|
||||
use hyper::service::{make_service_fn, service_fn};
|
||||
use hyper::{Body, Request, Response, Server};
|
||||
|
||||
static INDEX1: &'static [u8] = b"The 1st service!";
|
||||
static INDEX2: &'static [u8] = b"The 2nd service!";
|
||||
static INDEX1: &[u8] = b"The 1st service!";
|
||||
static INDEX2: &[u8] = b"The 2nd service!";
|
||||
|
||||
async fn index1(_: Request<Body>) -> Result<Response<Body>, hyper::Error> {
|
||||
Ok(Response::new(Body::from(INDEX1)))
|
||||
|
||||
@@ -71,5 +71,5 @@ async fn simple_file_send(filename: &str) -> Result<Response<Body>> {
|
||||
return Ok(internal_server_error());
|
||||
}
|
||||
|
||||
return Ok(not_found());
|
||||
Ok(not_found())
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use futures_util::future;
|
||||
use hyper::service::Service;
|
||||
use hyper::{Body, Request, Response, Server};
|
||||
|
||||
const ROOT: &'static str = "/";
|
||||
const ROOT: &str = "/";
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Svc;
|
||||
|
||||
@@ -112,10 +112,7 @@ impl Body {
|
||||
let (tx, rx) = mpsc::channel(0);
|
||||
let (abort_tx, abort_rx) = oneshot::channel();
|
||||
|
||||
let tx = Sender {
|
||||
abort_tx: abort_tx,
|
||||
tx: tx,
|
||||
};
|
||||
let tx = Sender { abort_tx, tx };
|
||||
let rx = Body::new(Kind::Chan {
|
||||
content_length,
|
||||
abort_rx,
|
||||
@@ -131,7 +128,6 @@ impl Body {
|
||||
///
|
||||
/// ```
|
||||
/// # use hyper::Body;
|
||||
/// # fn main() {
|
||||
/// let chunks: Vec<Result<_, ::std::io::Error>> = vec
|
||||
/// to work with this function; or use the `without_shutdown` wrapper.
|
||||
pub fn poll_without_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
|
||||
match self.inner.as_mut().expect("already upgraded") {
|
||||
&mut ProtoClient::H1(ref mut h1) => h1.poll_without_shutdown(cx),
|
||||
&mut ProtoClient::H2(ref mut h2) => Pin::new(h2).poll(cx).map_ok(|_| ()),
|
||||
match *self.inner.as_mut().expect("already upgraded") {
|
||||
ProtoClient::H1(ref mut h1) => h1.poll_without_shutdown(cx),
|
||||
ProtoClient::H2(ref mut h2) => Pin::new(h2).poll(cx).map_ok(|_| ()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -542,7 +542,7 @@ impl ConnectingTcpRemote {
|
||||
}
|
||||
}
|
||||
|
||||
return Err(err.take().expect("missing connect error"));
|
||||
Err(err.take().expect("missing connect error"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -552,9 +552,9 @@ fn connect(
|
||||
reuse_address: bool,
|
||||
connect_timeout: Option<Duration>,
|
||||
) -> io::Result<impl Future<Output = io::Result<TcpStream>>> {
|
||||
let builder = match addr {
|
||||
&SocketAddr::V4(_) => TcpBuilder::new_v4()?,
|
||||
&SocketAddr::V6(_) => TcpBuilder::new_v6()?,
|
||||
let builder = match *addr {
|
||||
SocketAddr::V4(_) => TcpBuilder::new_v4()?,
|
||||
SocketAddr::V6(_) => TcpBuilder::new_v6()?,
|
||||
};
|
||||
|
||||
if reuse_address {
|
||||
@@ -566,9 +566,9 @@ fn connect(
|
||||
builder.bind(SocketAddr::new(local_addr.clone(), 0))?;
|
||||
} else if cfg!(windows) {
|
||||
// Windows requires a socket be bound before calling connect
|
||||
let any: SocketAddr = match addr {
|
||||
&SocketAddr::V4(_) => ([0, 0, 0, 0], 0).into(),
|
||||
&SocketAddr::V6(_) => ([0, 0, 0, 0, 0, 0, 0, 0], 0).into(),
|
||||
let any: SocketAddr = match *addr {
|
||||
SocketAddr::V4(_) => ([0, 0, 0, 0], 0).into(),
|
||||
SocketAddr::V6(_) => ([0, 0, 0, 0, 0, 0, 0, 0], 0).into(),
|
||||
};
|
||||
builder.bind(any)?;
|
||||
}
|
||||
@@ -619,7 +619,7 @@ impl ConnectingTcp {
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(_) = result {
|
||||
if result.is_err() {
|
||||
// Fallback to the remaining future (could be preferred or fallback)
|
||||
// if we get an error
|
||||
future.await
|
||||
|
||||
@@ -12,13 +12,10 @@ pub fn channel<T, U>() -> (Sender<T, U>, Receiver<T, U>) {
|
||||
let (giver, taker) = want::new();
|
||||
let tx = Sender {
|
||||
buffered_once: false,
|
||||
giver: giver,
|
||||
giver,
|
||||
inner: tx,
|
||||
};
|
||||
let rx = Receiver {
|
||||
inner: rx,
|
||||
taker: taker,
|
||||
};
|
||||
let rx = Receiver { inner: rx, taker };
|
||||
(tx, rx)
|
||||
}
|
||||
|
||||
@@ -183,7 +180,7 @@ struct Envelope<T, U>(Option<(T, Callback<T, U>)>);
|
||||
impl<T, U> Drop for Envelope<T, U> {
|
||||
fn drop(&mut self) {
|
||||
if let Some((val, cb)) = self.0.take() {
|
||||
let _ = cb.send(Err((
|
||||
cb.send(Err((
|
||||
crate::Error::new_canceled().with("connection closed"),
|
||||
Some(val),
|
||||
)));
|
||||
|
||||
@@ -210,7 +210,7 @@ where
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
pub fn request(&self, mut req: Request<B>) -> ResponseFuture {
|
||||
let is_http_connect = req.method() == &Method::CONNECT;
|
||||
let is_http_connect = req.method() == Method::CONNECT;
|
||||
match req.version() {
|
||||
Version::HTTP_11 => (),
|
||||
Version::HTTP_10 => {
|
||||
@@ -237,7 +237,7 @@ where
|
||||
}
|
||||
};
|
||||
|
||||
let pool_key = Arc::new(domain.to_string());
|
||||
let pool_key = Arc::new(domain);
|
||||
ResponseFuture::new(Box::new(self.retryably_send_request(req, pool_key)))
|
||||
}
|
||||
|
||||
@@ -302,14 +302,14 @@ where
|
||||
}
|
||||
|
||||
// CONNECT always sends authority-form, so check it first...
|
||||
if req.method() == &Method::CONNECT {
|
||||
if req.method() == Method::CONNECT {
|
||||
authority_form(req.uri_mut());
|
||||
} else if pooled.conn_info.is_proxied {
|
||||
absolute_form(req.uri_mut());
|
||||
} else {
|
||||
origin_form(req.uri_mut());
|
||||
};
|
||||
} else if req.method() == &Method::CONNECT {
|
||||
} else if req.method() == Method::CONNECT {
|
||||
debug!("client does not support CONNECT requests over HTTP2");
|
||||
return Either::Left(future::err(ClientError::Normal(
|
||||
crate::Error::new_user_unsupported_request_method(),
|
||||
@@ -422,7 +422,7 @@ where
|
||||
});
|
||||
// An execute error here isn't important, we're just trying
|
||||
// to prevent a waste of a socket...
|
||||
let _ = executor.execute(bg);
|
||||
executor.execute(bg);
|
||||
}
|
||||
Either::Left(future::ok(checked_out))
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ impl<T: Poolable> PoolInner<T> {
|
||||
Some(value) => {
|
||||
// borrow-check scope...
|
||||
{
|
||||
let idle_list = self.idle.entry(key.clone()).or_insert(Vec::new());
|
||||
let idle_list = self.idle.entry(key.clone()).or_insert_with(Vec::new);
|
||||
if self.max_idle_per_host <= idle_list.len() {
|
||||
trace!("max idle per host for {:?}, dropping connection", key);
|
||||
return;
|
||||
@@ -360,7 +360,7 @@ impl<T: Poolable> PoolInner<T> {
|
||||
|
||||
debug!("pooling idle connection for {:?}", key);
|
||||
idle_list.push(Idle {
|
||||
value: value,
|
||||
value,
|
||||
idle_at: Instant::now(),
|
||||
});
|
||||
}
|
||||
@@ -610,7 +610,7 @@ impl<T: Poolable> Checkout<T> {
|
||||
inner
|
||||
.waiters
|
||||
.entry(self.key.clone())
|
||||
.or_insert(VecDeque::new())
|
||||
.or_insert_with(VecDeque::new)
|
||||
.push_back(tx);
|
||||
|
||||
// register the waker with this oneshot
|
||||
|
||||
@@ -34,10 +34,7 @@ impl<T: Buf> Buf for BufList<T> {
|
||||
|
||||
#[inline]
|
||||
fn bytes(&self) -> &[u8] {
|
||||
for buf in &self.bufs {
|
||||
return buf.bytes();
|
||||
}
|
||||
&[]
|
||||
self.bufs.front().map(Buf::bytes).unwrap_or_default()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -58,11 +58,11 @@ where
|
||||
) -> Poll<io::Result<usize>> {
|
||||
if let Some(mut prefix) = self.pre.take() {
|
||||
// If there are no remaining bytes, let the bytes get dropped.
|
||||
if prefix.len() > 0 {
|
||||
if !prefix.is_empty() {
|
||||
let copy_len = cmp::min(prefix.len(), buf.len());
|
||||
prefix.copy_to_slice(&mut buf[..copy_len]);
|
||||
// Put back whats left
|
||||
if prefix.len() > 0 {
|
||||
if !prefix.is_empty() {
|
||||
self.pre = Some(prefix);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,9 +49,8 @@ where
|
||||
type Output = R::Output;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
|
||||
match self.inner {
|
||||
Inner::Fut(ref mut f) => return Pin::new(f).poll(cx),
|
||||
_ => (),
|
||||
if let Inner::Fut(ref mut f) = self.inner {
|
||||
return Pin::new(f).poll(cx);
|
||||
}
|
||||
|
||||
match mem::replace(&mut self.inner, Inner::Empty) {
|
||||
|
||||
@@ -96,7 +96,7 @@ pub fn is_chunked_(value: &HeaderValue) -> bool {
|
||||
}
|
||||
|
||||
pub fn add_chunked(mut entry: OccupiedEntry<'_, HeaderValue>) {
|
||||
const CHUNKED: &'static str = "chunked";
|
||||
const CHUNKED: &str = "chunked";
|
||||
|
||||
if let Some(line) = entry.iter_mut().next_back() {
|
||||
// + 2 for ", "
|
||||
|
||||
@@ -13,7 +13,7 @@ use crate::common::{task, Pin, Poll, Unpin};
|
||||
use crate::headers::connection_keep_alive;
|
||||
use crate::proto::{BodyLength, DecodedLength, MessageHead};
|
||||
|
||||
const H2_PREFACE: &'static [u8] = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
|
||||
const H2_PREFACE: &[u8] = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
|
||||
|
||||
/// This handles a connection, which will have been established over an
|
||||
/// `AsyncRead + AsyncWrite` (like a socket), and will likely include multiple
|
||||
@@ -391,9 +391,8 @@ where
|
||||
|
||||
pub fn can_write_head(&self) -> bool {
|
||||
if !T::should_read_first() {
|
||||
match self.state.reading {
|
||||
Reading::Closed => return false,
|
||||
_ => {}
|
||||
if let Reading::Closed = self.state.reading {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
match self.state.writing {
|
||||
@@ -486,7 +485,7 @@ where
|
||||
let outgoing_is_keep_alive = head
|
||||
.headers
|
||||
.get(CONNECTION)
|
||||
.and_then(|value| Some(connection_keep_alive(value)))
|
||||
.map(connection_keep_alive)
|
||||
.unwrap_or(false);
|
||||
|
||||
if !outgoing_is_keep_alive {
|
||||
@@ -510,21 +509,17 @@ where
|
||||
// If we know the remote speaks an older version, we try to fix up any messages
|
||||
// to work with our older peer.
|
||||
fn enforce_version(&mut self, head: &mut MessageHead<T::Outgoing>) {
|
||||
match self.state.version {
|
||||
Version::HTTP_10 => {
|
||||
if let Version::HTTP_10 = self.state.version {
|
||||
// Fixes response or connection when keep-alive header is not present
|
||||
self.fix_keep_alive(head);
|
||||
// If the remote only knows HTTP/1.0, we should force ourselves
|
||||
// to do only speak HTTP/1.0 as well.
|
||||
head.version = Version::HTTP_10;
|
||||
}
|
||||
_ => {
|
||||
// If the remote speaks HTTP/1.1, then it *should* be fine with
|
||||
// both HTTP/1.0 and HTTP/1.1 from us. So again, we just let
|
||||
// the user's headers be.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_body(&mut self, chunk: B) {
|
||||
debug_assert!(self.can_write_body() && self.can_buffer_body());
|
||||
@@ -603,8 +598,7 @@ where
|
||||
// - Client: there is nothing we can do
|
||||
// - Server: if Response hasn't been written yet, we can send a 4xx response
|
||||
fn on_parse_error(&mut self, err: crate::Error) -> crate::Result<()> {
|
||||
match self.state.writing {
|
||||
Writing::Init => {
|
||||
if let Writing::Init = self.state.writing {
|
||||
if self.has_h2_prefix() {
|
||||
return Err(crate::Error::new_version_h2());
|
||||
}
|
||||
@@ -617,8 +611,6 @@ where
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
// fallback is pass the error back up
|
||||
Err(err)
|
||||
|
||||
@@ -62,8 +62,8 @@ where
|
||||
{
|
||||
pub fn new(dispatch: D, conn: Conn<I, Bs::Data, T>) -> Self {
|
||||
Dispatcher {
|
||||
conn: conn,
|
||||
dispatch: dispatch,
|
||||
conn,
|
||||
dispatch,
|
||||
body_tx: None,
|
||||
body_rx: Box::pin(None),
|
||||
is_closing: false,
|
||||
@@ -443,7 +443,7 @@ where
|
||||
pub fn new(service: S) -> Server<S, B> {
|
||||
Server {
|
||||
in_flight: Box::pin(None),
|
||||
service: service,
|
||||
service,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -580,7 +580,7 @@ where
|
||||
*res.status_mut() = msg.subject;
|
||||
*res.headers_mut() = msg.headers;
|
||||
*res.version_mut() = msg.version;
|
||||
let _ = cb.send(Ok(res));
|
||||
cb.send(Ok(res));
|
||||
Ok(())
|
||||
} else {
|
||||
// Getting here is likely a bug! An error should have happened
|
||||
@@ -591,7 +591,7 @@ where
|
||||
}
|
||||
Err(err) => {
|
||||
if let Some(cb) = self.callback.take() {
|
||||
let _ = cb.send(Err((err, None)));
|
||||
cb.send(Err((err, None)));
|
||||
Ok(())
|
||||
} else if !self.rx_closed {
|
||||
self.rx.close();
|
||||
@@ -599,7 +599,7 @@ where
|
||||
trace!("canceling queued request with connection error: {}", err);
|
||||
// in this case, the message was never even started, so it's safe to tell
|
||||
// the user that the request was completely canceled
|
||||
let _ = cb.send(Err((crate::Error::new_canceled().with(err), Some(req))));
|
||||
cb.send(Err((crate::Error::new_canceled().with(err), Some(req))));
|
||||
Ok(())
|
||||
} else {
|
||||
Err(err)
|
||||
|
||||
@@ -49,7 +49,7 @@ enum BufKind<B> {
|
||||
impl Encoder {
|
||||
fn new(kind: Kind) -> Encoder {
|
||||
Encoder {
|
||||
kind: kind,
|
||||
kind,
|
||||
is_last: false,
|
||||
}
|
||||
}
|
||||
@@ -307,7 +307,7 @@ impl fmt::Write for ChunkSize {
|
||||
fn write_str(&mut self, num: &str) -> fmt::Result {
|
||||
use std::io::Write;
|
||||
(&mut self.bytes[self.len.into()..])
|
||||
.write(num.as_bytes())
|
||||
.write_all(num.as_bytes())
|
||||
.expect("&mut [u8].write() cannot error");
|
||||
self.len += num.len() as u8; // safe because bytes is never bigger than 256
|
||||
Ok(())
|
||||
|
||||
@@ -57,7 +57,7 @@ where
|
||||
pub fn new(io: T) -> Buffered<T, B> {
|
||||
Buffered {
|
||||
flush_pipeline: false,
|
||||
io: io,
|
||||
io,
|
||||
read_blocked: false,
|
||||
read_buf: BytesMut::with_capacity(0),
|
||||
read_buf_strategy: ReadStrategy::default(),
|
||||
@@ -168,13 +168,10 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
match ready!(self.poll_read_from_io(cx)).map_err(crate::Error::new_io)? {
|
||||
0 => {
|
||||
if ready!(self.poll_read_from_io(cx)).map_err(crate::Error::new_io)? == 0 {
|
||||
trace!("parse eof");
|
||||
return Poll::Ready(Err(crate::Error::new_incomplete()));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,9 +213,8 @@ where
|
||||
} else if self.write_buf.remaining() == 0 {
|
||||
Pin::new(&mut self.io).poll_flush(cx)
|
||||
} else {
|
||||
match self.write_buf.strategy {
|
||||
WriteStrategy::Flatten => return self.poll_flush_flattened(cx),
|
||||
_ => (),
|
||||
if let WriteStrategy::Flatten = self.write_buf.strategy {
|
||||
return self.poll_flush_flattened(cx);
|
||||
}
|
||||
loop {
|
||||
let n =
|
||||
@@ -325,13 +321,13 @@ impl ReadStrategy {
|
||||
}
|
||||
|
||||
fn record(&mut self, bytes_read: usize) {
|
||||
match *self {
|
||||
ReadStrategy::Adaptive {
|
||||
if let ReadStrategy::Adaptive {
|
||||
ref mut decrease_now,
|
||||
ref mut next,
|
||||
max,
|
||||
..
|
||||
} => {
|
||||
} = *self
|
||||
{
|
||||
if bytes_read >= *next {
|
||||
*next = cmp::min(incr_power_of_two(*next), max);
|
||||
*decrease_now = false;
|
||||
@@ -353,8 +349,6 @@ impl ReadStrategy {
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,10 +378,7 @@ pub struct Cursor<T> {
|
||||
impl<T: AsRef<[u8]>> Cursor<T> {
|
||||
#[inline]
|
||||
pub(crate) fn new(bytes: T) -> Cursor<T> {
|
||||
Cursor {
|
||||
bytes: bytes,
|
||||
pos: 0,
|
||||
}
|
||||
Cursor { bytes, pos: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,16 +518,17 @@ impl<B: Buf> Buf for WriteBuf<B> {
|
||||
#[inline]
|
||||
fn advance(&mut self, cnt: usize) {
|
||||
let hrem = self.headers.remaining();
|
||||
if hrem == cnt {
|
||||
self.headers.reset();
|
||||
} else if hrem > cnt {
|
||||
self.headers.advance(cnt);
|
||||
} else {
|
||||
|
||||
match hrem.cmp(&cnt) {
|
||||
cmp::Ordering::Equal => self.headers.reset(),
|
||||
cmp::Ordering::Greater => self.headers.advance(cnt),
|
||||
cmp::Ordering::Less => {
|
||||
let qcnt = cnt - hrem;
|
||||
self.headers.reset();
|
||||
self.queue.advance(qcnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn bytes_vectored<'t>(&'t self, dst: &mut [IoSlice<'t>]) -> usize {
|
||||
@@ -558,7 +550,7 @@ impl<'a, B: Buf> WriteBufAuto<'a, B> {
|
||||
WriteBufAuto {
|
||||
bytes_called: Cell::new(false),
|
||||
bytes_vec_called: Cell::new(false),
|
||||
inner: inner,
|
||||
inner,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,11 +472,9 @@ impl Http1Transaction for Server {
|
||||
continue 'headers;
|
||||
}
|
||||
header::CONNECTION => {
|
||||
if !is_last {
|
||||
if headers::connection_close(&value) {
|
||||
if !is_last && headers::connection_close(&value) {
|
||||
is_last = true;
|
||||
}
|
||||
}
|
||||
if !is_name_written {
|
||||
is_name_written = true;
|
||||
extend(dst, b"connection: ");
|
||||
@@ -594,9 +592,8 @@ impl Server {
|
||||
}
|
||||
|
||||
fn can_chunked(method: &Option<Method>, status: StatusCode) -> bool {
|
||||
if method == &Some(Method::HEAD) {
|
||||
false
|
||||
} else if method == &Some(Method::CONNECT) && status.is_success() {
|
||||
if method == &Some(Method::HEAD) || method == &Some(Method::CONNECT) && status.is_success()
|
||||
{
|
||||
false
|
||||
} else {
|
||||
match status {
|
||||
@@ -766,7 +763,7 @@ impl Client {
|
||||
101 => {
|
||||
return Ok(Some((DecodedLength::ZERO, true)));
|
||||
}
|
||||
100..=199 => {
|
||||
100 | 102..=199 => {
|
||||
trace!("ignoring informational response: {}", inc.subject.as_u16());
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
@@ -44,9 +44,10 @@ where
|
||||
let (conn_drop_ref, rx) = mpsc::channel(1);
|
||||
let (cancel_tx, conn_eof) = oneshot::channel();
|
||||
|
||||
let conn_drop_rx = rx.into_future().map(|(item, _rx)| match item {
|
||||
Some(never) => match never {},
|
||||
None => (),
|
||||
let conn_drop_rx = rx.into_future().map(|(item, _rx)| {
|
||||
if let Some(never) = item {
|
||||
match never {}
|
||||
}
|
||||
});
|
||||
|
||||
let conn = conn.map_err(|e| debug!("connection error: {}", e));
|
||||
|
||||
@@ -47,11 +47,9 @@ fn strip_connection_headers(headers: &mut HeaderMap, is_request: bool) {
|
||||
warn!("TE headers not set to \"trailers\" are illegal in HTTP/2 requests");
|
||||
headers.remove(TE);
|
||||
}
|
||||
} else {
|
||||
if headers.remove(TE).is_some() {
|
||||
} else if headers.remove(TE).is_some() {
|
||||
warn!("TE headers illegal in HTTP/2 responses");
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(header) = headers.remove(CONNECTION) {
|
||||
warn!(
|
||||
@@ -94,7 +92,7 @@ where
|
||||
PipeToSendStream {
|
||||
body_tx: tx,
|
||||
data_done: false,
|
||||
stream: stream,
|
||||
stream,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,8 +123,7 @@ where
|
||||
None => return Poll::Ready(Err(crate::Error::new_canceled())),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if let Poll::Ready(reason) = me
|
||||
} else if let Poll::Ready(reason) = me
|
||||
.body_tx
|
||||
.poll_reset(cx)
|
||||
.map_err(crate::Error::new_body_write)?
|
||||
@@ -136,7 +133,6 @@ where
|
||||
reason,
|
||||
))));
|
||||
}
|
||||
}
|
||||
|
||||
match ready!(me.stream.as_mut().poll_data(cx)) {
|
||||
Some(Ok(chunk)) => {
|
||||
@@ -172,7 +168,7 @@ where
|
||||
if let Poll::Ready(reason) = me
|
||||
.body_tx
|
||||
.poll_reset(cx)
|
||||
.map_err(|e| crate::Error::new_body_write(e))?
|
||||
.map_err(crate::Error::new_body_write)?
|
||||
{
|
||||
debug!("stream received RST_STREAM: {:?}", reason);
|
||||
return Poll::Ready(Err(crate::Error::new_body_write(::h2::Error::from(
|
||||
@@ -238,6 +234,8 @@ impl<B: Buf> Buf for SendBuf<B> {
|
||||
|
||||
#[inline]
|
||||
fn advance(&mut self, cnt: usize) {
|
||||
self.0.as_mut().map(|b| b.advance(cnt));
|
||||
if let Some(b) = self.0.as_mut() {
|
||||
b.advance(cnt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,10 +259,8 @@ where
|
||||
Poll::Pending => {
|
||||
// Response is not yet ready, so we want to check if the client has sent a
|
||||
// RST_STREAM frame which would cancel the current request.
|
||||
if let Poll::Ready(reason) = me
|
||||
.reply
|
||||
.poll_reset(cx)
|
||||
.map_err(|e| crate::Error::new_h2(e))?
|
||||
if let Poll::Ready(reason) =
|
||||
me.reply.poll_reset(cx).map_err(crate::Error::new_h2)?
|
||||
{
|
||||
debug!("stream received RST_STREAM: {:?}", reason);
|
||||
return Poll::Ready(Err(crate::Error::new_h2(reason.into())));
|
||||
|
||||
@@ -489,8 +489,8 @@ where
|
||||
ProtoServer::H1(h1) => {
|
||||
let (io, read_buf, dispatch) = h1.into_inner();
|
||||
Some(Parts {
|
||||
io: io,
|
||||
read_buf: read_buf,
|
||||
io,
|
||||
read_buf,
|
||||
service: dispatch.into_service(),
|
||||
_inner: (),
|
||||
})
|
||||
@@ -522,7 +522,7 @@ where
|
||||
ProtoServer::H2(ref mut h2) => return Pin::new(h2).poll(cx).map_ok(|_| ()),
|
||||
};
|
||||
match ready!(polled) {
|
||||
Ok(x) => return Poll::Ready(Ok(x)),
|
||||
Ok(()) => return Poll::Ready(Ok(())),
|
||||
Err(e) => match *e.kind() {
|
||||
Kind::Parse(Parse::VersionH2) if self.fallback.to_h2() => {
|
||||
self.upgrade_h2();
|
||||
|
||||
@@ -35,7 +35,7 @@ impl AddrIncoming {
|
||||
let addr = listener.local_addr().map_err(crate::Error::new_listen)?;
|
||||
Ok(AddrIncoming {
|
||||
listener,
|
||||
addr: addr,
|
||||
addr,
|
||||
sleep_on_errors: true,
|
||||
tcp_keepalive_timeout: None,
|
||||
tcp_nodelay: false,
|
||||
|
||||
@@ -310,7 +310,7 @@ macro_rules! __client_req_header {
|
||||
}
|
||||
}
|
||||
|
||||
static REPLY_OK: &'static str = "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n";
|
||||
static REPLY_OK: &str = "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n";
|
||||
|
||||
test! {
|
||||
name: client_get,
|
||||
@@ -1771,7 +1771,7 @@ mod dispatch_impl {
|
||||
// so the unwrapped responses futures show it still worked.
|
||||
assert_eq!(connects.load(Ordering::SeqCst), 3);
|
||||
|
||||
let res4 = client.get(url.clone());
|
||||
let res4 = client.get(url);
|
||||
rt.block_on(res4).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
@@ -1800,8 +1800,8 @@ mod dispatch_impl {
|
||||
|
||||
fn with_http_and_closes(http: HttpConnector, closes: mpsc::Sender<()>) -> DebugConnector {
|
||||
DebugConnector {
|
||||
http: http,
|
||||
closes: closes,
|
||||
http,
|
||||
closes,
|
||||
connects: Arc::new(AtomicUsize::new(0)),
|
||||
is_proxy: false,
|
||||
alpn_h2: false,
|
||||
@@ -2242,7 +2242,7 @@ mod conn {
|
||||
let tcp = rt.block_on(tcp_connect(&addr)).unwrap();
|
||||
|
||||
let io = DebugStream {
|
||||
tcp: tcp,
|
||||
tcp,
|
||||
shutdown_called: false,
|
||||
};
|
||||
|
||||
@@ -2330,7 +2330,7 @@ mod conn {
|
||||
let tcp = rt.block_on(tcp_connect(&addr)).unwrap();
|
||||
|
||||
let io = DebugStream {
|
||||
tcp: tcp,
|
||||
tcp,
|
||||
shutdown_called: false,
|
||||
};
|
||||
|
||||
|
||||
@@ -1457,7 +1457,7 @@ async fn max_buf_size() {
|
||||
thread::spawn(move || {
|
||||
let mut tcp = connect(&addr);
|
||||
tcp.write_all(b"POST /").expect("write 1");
|
||||
tcp.write_all(&vec![b'a'; MAX]).expect("write 2");
|
||||
tcp.write_all(&[b'a'; MAX]).expect("write 2");
|
||||
let mut buf = [0; 256];
|
||||
tcp.read(&mut buf).expect("read 1");
|
||||
|
||||
@@ -1481,8 +1481,8 @@ fn streaming_body() {
|
||||
// disable keep-alive so we can use read_to_end
|
||||
let server = serve_opts().keep_alive(false).serve();
|
||||
|
||||
static S: &'static [&'static [u8]] = &[&[b'x'; 1_000] as &[u8]; 1_00] as _;
|
||||
let b = ::futures_util::stream::iter(S.into_iter()).map(|&s| Ok::<_, hyper::Error>(s));
|
||||
static S: &[&[u8]] = &[&[b'x'; 1_000] as &[u8]; 1_00] as _;
|
||||
let b = futures_util::stream::iter(S.iter()).map(|&s| Ok::<_, hyper::Error>(s));
|
||||
let b = hyper::Body::wrap_stream(b);
|
||||
server.reply().body_stream(b);
|
||||
|
||||
@@ -1588,7 +1588,7 @@ fn http2_body_user_error_sends_reset_reason() {
|
||||
let server = serve();
|
||||
let addr_str = format!("http://{}", server.addr());
|
||||
|
||||
let b = ::futures_util::stream::once(future::err::<String, _>(h2::Error::from(
|
||||
let b = futures_util::stream::once(future::err::<String, _>(h2::Error::from(
|
||||
h2::Reason::INADEQUATE_SECURITY,
|
||||
)));
|
||||
let b = hyper::Body::wrap_stream(b);
|
||||
@@ -1931,7 +1931,7 @@ impl TestService {
|
||||
}
|
||||
}
|
||||
|
||||
const HELLO: &'static str = "hello";
|
||||
const HELLO: &str = "hello";
|
||||
|
||||
struct HelloWorld;
|
||||
|
||||
@@ -2030,8 +2030,8 @@ impl ServeOptions {
|
||||
let msg_tx = msg_tx.clone();
|
||||
let reply_rx = reply_rx.clone();
|
||||
future::ok::<_, BoxError>(TestService {
|
||||
tx: msg_tx.clone(),
|
||||
reply: reply_rx.clone(),
|
||||
tx: msg_tx,
|
||||
reply: reply_rx,
|
||||
})
|
||||
});
|
||||
|
||||
@@ -2056,9 +2056,9 @@ impl ServeOptions {
|
||||
let addr = addr_rx.recv().expect("server addr rx");
|
||||
|
||||
Serve {
|
||||
msg_rx: msg_rx,
|
||||
msg_rx,
|
||||
reply_tx: Mutex::new(reply_tx),
|
||||
addr: addr,
|
||||
addr,
|
||||
shutdown_signal: Some(shutdown_tx),
|
||||
thread: Some(thread),
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ async fn async_test(cfg: __TestConfig) {
|
||||
let mut addr = server.local_addr();
|
||||
|
||||
tokio::task::spawn(server.map(|result| {
|
||||
let _ = result.expect("server error");
|
||||
result.expect("server error");
|
||||
}));
|
||||
|
||||
if cfg.proxy {
|
||||
@@ -460,7 +460,7 @@ fn naive_proxy(cfg: ProxyConfig) -> (SocketAddr, impl Future<Output = ()>) {
|
||||
|
||||
let srv = Server::bind(&([127, 0, 0, 1], 0).into()).serve(make_service_fn(move |_| {
|
||||
let prev = counter.fetch_add(1, Ordering::Relaxed);
|
||||
assert!(max_connections >= prev + 1, "proxy max connections");
|
||||
assert!(max_connections > prev, "proxy max connections");
|
||||
let client = client.clone();
|
||||
future::ok::<_, hyper::Error>(service_fn(move |mut req| {
|
||||
let uri = format!("http://{}{}", dst_addr, req.uri().path())
|
||||
|
||||
Reference in New Issue
Block a user