Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
on:
push:
branches:
- master
pull_request: {}

name: Continuous integration

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check

test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ homepage = "https://github.com/hjr3/hyper-timeout"
repository = "https://github.com/hjr3/hyper-timeout"
readme = "README.md"

[badges]
travis-ci = { repository = "https://github.com/hjr3/hyper-timeout", branch = "master" }

[dependencies]
bytes = "1.0.0"
hyper = { version = "0.14", default-features = false, features = ["client", "http1", "tcp"] }
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[![Build Status](https://travis-ci.org/hjr3/hyper-timeout.svg?branch=master)](https://travis-ci.org/hjr3/hyper-timeout)
[![crates.io](https://img.shields.io/crates/v/hyper-timeout.svg)](https://crates.io/crates/hyper-timeout)

# hyper-timeout
Expand Down
6 changes: 2 additions & 4 deletions examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::env;
use std::time::Duration;

use hyper::{Client, body::HttpBody as _};
use hyper::{body::HttpBody as _, Client};
use tokio::io::{self, AsyncWriteExt as _};

use hyper::client::HttpConnector;
Expand Down Expand Up @@ -38,9 +38,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

while let Some(chunk) = res.body_mut().data().await {
let chunk = chunk?;
io::stdout()
.write_all(&chunk)
.await?
io::stdout().write_all(&chunk).await?
}
Ok(())
}
15 changes: 9 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use tokio::io::{AsyncRead, AsyncWrite};
use tokio::time::{timeout, Duration};
use tokio_io_timeout::TimeoutStream;

use hyper::{service::Service, Uri};
use hyper::client::connect::{Connect, Connected, Connection};
use hyper::{service::Service, Uri};

mod stream;

Expand All @@ -33,7 +33,7 @@ impl<T: Connect> TimeoutConnector<T> {
/// Construct a new TimeoutConnector with a given connector implementing the `Connect` trait
pub fn new(connector: T) -> Self {
TimeoutConnector {
connector: connector,
connector,
connect_timeout: None,
read_timeout: None,
write_timeout: None,
Expand All @@ -50,15 +50,16 @@ where
{
type Response = Pin<Box<TimeoutConnectorStream<T::Response>>>;
type Error = BoxError;
#[allow(clippy::type_complexity)]
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.connector.poll_ready(cx).map_err(Into::into)
}

fn call(&mut self, dst: Uri) -> Self::Future {
let read_timeout = self.read_timeout.clone();
let write_timeout = self.write_timeout.clone();
let read_timeout = self.read_timeout;
let write_timeout = self.write_timeout;
let connecting = self.connector.call(dst);

if self.connect_timeout.is_none() {
Expand All @@ -78,7 +79,9 @@ where
let timeout = timeout(connect_timeout, connecting);

let fut = async move {
let connecting = timeout.await.map_err(|e| io::Error::new(io::ErrorKind::TimedOut, e))?;
let connecting = timeout
.await
.map_err(|e| io::Error::new(io::ErrorKind::TimedOut, e))?;
let io = connecting.map_err(Into::into)?;

let mut tm = TimeoutConnectorStream::new(TimeoutStream::new(io));
Expand Down Expand Up @@ -132,8 +135,8 @@ mod tests {
use std::io;
use std::time::Duration;

use hyper::Client;
use hyper::client::HttpConnector;
use hyper::Client;

use super::TimeoutConnector;

Expand Down
2 changes: 1 addition & 1 deletion src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io;
use std::io::IoSlice;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::{Duration};
use std::time::Duration;

use hyper::client::connect::{Connected, Connection};
use pin_project_lite::pin_project;
Expand Down