Skip to content

Commit

Permalink
Merge patch (#4)
Browse files Browse the repository at this point in the history
* Add a setter for header_table_size

* Include a test for setting header_table_size

* Fix formatting

* Switch pseudo header order to mimic chrome

* support chrome/okhttp impersonate

* deps(http): bump version to v0.2.11

* feat(header): support safari header pseudo order

* Send frames based on custom configuration

* Revert "deps(http): bump version to v0.2.11"

* deps(http): bump version to v0.2.11

* bump version to v0.4.2

* fix: streams awaiting capacity lockout (#730) (#734)

This PR changes the the assign-capacity queue to prioritize streams that
are send-ready.

This is necessary to prevent a lockout when streams aren't able to proceed while
waiting for connection capacity, but there is none.

Closes hyperium/hyper#3338

Co-authored-by: dswij <dharmasw@outlook.com>

* streams: limit error resets for misbehaving connections

This change causes GOAWAYs to be issued to misbehaving connections which for one reason or another cause us to emit lots of error resets.

Error resets are not generally expected from valid implementations anyways.

The threshold after which we issue GOAWAYs is tunable, and will default to 1024.

* Prepare v0.3.24

* perf: optimize header list size calculations (#750)

This speeds up loading blocks in cases where we have many headers already.

* deps(http): v0.2

* Fix header order

* Optimize pseudo-header sort

* Setting static headers

* feat(frame): Passing values ​​to solve pseudo order

* Add headers priority

* Fix default flag

* Project rename to `h2-patch`
---------

Co-authored-by: 4JX <79868816+4JX@users.noreply.github.com>
Co-authored-by: Sean McArthur <sean@seanmonstar.com>
Co-authored-by: dswij <dharmasw@outlook.com>
Co-authored-by: Noah Kennedy <nkennedy@cloudflare.com>
  • Loading branch information
5 people authored Aug 11, 2024
1 parent 36cf4f2 commit 64eaf51
Show file tree
Hide file tree
Showing 31 changed files with 342 additions and 210 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
strategy:
matrix:
rust:
- nightly
- beta
- stable
steps:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
* Update to `http` 1.0.
* Remove deprecated `Server::poll_close()`.

# 0.3.24 (January 17, 2024)

* Limit error resets for misbehaving connections.

# 0.3.23 (January 10, 2024)

* Backport fix from 0.4.1 for stream capacity assignment.

# 0.3.22 (November 15, 2023)

* Add `header_table_size(usize)` option to client and server builders.
Expand Down
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "h2"
name = "h2-patch"
# When releasing to crates.io:
# - Update CHANGELOG.md.
# - Create git tag
version = "0.4.5"
version = "0.5.7"
license = "MIT"
authors = [
"Carl Lerche <me@carllerche.com>",
Expand Down Expand Up @@ -45,8 +45,8 @@ futures-sink = { version = "0.3", default-features = false }
tokio-util = { version = "0.7.1", features = ["codec", "io"] }
tokio = { version = "1", features = ["io-util"] }
bytes = "1"
http = "1"
tracing = { version = "0.1.35", default-features = false, features = ["std"] }
http = "0.2"
tracing = { version = "0.1.32", default-features = false, features = ["std"] }
fnv = "1.0.5"
slab = "0.4.2"
indexmap = { version = "2", features = ["std"] }
Expand All @@ -66,6 +66,7 @@ serde_json = "1.0.0"
# Examples
tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync", "net"] }
env_logger = { version = "0.10", default-features = false }

tokio-rustls = "0.26"
webpki-roots = "0.26"

Expand Down
1 change: 1 addition & 0 deletions benches/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use h2_patch as h2;
use bytes::Bytes;
use h2::{
client,
Expand Down
1 change: 1 addition & 0 deletions examples/akamai.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use h2::client;
use h2_patch as h2;
use http::{Method, Request};
use tokio::net::TcpStream;
use tokio_rustls::TlsConnector;
Expand Down
1 change: 1 addition & 0 deletions examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use h2::client;
use h2_patch as h2;
use http::{HeaderMap, Request};

use std::error::Error;
Expand Down
1 change: 1 addition & 0 deletions examples/server.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use h2_patch as h2;
use std::error::Error;

use bytes::Bytes;
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tokio = { version = "1", features = [ "full" ] }
h2 = { path = "../", features = [ "unstable" ] }
h2-support = { path = "../tests/h2-support" }
futures = { version = "0.3", default-features = false, features = ["std"] }
http = "1"
http = "0.2"

# Prevent this from interfering with workspaces
[workspace]
Expand Down
26 changes: 23 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
use crate::codec::{Codec, SendError, UserError};
use crate::ext::Protocol;
use crate::frame::{Headers, Pseudo, Reason, Settings, StreamId};
use crate::profile::AgentProfile;
use crate::proto::{self, Error};
use crate::{FlowControl, PingPong, RecvStream, SendStream};

Expand Down Expand Up @@ -175,6 +176,7 @@ use tracing::Instrument;
pub struct SendRequest<B: Buf> {
inner: proto::Streams<B, Peer>,
pending: Option<proto::OpaqueStreamRef>,
profile: AgentProfile,
}

/// Returns a `SendRequest` instance once it is ready to send at least one
Expand Down Expand Up @@ -343,6 +345,9 @@ pub struct Builder {
///
/// When this gets exceeded, we issue GOAWAYs.
local_max_error_reset_streams: Option<usize>,

/// Profile Settings
_profile: AgentProfile,
}

#[derive(Debug)]
Expand Down Expand Up @@ -515,7 +520,12 @@ where
end_of_stream: bool,
) -> Result<(ResponseFuture, SendStream<B>), crate::Error> {
self.inner
.send_request(request, end_of_stream, self.pending.as_ref())
.send_request(
request,
end_of_stream,
self.pending.as_ref(),
self.profile.clone(),
)
.map_err(Into::into)
.map(|(stream, is_full)| {
if stream.is_pending_open() && is_full {
Expand Down Expand Up @@ -576,6 +586,7 @@ where
SendRequest {
inner: self.inner.clone(),
pending: None,
profile: self.profile.clone(),
}
}
}
Expand Down Expand Up @@ -663,9 +674,16 @@ impl Builder {
settings: Default::default(),
stream_id: 1.into(),
local_max_error_reset_streams: Some(proto::DEFAULT_LOCAL_RESET_COUNT_MAX),
_profile: AgentProfile::default(),
}
}

/// Use the profile to configure the client.
pub fn profile(&mut self, profile: AgentProfile) -> &mut Self {
self._profile = profile;
self
}

/// Indicates the initial window size (in octets) for stream-level
/// flow control for received data.
///
Expand Down Expand Up @@ -1321,7 +1339,7 @@ where

// Send initial settings frame
codec
.buffer(builder.settings.clone().into())
.buffer((builder.settings.clone(), builder._profile.clone()).into())
.expect("invalid SETTINGS frame");

let inner = proto::Connection::new(
Expand All @@ -1340,6 +1358,7 @@ where
let send_request = SendRequest {
inner: inner.streams().clone(),
pending: None,
profile: builder._profile,
};

let mut connection = Connection { inner };
Expand Down Expand Up @@ -1584,6 +1603,7 @@ impl Peer {
request: Request<()>,
protocol: Option<Protocol>,
end_of_stream: bool,
profile: AgentProfile,
) -> Result<Headers, SendError> {
use http::request::Parts;

Expand All @@ -1602,7 +1622,7 @@ impl Peer {

// Build the set pseudo header set. All requests will include `method`
// and `path`.
let mut pseudo = Pseudo::request(method, uri, protocol);
let mut pseudo = Pseudo::request(method, uri, protocol, profile);

if pseudo.scheme.is_none() {
// If the scheme is not set, then there are a two options.
Expand Down
4 changes: 2 additions & 2 deletions src/codec/framed_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ where
self.next = Some(Next::Continuation(continuation));
}
}
Frame::Settings(v) => {
v.encode(self.buf.get_mut());
Frame::Settings(v, _profile) => {
v.encode(self.buf.get_mut(), _profile);
tracing::trace!(rem = self.buf.remaining(), "encoded settings");
}
Frame::GoAway(v) => {
Expand Down
Loading

0 comments on commit 64eaf51

Please sign in to comment.