Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hyperium/hyper
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.14.24
Choose a base ref
...
head repository: hyperium/hyper
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.14.25
Choose a head ref
  • 11 commits
  • 20 files changed
  • 5 contributors

Commits on Feb 20, 2023

  1. feat(client): add poison to Connected (#3145)

    Add `poison` method to `Connected`. This allows callers to mark a connection as poisoned which prevents the pool from reusing it on subsequent requests. `is_open` will consider poisoning prior to returning a connection to the pool.
    rcoh authored Feb 20, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    37ed5a2 View commit details

Commits on Feb 22, 2023

  1. feat(client): add client::connect::capture_connection() (#3144)

    Add `capture_connection` functionality. This allows callers to retrieve the `Connected` struct of the connection that was used internally by Hyper. This is in service of #2605.
    
    Although this uses `http::Extensions` under the hood, the API exposed explicitly hides that detail.
    rcoh authored Feb 22, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    c849339 View commit details

Commits on Mar 6, 2023

  1. feat(client): add 1.0 compatible client conn API (#3155)

    This patch backports client/conn/http1 and http2 modules from 1.0 to
    ease transition. It allows code still using 0.14.x to switch to the
    per-version Connection types available in 1.0.
    
    Closes #3053 
    
    Co-authored-by: KOVACS Tamas <ktamas@fastmail.fm>
    seanmonstar and kxt authored Mar 6, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    253cc74 View commit details

Commits on Mar 7, 2023

  1. feat(client): deprecate client::conn types (#3156)

    `client::conn::{SendRequest, Connection, Builder, handshake}` are deprecated as they are removed in 1.0.
    
    This adds the `deprecated` feature to Cargo, and only when `hyper/deprecated` is enabled will these warnings be emitted.
    
    Co-authored-by: KOVACS Tamas <ktamas@fastmail.fm>
    seanmonstar and kxt authored Mar 7, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    0ced15d View commit details
  2. Copy the full SHA
    0368a41 View commit details

Commits on Mar 8, 2023

  1. Copy the full SHA
    84881c9 View commit details

Commits on Mar 9, 2023

  1. Copy the full SHA
    02fe20f View commit details
  2. Copy the full SHA
    86bc750 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    fc111eb View commit details

Commits on Mar 10, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    645db19 View commit details
  2. v0.14.25

    seanmonstar committed Mar 10, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    a9d4e83 View commit details
35 changes: 32 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ jobs:
- msrv
- miri
- features
- deprecated
- ffi
- ffi-header
- doc
@@ -62,11 +63,11 @@ jobs:

include:
- rust: stable
features: "--features full"
features: "--features full,backports,deprecated"
- rust: beta
features: "--features full"
features: "--features full,backports"
- rust: nightly
features: "--features full,nightly"
features: "--features full,nightly,backports"
benches: true

runs-on: ${{ matrix.os }}
@@ -167,6 +168,34 @@ jobs:
- name: check --feature-powerset
run: cargo hack check --feature-powerset --depth 2 --skip ffi -Z avoid-dev-deps

deprecated:
name: Check deprecated on ${{ matrix.rust }}
needs: [style]
strategy:
matrix:
rust:
- stable
- beta

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1

- name: Install Rust (${{ matrix.rust }})
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true

- name: Check
uses: actions-rs/cargo@v1
with:
command: check
args: --features full,backports,deprecated

ffi:
name: Test C API (FFI)
needs: [style]
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
### v0.14.25 (2023-03-10)


#### Features

* **client:**
* deprecate `client::conn` types (#3156) ([0ced15d3](https://github.com/hyperium/hyper/commit/0ced15d3cc10ace477ebda13ead8e6857b51867e))
* add 1.0 compatible client conn API (#3155) ([253cc74d](https://github.com/hyperium/hyper/commit/253cc74d86b082067aa884a0a63a089d7d19401d), closes [#3053](https://github.com/hyperium/hyper/issues/3053))
* add `client::connect::capture_connection()` (#3144) ([c8493399](https://github.com/hyperium/hyper/commit/c8493399b2929a86f3020ae77304a00e43cfd161))
* add `poison` to `Connected` (#3145) ([37ed5a2e](https://github.com/hyperium/hyper/commit/37ed5a2e3cab76a11092823a80afd8fe2f2a9693))
* **server:**
* deprecate server conn structs (#3161) ([02fe20f2](https://github.com/hyperium/hyper/commit/02fe20f232a7c3cf24d505b121ce4d428a93254d))
* backport the split server conn modules from 1.0 (#3102) ([84881c9e](https://github.com/hyperium/hyper/commit/84881c9e5160167a89d18d30c0ef6856dc859839), closes [#3079](https://github.com/hyperium/hyper/issues/3079))
* remove some `Unpin` and `'static` constraints (#3119) ([0368a41a](https://github.com/hyperium/hyper/commit/0368a41a6cc1a5c6f1eada0d88e38b7dce261587))


### v0.14.24 (2023-02-02)


8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hyper"
version = "0.14.24"
version = "0.14.25"
description = "A fast and correct HTTP library."
readme = "README.md"
homepage = "https://hyper.rs"
@@ -109,6 +109,12 @@ tcp = [
# C-API support (currently unstable (no semver))
ffi = ["libc"]

# enable 1.0 backports
backports = []

# whether or not to display deprecation warnings
deprecated = []

# internal features used in CI
nightly = []
__internal_happy_eyeballs_tests = []
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ libraries and applications.

If you are looking for a convenient HTTP client, then you may wish to consider
[reqwest](https://github.com/seanmonstar/reqwest). If you are looking for a
convenient HTTP server, then you may wish to consider [warp](https://github.com/seanmonstar/warp).
convenient HTTP server, then you may wish to consider [Axum](https://github.com/tokio-rs/tokio).
Both are built on top of this library.

## Contributing
48 changes: 40 additions & 8 deletions examples/tower_client.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#![deny(warnings)]

use hyper::client::conn::Builder;
use hyper::client::connect::HttpConnector;
use hyper::client::service::Connect;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

use hyper::service::Service;
use hyper::{Body, Request};
use hyper::{Body, Request, Response};
use tokio::net::TcpStream;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
pretty_env_logger::init();

let mut mk_svc = Connect::new(HttpConnector::new(), Builder::new());

let uri = "http://127.0.0.1:8080".parse::<http::Uri>()?;

let mut svc = mk_svc.call(uri.clone()).await?;
let mut svc = Connector;

let body = Body::empty();

@@ -25,3 +25,35 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

Ok(())
}

struct Connector;

impl Service<Request<Body>> for Connector {
type Response = Response<Body>;
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;

fn poll_ready(&mut self, _cx: &mut Context<'_>) -> std::task::Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn call(&mut self, req: Request<Body>) -> Self::Future {
Box::pin(async move {
let host = req.uri().host().expect("no host in uri");
let port = req.uri().port_u16().expect("no port in uri");

let stream = TcpStream::connect(format!("{}:{}", host, port)).await?;

let (mut sender, conn) = hyper::client::conn::http1::handshake(stream).await?;

tokio::task::spawn(async move {
if let Err(err) = conn.await {
println!("Connection error: {:?}", err);
}
});

let res = sender.send_request(req).await?;
Ok(res)
})
}
}
28 changes: 24 additions & 4 deletions src/client/client.rs
Original file line number Diff line number Diff line change
@@ -10,16 +10,21 @@ use http::uri::{Port, Scheme};
use http::{Method, Request, Response, Uri, Version};
use tracing::{debug, trace, warn};

use crate::body::{Body, HttpBody};
use crate::client::connect::CaptureConnectionExtension;
use crate::common::{
exec::BoxSendFuture, lazy as hyper_lazy, sync_wrapper::SyncWrapper, task, Future, Lazy, Pin,
Poll,
};
use crate::rt::Executor;

use super::conn;
use super::connect::{self, sealed::Connect, Alpn, Connected, Connection};
use super::pool::{
self, CheckoutIsClosedError, Key as PoolKey, Pool, Poolable, Pooled, Reservation,
};
#[cfg(feature = "tcp")]
use super::HttpConnector;
use crate::body::{Body, HttpBody};
use crate::common::{exec::BoxSendFuture, sync_wrapper::SyncWrapper, lazy as hyper_lazy, task, Future, Lazy, Pin, Poll};
use crate::rt::Executor;

/// A Client to make outgoing HTTP requests.
///
@@ -28,6 +33,7 @@ use crate::rt::Executor;
#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
pub struct Client<C, B = Body> {
config: Config,
#[cfg_attr(feature = "deprecated", allow(deprecated))]
conn_builder: conn::Builder,
connector: C,
pool: Pool<PoolClient<B>>,
@@ -238,7 +244,9 @@ where
})
}
};

req.extensions_mut()
.get_mut::<CaptureConnectionExtension>()
.map(|conn| conn.set(&pooled.conn_info));
if pooled.is_http1() {
if req.version() == Version::HTTP_2 {
warn!("Connection is HTTP/1, but request requires HTTP/2");
@@ -320,12 +328,14 @@ where
drop(delayed_tx);
});

#[cfg_attr(feature = "deprecated", allow(deprecated))]
self.conn_builder.exec.execute(on_idle);
} else {
// There's no body to delay, but the connection isn't
// ready yet. Only re-insert when it's ready
let on_idle = future::poll_fn(move |cx| pooled.poll_ready(cx)).map(|_| ());

#[cfg_attr(feature = "deprecated", allow(deprecated))]
self.conn_builder.exec.execute(on_idle);
}

@@ -379,6 +389,7 @@ where
});
// An execute error here isn't important, we're just trying
// to prevent a waste of a socket...
#[cfg_attr(feature = "deprecated", allow(deprecated))]
self.conn_builder.exec.execute(bg);
}
Ok(checked_out)
@@ -423,6 +434,7 @@ where
&self,
pool_key: PoolKey,
) -> impl Lazy<Output = crate::Result<Pooled<PoolClient<B>>>> + Unpin {
#[cfg_attr(feature = "deprecated", allow(deprecated))]
let executor = self.conn_builder.exec.clone();
let pool = self.pool.clone();
#[cfg(not(feature = "http2"))]
@@ -622,6 +634,7 @@ struct PoolClient<B> {
}

enum PoolTx<B> {
#[cfg_attr(feature = "deprecated", allow(deprecated))]
Http1(conn::SendRequest<B>),
#[cfg(feature = "http2")]
Http2(conn::Http2SendRequest<B>),
@@ -689,6 +702,10 @@ where
B: Send + 'static,
{
fn is_open(&self) -> bool {
if self.conn_info.poisoned.poisoned() {
trace!("marking {:?} as closed because it was poisoned", self.conn_info);
return false;
}
match self.tx {
PoolTx::Http1(ref tx) => tx.is_ready(),
#[cfg(feature = "http2")]
@@ -894,6 +911,7 @@ fn is_schema_secure(uri: &Uri) -> bool {
#[derive(Clone)]
pub struct Builder {
client_config: Config,
#[cfg_attr(feature = "deprecated", allow(deprecated))]
conn_builder: conn::Builder,
pool_config: pool::Config,
}
@@ -906,6 +924,7 @@ impl Default for Builder {
set_host: true,
ver: Ver::Auto,
},
#[cfg_attr(feature = "deprecated", allow(deprecated))]
conn_builder: conn::Builder::new(),
pool_config: pool::Config {
idle_timeout: Some(Duration::from_secs(90)),
@@ -1370,6 +1389,7 @@ impl Builder {
B: HttpBody + Send,
B::Data: Send,
{
#[cfg_attr(feature = "deprecated", allow(deprecated))]
Client {
config: self.client_config,
conn_builder: self.conn_builder.clone(),
Loading