Compare commits

...

8 Commits

Author SHA1 Message Date
ngrondin ab38164ca9
Merge 9320df6339 into b6ad483699 2025-07-14 23:40:54 -07:00
dependabot[bot] b6ad483699
build(deps): bump tokio from 1.45.1 to 1.46.1 (#3689)
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.45.1 to 1.46.1.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.45.1...tokio-1.46.1)

---
updated-dependencies:
- dependency-name: tokio
  dependency-version: 1.46.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-14 01:52:41 +00:00
dependabot[bot] c002fd783c
build(deps): bump taiki-e/install-action from 2.54.3 to 2.56.13 (#3693)
Bumps [taiki-e/install-action](https://github.com/taiki-e/install-action) from 2.54.3 to 2.56.13.
- [Release notes](https://github.com/taiki-e/install-action/releases)
- [Changelog](https://github.com/taiki-e/install-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/taiki-e/install-action/compare/v2.54.3...v2.56.13)

---
updated-dependencies:
- dependency-name: taiki-e/install-action
  dependency-version: 2.56.13
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-14 01:16:19 +00:00
Thomas de Zeeuw 95ad1caa23
Update socket2 to v0.6 (#3688) 2025-07-14 01:13:01 +00:00
dependabot[bot] eb906d077a
build(deps): bump trybuild from 1.0.105 to 1.0.106 (#3692)
Bumps [trybuild](https://github.com/dtolnay/trybuild) from 1.0.105 to 1.0.106.
- [Release notes](https://github.com/dtolnay/trybuild/releases)
- [Commits](https://github.com/dtolnay/trybuild/compare/1.0.105...1.0.106)

---
updated-dependencies:
- dependency-name: trybuild
  dependency-version: 1.0.106
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-14 01:01:17 +00:00
dependabot[bot] f08fa6b684
build(deps): bump h2 from 0.3.26 to 0.3.27 (#3691)
Bumps [h2](https://github.com/hyperium/h2) from 0.3.26 to 0.3.27.
- [Release notes](https://github.com/hyperium/h2/releases)
- [Changelog](https://github.com/hyperium/h2/blob/v0.3.27/CHANGELOG.md)
- [Commits](https://github.com/hyperium/h2/compare/v0.3.26...v0.3.27)

---
updated-dependencies:
- dependency-name: h2
  dependency-version: 0.3.27
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-14 00:50:00 +00:00
Nicolas 9320df6339 Fix formatting 2025-06-01 18:37:55 +10:00
Nicolas ee7e37c62f Added max_buffer_size as a configuration item on the httpservice 2025-06-01 15:48:21 +10:00
12 changed files with 127 additions and 53 deletions

View File

@ -49,7 +49,7 @@ jobs:
toolchain: ${{ matrix.version.version }}
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
uses: taiki-e/install-action@v2.54.3
uses: taiki-e/install-action@v2.56.13
with:
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
@ -83,7 +83,7 @@ jobs:
uses: actions-rust-lang/setup-rust-toolchain@v1.13.0
- name: Install just, cargo-hack
uses: taiki-e/install-action@v2.54.3
uses: taiki-e/install-action@v2.56.13
with:
tool: just,cargo-hack

View File

@ -64,7 +64,7 @@ jobs:
toolchain: ${{ matrix.version.version }}
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
uses: taiki-e/install-action@v2.54.3
uses: taiki-e/install-action@v2.56.13
with:
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
@ -113,7 +113,7 @@ jobs:
toolchain: nightly
- name: Install just
uses: taiki-e/install-action@v2.54.3
uses: taiki-e/install-action@v2.56.13
with:
tool: just

View File

@ -24,7 +24,7 @@ jobs:
components: llvm-tools
- name: Install just, cargo-llvm-cov, cargo-nextest
uses: taiki-e/install-action@v2.54.3
uses: taiki-e/install-action@v2.56.13
with:
tool: just,cargo-llvm-cov,cargo-nextest

View File

@ -77,7 +77,7 @@ jobs:
toolchain: ${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
- name: Install just
uses: taiki-e/install-action@v2.54.3
uses: taiki-e/install-action@v2.56.13
with:
tool: just

100
Cargo.lock generated
View File

@ -147,7 +147,7 @@ dependencies = [
"serde_json",
"serde_urlencoded",
"slab",
"socket2 0.5.10",
"socket2 0.6.0",
"tokio",
]
@ -393,7 +393,7 @@ dependencies = [
"serde_json",
"serde_urlencoded",
"smallvec",
"socket2 0.5.10",
"socket2 0.6.0",
"static_assertions",
"time",
"tokio",
@ -1509,9 +1509,9 @@ checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
[[package]]
name = "h2"
version = "0.3.26"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8"
checksum = "0beca50380b1fc32983fc1cb4587bfa4bb9e78fc259aad4a0032d2080309222d"
dependencies = [
"bytes",
"fnv",
@ -1785,6 +1785,17 @@ dependencies = [
"libc",
]
[[package]]
name = "io-uring"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013"
dependencies = [
"bitflags 2.9.1",
"cfg-if",
"libc",
]
[[package]]
name = "ipconfig"
version = "0.3.2"
@ -2794,9 +2805,9 @@ dependencies = [
[[package]]
name = "serde_spanned"
version = "0.6.8"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1"
checksum = "40734c41988f7306bb04f0ecf60ec0f3f1caa34290e4e8ea471dcd3346483b83"
dependencies = [
"serde",
]
@ -2882,6 +2893,16 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "socket2"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807"
dependencies = [
"libc",
"windows-sys 0.59.0",
]
[[package]]
name = "spin"
version = "0.5.2"
@ -3066,17 +3087,19 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.45.1"
version = "1.46.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779"
checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17"
dependencies = [
"backtrace",
"bytes",
"io-uring 0.7.8",
"libc",
"mio",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"slab",
"socket2 0.5.10",
"tokio-macros",
"windows-sys 0.52.0",
@ -3165,7 +3188,7 @@ checksum = "748482e3e13584a34664a710168ad5068e8cb1d968aa4ffa887e83ca6dd27967"
dependencies = [
"bytes",
"futures-util",
"io-uring",
"io-uring 0.6.4",
"libc",
"slab",
"socket2 0.4.10",
@ -3187,44 +3210,42 @@ dependencies = [
[[package]]
name = "toml"
version = "0.8.22"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05ae329d1f08c4d17a59bed7ff5b5a769d062e64a62d34a3261b219e62cd5aae"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e"
checksum = "ed0aee96c12fa71097902e0bb061a5e1ebd766a6636bb605ba401c45c1650eac"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"toml_write",
"toml_parser",
"toml_writer",
"winnow",
]
[[package]]
name = "toml_write"
version = "0.1.1"
name = "toml_datetime"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfb942dfe1d8e29a7ee7fcbde5bd2b9a25fb89aa70caea2eba3bee836ff41076"
checksum = "bade1c3e902f58d73d3f294cd7f20391c1cb2fbcb643b73566bc773971df91e3"
dependencies = [
"serde",
]
[[package]]
name = "toml_parser"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97200572db069e74c512a14117b296ba0a80a30123fbbb5aa1f4a348f639ca30"
dependencies = [
"winnow",
]
[[package]]
name = "toml_writer"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcc842091f2def52017664b53082ecbbeb5c7731092bad69d2c63050401dfd64"
[[package]]
name = "tracing"
@ -3306,9 +3327,9 @@ dependencies = [
[[package]]
name = "trybuild"
version = "1.0.105"
version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c9bf9513a2f4aeef5fdac8677d7d349c79fdbcc03b9c86da6e9d254f1e43be2"
checksum = "65af40ad689f2527aebbd37a0a816aea88ff5f774ceabe99de5be02f2f91dae2"
dependencies = [
"glob",
"serde",
@ -3759,9 +3780,6 @@ name = "winnow"
version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec"
dependencies = [
"memchr",
]
[[package]]
name = "winreg"

View File

@ -53,7 +53,7 @@ serde = "1"
serde_json = "1"
serde_urlencoded = "0.7"
slab = "0.4"
socket2 = "0.5"
socket2 = "0.6"
tls-openssl = { version = "0.10.55", package = "openssl", optional = true }
tokio = { version = "1.38.2", features = ["sync"] }

View File

@ -17,6 +17,7 @@ pub struct HttpServiceBuilder<T, S, X = ExpectHandler, U = UpgradeHandler> {
keep_alive: KeepAlive,
client_request_timeout: Duration,
client_disconnect_timeout: Duration,
max_buffer_size: Option<usize>,
secure: bool,
local_addr: Option<net::SocketAddr>,
expect: X,
@ -38,6 +39,7 @@ where
keep_alive: KeepAlive::default(),
client_request_timeout: Duration::from_secs(5),
client_disconnect_timeout: Duration::ZERO,
max_buffer_size: None,
secure: false,
local_addr: None,
@ -124,6 +126,15 @@ where
self.client_disconnect_timeout(dur)
}
/// Set maximum buffer size.
///
/// Defines the maximum size of the buffer. When the size is reached, the dispatcher
/// will flush the data to the IO streams
pub fn max_buffer_size(mut self, size: usize) -> Self {
self.max_buffer_size = Some(size);
self
}
/// Provide service for `EXPECT: 100-Continue` support.
///
/// Service get called with request that contains `EXPECT` header.
@ -140,6 +151,7 @@ where
keep_alive: self.keep_alive,
client_request_timeout: self.client_request_timeout,
client_disconnect_timeout: self.client_disconnect_timeout,
max_buffer_size: self.max_buffer_size,
secure: self.secure,
local_addr: self.local_addr,
expect: expect.into_factory(),
@ -164,6 +176,7 @@ where
keep_alive: self.keep_alive,
client_request_timeout: self.client_request_timeout,
client_disconnect_timeout: self.client_disconnect_timeout,
max_buffer_size: self.max_buffer_size,
secure: self.secure,
local_addr: self.local_addr,
expect: self.expect,
@ -199,6 +212,7 @@ where
self.keep_alive,
self.client_request_timeout,
self.client_disconnect_timeout,
self.max_buffer_size,
self.secure,
self.local_addr,
);
@ -224,6 +238,7 @@ where
self.keep_alive,
self.client_request_timeout,
self.client_disconnect_timeout,
self.max_buffer_size,
self.secure,
self.local_addr,
);
@ -246,6 +261,7 @@ where
self.keep_alive,
self.client_request_timeout,
self.client_disconnect_timeout,
self.max_buffer_size,
self.secure,
self.local_addr,
);

View File

@ -17,6 +17,7 @@ struct Inner {
keep_alive: KeepAlive,
client_request_timeout: Duration,
client_disconnect_timeout: Duration,
max_buffer_size: Option<usize>,
secure: bool,
local_addr: Option<std::net::SocketAddr>,
date_service: DateService,
@ -28,6 +29,7 @@ impl Default for ServiceConfig {
KeepAlive::default(),
Duration::from_secs(5),
Duration::ZERO,
None,
false,
None,
)
@ -40,6 +42,7 @@ impl ServiceConfig {
keep_alive: KeepAlive,
client_request_timeout: Duration,
client_disconnect_timeout: Duration,
max_buffer_size: Option<usize>,
secure: bool,
local_addr: Option<net::SocketAddr>,
) -> ServiceConfig {
@ -47,6 +50,7 @@ impl ServiceConfig {
keep_alive: keep_alive.normalize(),
client_request_timeout,
client_disconnect_timeout,
max_buffer_size,
secure,
local_addr,
date_service: DateService::new(),
@ -104,6 +108,10 @@ impl ServiceConfig {
self.0.date_service.now()
}
pub fn max_buffer_size(&self) -> Option<usize> {
self.0.max_buffer_size
}
/// Writes date header to `dst` buffer.
///
/// Low-level method that utilizes the built-in efficient date service, requiring fewer syscalls
@ -143,8 +151,14 @@ mod tests {
#[actix_rt::test]
async fn test_date_service_update() {
let settings =
ServiceConfig::new(KeepAlive::Os, Duration::ZERO, Duration::ZERO, false, None);
let settings = ServiceConfig::new(
KeepAlive::Os,
Duration::ZERO,
Duration::ZERO,
None,
false,
None,
);
yield_now().await;

View File

@ -166,6 +166,7 @@ pin_project! {
pub(super) io: Option<T>,
read_buf: BytesMut,
write_buf: BytesMut,
max_buffer_size: usize,
codec: Codec,
}
}
@ -278,6 +279,7 @@ where
io: Some(io),
read_buf: BytesMut::with_capacity(HW_BUFFER_SIZE),
write_buf: BytesMut::with_capacity(HW_BUFFER_SIZE),
max_buffer_size: config.max_buffer_size().unwrap_or(MAX_BUFFER_SIZE),
codec: Codec::new(config),
},
},
@ -493,7 +495,7 @@ where
StateProj::SendPayload { mut body } => {
// keep populate writer buffer until buffer size limit hit,
// get blocked or finished.
while this.write_buf.len() < super::payload::MAX_BUFFER_SIZE {
while this.write_buf.len() < *this.max_buffer_size {
match body.as_mut().poll_next(cx) {
Poll::Ready(Some(Ok(item))) => {
this.codec
@ -532,7 +534,7 @@ where
// keep populate writer buffer until buffer size limit hit,
// get blocked or finished.
while this.write_buf.len() < super::payload::MAX_BUFFER_SIZE {
while this.write_buf.len() < *this.max_buffer_size {
match body.as_mut().poll_next(cx) {
Poll::Ready(Some(Ok(item))) => {
this.codec

View File

@ -82,6 +82,7 @@ async fn late_request() {
KeepAlive::Disabled,
Duration::from_millis(100),
Duration::ZERO,
None,
false,
None,
);
@ -149,6 +150,7 @@ async fn oneshot_connection() {
KeepAlive::Disabled,
Duration::from_millis(100),
Duration::ZERO,
None,
false,
None,
);
@ -210,6 +212,7 @@ async fn keep_alive_timeout() {
KeepAlive::Timeout(Duration::from_millis(200)),
Duration::from_millis(100),
Duration::ZERO,
None,
false,
None,
);
@ -289,6 +292,7 @@ async fn keep_alive_follow_up_req() {
KeepAlive::Timeout(Duration::from_millis(500)),
Duration::from_millis(100),
Duration::ZERO,
None,
false,
None,
);
@ -453,6 +457,7 @@ async fn pipelining_ok_then_ok() {
KeepAlive::Disabled,
Duration::from_millis(1),
Duration::from_millis(1),
None,
false,
None,
);
@ -523,6 +528,7 @@ async fn pipelining_ok_then_bad() {
KeepAlive::Disabled,
Duration::from_millis(1),
Duration::from_millis(1),
None,
false,
None,
);
@ -586,6 +592,7 @@ async fn expect_handling() {
KeepAlive::Disabled,
Duration::ZERO,
Duration::ZERO,
None,
false,
None,
);
@ -663,6 +670,7 @@ async fn expect_eager() {
KeepAlive::Disabled,
Duration::ZERO,
Duration::ZERO,
None,
false,
None,
);
@ -746,6 +754,7 @@ async fn upgrade_handling() {
KeepAlive::Disabled,
Duration::ZERO,
Duration::ZERO,
None,
false,
None,
);

View File

@ -158,7 +158,7 @@ serde = "1.0"
serde_json = "1.0"
serde_urlencoded = "0.7"
smallvec = "1.6.1"
socket2 = "0.5"
socket2 = "0.6"
time = { version = "0.3", default-features = false, features = ["formatting"] }
tracing = "0.1.30"
url = "2.5.4"

View File

@ -31,6 +31,7 @@ struct Config {
keep_alive: KeepAlive,
client_request_timeout: Duration,
client_disconnect_timeout: Duration,
max_buffer_size: Option<usize>,
#[allow(dead_code)] // only dead when no TLS features are enabled
tls_handshake_timeout: Option<Duration>,
}
@ -116,6 +117,7 @@ where
keep_alive: KeepAlive::default(),
client_request_timeout: Duration::from_secs(5),
client_disconnect_timeout: Duration::from_secs(1),
max_buffer_size: None,
tls_handshake_timeout: None,
})),
backlog: 1024,
@ -234,6 +236,15 @@ where
self
}
/// Set maximum buffer size.
///
/// Defines the maximum size of the write buffer. When the size is reached, the dispatcher
/// will flush the data to the IO streams
pub fn max_buffer_size(self, size: usize) -> Self {
self.config.lock().unwrap().max_buffer_size = Some(size);
self
}
/// Sets TLS handshake timeout.
///
/// Defines a timeout for TLS handshake. If the TLS handshake does not complete within this
@ -560,6 +571,10 @@ where
.client_disconnect_timeout(cfg.client_disconnect_timeout)
.local_addr(addr);
if let Some(size) = cfg.max_buffer_size {
svc = svc.max_buffer_size(size);
};
if let Some(handler) = on_connect_fn.clone() {
svc =
svc.on_connect_ext(move |io: &_, ext: _| (handler)(io as &dyn Any, ext))