Skip to content

Commit ee3ca9f

Browse files
authored
SharedCfg is not Copy (#82)
1 parent b8e1971 commit ee3ca9f

File tree

13 files changed

+60
-52
lines changed

13 files changed

+60
-52
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes
22

3+
## [3.7.0] - 2026-02-16
4+
5+
* SharedCfg is not Copy
6+
37
## [3.6.2] - 2026-02-11
48

59
* Better clippy configuration

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ntex-h2"
3-
version = "3.6.2"
3+
version = "3.7.0"
44
license = "MIT OR Apache-2.0"
55
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
66
description = "An HTTP/2 client and server"
@@ -31,6 +31,7 @@ ntex-io = "3.7"
3131
ntex-net = "3"
3232
ntex-service = "4.4"
3333
ntex-util = "3"
34+
ntex-server = "3.7"
3435

3536
bitflags = "2"
3637
foldhash = "0.2"

src/client/connector.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ where
9090
type Service = ConnectorService<A, T::Service>;
9191

9292
async fn create(&self, cfg: SharedCfg) -> Result<Self::Service, Self::InitError> {
93+
let config = cfg.get();
9394
let svc = self.svc.create(cfg).await?;
9495
Ok(ConnectorService {
9596
svc,
97+
config,
9698
scheme: self.scheme.clone(),
97-
config: cfg.get(),
9899
pool: self.pool.clone(),
99100
_t: PhantomData,
100101
})
@@ -126,7 +127,7 @@ where
126127
let fut = async {
127128
Ok::<_, ClientError>(SimpleClient::with_params(
128129
ctx.call(&self.svc, Connect::new(req)).await?.into(),
129-
self.config,
130+
self.config.clone(),
130131
&self.scheme,
131132
authority,
132133
false,

src/client/pool.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl Client {
174174
// construct client
175175
let client = SimpleClient::with_params(
176176
io,
177-
inner.cfg,
177+
inner.cfg.clone(),
178178
&inner.config.scheme,
179179
inner.config.authority.clone(),
180180
inner.config.skip_unknown_streams,
@@ -433,22 +433,20 @@ where
433433
/// Finish configuration process and create connections pool.
434434
pub async fn build(self, cfg: SharedCfg) -> Result<Client, T::InitError> {
435435
let connect = self.connect;
436+
let tag = cfg.tag();
437+
let client_cfg = cfg.get();
436438
let svc = Pipeline::new(self.connector.create(cfg).await?);
437439

438440
let connector = Box::new(move || {
439-
log::trace!(
440-
"{}: Opening http/2 connection to {}",
441-
cfg.tag(),
442-
connect.host()
443-
);
441+
log::trace!("{tag}: Opening http/2 connection to {}", connect.host());
444442
let fut = svc.call_static(connect.clone());
445443
Box::pin(async move { fut.await.map(IoBoxed::from) }) as Fut
446444
});
447445

448446
Ok(Client {
449447
inner: Rc::new(Inner {
450448
connector,
451-
cfg: cfg.get(),
449+
cfg: client_cfg,
452450
config: self.inner,
453451
}),
454452
waiters: Rc::default(),

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use ntex_util::time::Seconds;
1111

1212
use crate::{consts, frame, frame::Settings, frame::WindowSize};
1313

14-
#[derive(Copy, Clone, Debug)]
14+
#[derive(Clone, Debug)]
1515
/// Http2 connection configuration
1616
pub struct ServiceConfig {
1717
pub(crate) settings: Settings,

src/connection.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,17 +990,18 @@ mod tests {
990990

991991
const PREFACE: [u8; 24] = *b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
992992

993+
#[allow(clippy::needless_pass_by_value)]
993994
fn get_reset(frm: frame::Frame) -> frame::Reset {
994995
match frm {
995996
frame::Frame::Reset(rst) => rst,
996-
_ => panic!("Expect Reset frame: {:?}", frm),
997+
_ => panic!("Expect Reset frame: {frm:?}"),
997998
}
998999
}
9991000

10001001
fn goaway(frm: frame::Frame) -> frame::GoAway {
10011002
match frm {
10021003
frame::Frame::GoAway(f) => f,
1003-
_ => panic!("Expect Reset frame: {:?}", frm),
1004+
_ => panic!("Expect Reset frame: {frm:?}"),
10041005
}
10051006
}
10061007

src/frame/headers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ mod test {
561561
HeaderValue::from_static("sup"),
562562
);
563563

564-
let mut headers = Headers::new(StreamId::CON, Default::default(), hdrs, false);
564+
let mut headers = Headers::new(StreamId::CON, PseudoHeaders::default(), hdrs, false);
565565
headers.set_end_headers();
566566
headers.encode(&mut encoder, &mut dst, 8);
567567
assert_eq!(48, dst.len());

src/hpack/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ mod test {
851851
let mut de = Decoder::new(0);
852852

853853
let mut buf = BytesMut::new();
854-
buf.extend(&[0b01000000, 0x80 | 2]);
854+
buf.extend(&[0b0100_0000, 0x80 | 2]);
855855
buf.extend(huff_encode(b"foo"));
856856
buf.extend(&[0x80 | 3]);
857857
buf.extend(huff_encode(b"bar"));
@@ -890,7 +890,7 @@ mod test {
890890
let value = huff_encode(b"bar");
891891
let mut buf = BytesMut::new();
892892
// header name is non_huff encoded
893-
buf.extend(&[0b01000000, 3]);
893+
buf.extend(&[0b0100_0000, 3]);
894894
buf.extend(b"foo");
895895
// header value is partial
896896
buf.extend(&[0x80 | 3]);

src/hpack/encoder.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ mod test {
321321
let mut encoder = Encoder::default();
322322
let res = encode(&mut encoder, vec![method("PATCH")]);
323323

324-
assert_eq!(res[0], 0b01000000 | 2); // Incremental indexing w/ name pulled from table
324+
assert_eq!(res[0], 0b0100_0000 | 2); // Incremental indexing w/ name pulled from table
325325
assert_eq!(res[1], 0x80 | 5); // header value w/ huffman coding
326326

327327
assert_eq!("PATCH", huff_decode(&res[2..7]));
@@ -338,14 +338,14 @@ mod test {
338338
let mut encoder = Encoder::default();
339339
let res = encode(&mut encoder, vec![header("content-language", "foo")]);
340340

341-
assert_eq!(res[0], 0b01000000 | 27); // Indexed name
341+
assert_eq!(res[0], 0b0100_0000 | 27); // Indexed name
342342
assert_eq!(res[1], 0x80 | 2); // header value w/ huffman coding
343343

344344
assert_eq!("foo", huff_decode(&res[2..4]));
345345

346346
// Same name, new value should still use incremental
347347
let res = encode(&mut encoder, vec![header("content-language", "bar")]);
348-
assert_eq!(res[0], 0b01000000 | 27); // Indexed name
348+
assert_eq!(res[0], 0b0100_0000 | 27); // Indexed name
349349
assert_eq!(res[1], 0x80 | 3); // header value w/ huffman coding
350350
assert_eq!("bar", huff_decode(&res[2..5]));
351351
}
@@ -355,7 +355,7 @@ mod test {
355355
let mut encoder = Encoder::default();
356356
let res = encode(&mut encoder, vec![header("foo", "hello")]);
357357

358-
assert_eq!(&[0b01000000, 0x80 | 2], &res[0..2]);
358+
assert_eq!(&[0b0100_0000, 0x80 | 2], &res[0..2]);
359359
assert_eq!("foo", huff_decode(&res[2..4]));
360360
assert_eq!(0x80 | 4, res[4]);
361361
assert_eq!("hello", huff_decode(&res[5..]));
@@ -375,10 +375,10 @@ mod test {
375375

376376
// Fill the table
377377
for i in 0..64 {
378-
let key = format!("x-hello-world-{:02}", i);
378+
let key = format!("x-hello-world-{i:02}");
379379
let res = encode(&mut encoder, vec![header(&key, &key)]);
380380

381-
assert_eq!(&[0b01000000, 0x80 | 12], &res[0..2]);
381+
assert_eq!(&[0b0100_0000, 0x80 | 12], &res[0..2]);
382382
assert_eq!(key, huff_decode(&res[2..14]));
383383
assert_eq!(0x80 | 12, res[14]);
384384
assert_eq!(key, huff_decode(&res[15..]));
@@ -396,7 +396,7 @@ mod test {
396396

397397
// Find existing headers
398398
for i in 0..64 {
399-
let key = format!("x-hello-world-{:02}", i);
399+
let key = format!("x-hello-world-{i:02}");
400400
let res = encode(&mut encoder, vec![header(&key, &key)]);
401401
assert_eq!(0x80, res[0] & 0x80);
402402
}
@@ -405,7 +405,7 @@ mod test {
405405
let key = "x-hello-world-64";
406406
let res = encode(&mut encoder, vec![header(key, key)]);
407407

408-
assert_eq!(&[0b01000000, 0x80 | 12], &res[0..2]);
408+
assert_eq!(&[0b0100_0000, 0x80 | 12], &res[0..2]);
409409
assert_eq!(key, huff_decode(&res[2..14]));
410410
assert_eq!(0x80 | 12, res[14]);
411411
assert_eq!(key, huff_decode(&res[15..]));
@@ -415,7 +415,7 @@ mod test {
415415

416416
// Now try encoding entries that should exist in the table
417417
for i in 1..65 {
418-
let key = format!("x-hello-world-{:02}", i);
418+
let key = format!("x-hello-world-{i:02}");
419419
let res = encode(&mut encoder, vec![header(&key, &key)]);
420420
assert_eq!(0x80 | (61 + (65 - i)), res[0]);
421421
}
@@ -678,20 +678,14 @@ mod test {
678678
fn test_large_size_update() {
679679
let mut encoder = Encoder::default();
680680

681-
encoder.update_max_size(1912930560);
682-
assert_eq!(Some(SizeUpdate::One(1912930560)), encoder.size_update);
681+
encoder.update_max_size(1_912_930_560);
682+
assert_eq!(Some(SizeUpdate::One(1_912_930_560)), encoder.size_update);
683683

684684
let mut dst = BytesMut::with_capacity(6);
685685
encoder.encode_size_updates(&mut dst);
686686
assert_eq!([63, 225, 129, 148, 144, 7], &dst[..]);
687687
}
688688

689-
#[test]
690-
#[ignore]
691-
fn test_evicted_overflow() {
692-
// Not sure what the best way to do this is.
693-
}
694-
695689
fn encode(e: &mut Encoder, hdrs: Vec<Header<Option<HeaderName>>>) -> BytesMut {
696690
let mut dst = BytesMut::with_capacity(1024);
697691
e.encode(hdrs, &mut dst);

src/hpack/test/fixture.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ fn test_fixture(path: &Path) {
1616
file.read_to_string(&mut data).unwrap();
1717

1818
let story: Value = serde_json::from_str(&data).unwrap();
19-
test_story(story);
19+
test_story(&story);
2020
}
2121

22-
fn test_story(story: Value) {
22+
fn test_story(story: &Value) {
2323
let story = story.as_object().unwrap();
2424

2525
if let Some(cases) = story.get("cases") {
@@ -144,10 +144,8 @@ fn key_str(e: &Header) -> &str {
144144
fn value_str(e: &Header) -> &str {
145145
match *e {
146146
Header::Field { ref value, .. } => value.to_str().unwrap(),
147-
Header::Authority(ref v) => v,
147+
Header::Authority(ref v) | Header::Scheme(ref v) | Header::Path(ref v) => v,
148148
Header::Method(ref m) => m.as_str(),
149-
Header::Scheme(ref v) => v,
150-
Header::Path(ref v) => v,
151149
Header::Protocol(ref v) => v.as_str(),
152150
Header::Status(ref v) => v.as_str(),
153151
}

0 commit comments

Comments
 (0)