apollo-http-client 0.3.0

HTTP client for Apollo platform
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
//! Integration tests for HTTP/2 paths.
#![allow(unused_imports)]

#[macro_use]
mod common;

use std::net::SocketAddr;
use std::time::Duration;

use apollo_http_client::{HttpBody, HttpClient, HttpClientConfig};
use apollo_opentelemetry::metrics::Clock;
use apollo_opentelemetry_test::{TelemetryContext, assert_metric, assert_metrics_snapshot};
use axum::Router;
use axum::routing::get;
use bytes::Bytes;
use http_body_util::{BodyExt as _, Full};
use hyper_util::rt::{TokioExecutor, TokioIo};
use indoc::indoc;
use opentelemetry_sdk::metrics::{Aggregation, Instrument, StreamBuilder};
use tower::ServiceExt as _;

use common::*;

// --- H2: infrastructure ---------------------------------------------------

/// Spawns a local H2c (HTTP/2 cleartext, no TLS) server.
///
/// Unlike [`spawn_server`], this uses `hyper::server::conn::http2` directly so
/// that the client can connect with H2 prior-knowledge without TLS negotiation.
async fn spawn_h2c_server(router: Router) -> SocketAddr {
    use hyper::server::conn::http2;
    use hyper_util::service::TowerToHyperService;

    let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
    let addr = listener.local_addr().unwrap();

    tokio::spawn(async move {
        loop {
            let Ok((stream, _)) = listener.accept().await else {
                break;
            };
            let io = TokioIo::new(stream);
            let svc = TowerToHyperService::new(router.clone());
            tokio::spawn(async move {
                http2::Builder::new(TokioExecutor::new())
                    .serve_connection(io, svc)
                    .await
                    .ok();
            });
        }
    });

    addr
}

fn h2_config() -> HttpClientConfig {
    parse_config("protocol: http2")
}

/// Returns a [`TelemetryContext`] that records only `http.client.open_connections`.
///
/// Used in H2 connection-state tests to keep snapshots focused without the noise
/// of request-level metrics. `http.client.connection.duration` is tested
/// separately in [`h2_connection_duration_is_recorded`].
fn h2_connections_context() -> TelemetryContext {
    TelemetryContext::builder()
        .with_view(|instrument: &Instrument| {
            if instrument.name() != "http.client.open_connections" {
                Some(
                    StreamBuilder::default()
                        .with_aggregation(Aggregation::Drop)
                        .build()
                        .unwrap(),
                )
            } else {
                None
            }
        })
        .build()
}

// --- H2: error path -------------------------------------------------------

/// H2 configuration does not panic on a connection-refused error; `error.type: "_OTHER"`
/// is recorded on `http.client.request.duration`.
#[tokio::test]
async fn h2_connection_refused_records_error() {
    let ctx = TelemetryContext::new();

    let config = parse_config("protocol: http2\nconnect_timeout: 1s");
    let req = http::Request::builder()
        .method(http::Method::GET)
        .uri("http://127.0.0.1:1/")
        .body(empty_body())
        .unwrap();

    let _ = new_client(&config).oneshot(req).await;

    assert_metrics_snapshot!(ctx, @r#"
    - name: http.client.active_requests
      description: Number of HTTP requests currently in flight
      unit: "{request}"
      data:
        type: Sum
        data_points:
          - attributes:
              http.request.method: GET
              server.address: 127.0.0.1
              server.port: "1"
            value: 0
        is_monotonic: false
        temporality: Cumulative
    - name: http.client.request.duration
      description: Duration of HTTP client requests
      unit: s
      data:
        type: Histogram
        data_points:
          - attributes:
              error.type: _OTHER
              http.request.method: GET
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "1"
            count: 1
            sum: 0
            min: 0
            max: 0
            bounds:
              - 0.005
              - 0.01
              - 0.025
              - 0.05
              - 0.075
              - 0.1
              - 0.25
              - 0.5
              - 0.75
              - 1
              - 2.5
              - 5
              - 7.5
              - 10
            bucket_counts:
              - 1
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
        temporality: Cumulative
    "#);
}

/// When an H2c server accepts the TCP connection but immediately closes it,
/// the HTTP/2 handshake succeeds (the client sends its preface before the FIN
/// arrives) but the subsequent request fails. `error.type: "_OTHER"` is
/// recorded. `http.client.open_connections` is incremented then returned to
/// zero on connection close, and `connection.duration` is emitted.
#[tokio::test]
async fn h2_server_closes_before_handshake() {
    let ctx = integration_context();

    let addr = spawn_drop_server().await;
    let req = http::Request::builder()
        .method(http::Method::GET)
        .uri(format!("http://{addr}/"))
        .body(empty_body())
        .unwrap();

    let err = new_client(&h2_config())
        .oneshot(req)
        .await
        .expect_err("should fail");
    assert!(matches!(
        err,
        apollo_http_client::HttpClientError::Request { .. }
    ));

    snapshot!(ctx, @r#"
    - name: http.client.active_requests
      description: Number of HTTP requests currently in flight
      unit: "{request}"
      data:
        type: Sum
        data_points:
          - attributes:
              http.request.method: GET
              server.address: 127.0.0.1
              server.port: "<port>"
            value: 0
        is_monotonic: false
        temporality: Cumulative
    - name: http.client.open_connections
      description: Number of open connections in the HTTP client pool
      unit: "{connection}"
      data:
        type: Sum
        data_points:
          - attributes:
              http.connection.state: active
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
            value: 0
          - attributes:
              http.connection.state: idle
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
            value: 0
        is_monotonic: false
        temporality: Cumulative
    - name: http.client.request.duration
      description: Duration of HTTP client requests
      unit: s
      data:
        type: Histogram
        data_points:
          - attributes:
              error.type: _OTHER
              http.request.method: GET
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
            count: 1
            sum: 0
            min: 0
            max: 0
            bounds:
              - 0.005
              - 0.01
              - 0.025
              - 0.05
              - 0.075
              - 0.1
              - 0.25
              - 0.5
              - 0.75
              - 1
              - 2.5
              - 5
              - 7.5
              - 10
            bucket_counts:
              - 1
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
        temporality: Cumulative
    "#);
}

/// When the server closes the H2 connection while a request is in-flight, the
/// request fails with `error.type: "_OTHER"`. Open connection counters return
/// to zero and all RAII metric guards fire correctly.
#[tokio::test]
async fn h2_server_closes_connection_during_request() {
    use hyper::server::conn::http2;
    use hyper_util::service::TowerToHyperService;

    let ctx = integration_context();

    let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
    let addr = listener.local_addr().unwrap();

    tokio::spawn(async move {
        let Ok((stream, _)) = listener.accept().await else {
            return;
        };
        let io = TokioIo::new(stream);
        // Handler sleeps forever; connection is dropped from the outside after
        // the request arrives.
        let svc = TowerToHyperService::new(Router::new().route(
            "/",
            get(|| async {
                tokio::time::sleep(Duration::MAX).await;
                ""
            }),
        ));
        let conn = http2::Builder::new(TokioExecutor::new()).serve_connection(io, svc);
        tokio::pin!(conn);
        // Drive the connection long enough for the request to arrive, then
        // close it. The client's in-flight request will get a stream or
        // connection error.
        let _ = tokio::time::timeout(Duration::from_millis(50), &mut conn).await;
        // conn is dropped here, closing the TCP connection.
    });

    let req = http::Request::builder()
        .method(http::Method::GET)
        .uri(format!("http://{addr}/"))
        .body(empty_body())
        .unwrap();

    let err = new_client(&h2_config())
        .oneshot(req)
        .await
        .expect_err("should fail");
    assert!(matches!(
        err,
        apollo_http_client::HttpClientError::Request { .. }
    ));

    snapshot!(ctx, @r#"
    - name: http.client.active_requests
      description: Number of HTTP requests currently in flight
      unit: "{request}"
      data:
        type: Sum
        data_points:
          - attributes:
              http.request.method: GET
              server.address: 127.0.0.1
              server.port: "<port>"
            value: 0
        is_monotonic: false
        temporality: Cumulative
    - name: http.client.open_connections
      description: Number of open connections in the HTTP client pool
      unit: "{connection}"
      data:
        type: Sum
        data_points:
          - attributes:
              http.connection.state: active
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
            value: 0
          - attributes:
              http.connection.state: idle
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
            value: 0
        is_monotonic: false
        temporality: Cumulative
    - name: http.client.request.duration
      description: Duration of HTTP client requests
      unit: s
      data:
        type: Histogram
        data_points:
          - attributes:
              error.type: _OTHER
              http.request.method: GET
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
            count: 1
            sum: 0
            min: 0
            max: 0
            bounds:
              - 0.005
              - 0.01
              - 0.025
              - 0.05
              - 0.075
              - 0.1
              - 0.25
              - 0.5
              - 0.75
              - 1
              - 2.5
              - 5
              - 7.5
              - 10
            bucket_counts:
              - 1
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
        temporality: Cumulative
    "#);
}

// --- H2: success path -----------------------------------------------------

/// A successful H2 GET records all metrics with `network.protocol.version: "2"`,
/// including body size metrics (enabled explicitly).
#[tokio::test]
async fn h2_successful_get_records_all_metrics() {
    let ctx = integration_context();

    let addr = spawn_h2c_server(Router::new().route("/", get(|| async { "hello" }))).await;
    let config = parse_config(indoc! {"
        protocol: http2
        telemetry:
          metrics:
            request_body_size: true
            response_body_size: true
            url_scheme: true
    "});
    let client = new_client(&config);
    let req = http::Request::builder()
        .method(http::Method::GET)
        .uri(format!("http://{addr}/"))
        .body(empty_body())
        .unwrap();

    let resp = client.clone().oneshot(req).await.expect("request ok");
    resp.into_body().collect().await.unwrap();
    drop(client);

    snapshot!(ctx, @r#"
    - name: http.client.active_requests
      description: Number of HTTP requests currently in flight
      unit: "{request}"
      data:
        type: Sum
        data_points:
          - attributes:
              http.request.method: GET
              server.address: 127.0.0.1
              server.port: "<port>"
              url.scheme: http
            value: 0
        is_monotonic: false
        temporality: Cumulative
    - name: http.client.open_connections
      description: Number of open connections in the HTTP client pool
      unit: "{connection}"
      data:
        type: Sum
        data_points:
          - attributes:
              http.connection.state: active
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
              url.scheme: http
            value: 0
          - attributes:
              http.connection.state: idle
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
              url.scheme: http
            value: 0
        is_monotonic: false
        temporality: Cumulative
    - name: http.client.request.body.size
      description: Size of HTTP request bodies sent by the client
      unit: By
      data:
        type: Histogram
        data_points:
          - attributes:
              http.request.method: GET
              http.response.status_code: "200"
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
              url.scheme: http
            count: 1
            sum: 0
            min: 0
            max: 0
            bounds:
              - 0
              - 1024
              - 4096
              - 16384
              - 65536
              - 262144
              - 1048576
              - 4194304
              - 16777216
            bucket_counts:
              - 1
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
        temporality: Cumulative
    - name: http.client.request.duration
      description: Duration of HTTP client requests
      unit: s
      data:
        type: Histogram
        data_points:
          - attributes:
              http.request.method: GET
              http.response.status_code: "200"
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
              url.scheme: http
            count: 1
            sum: 0
            min: 0
            max: 0
            bounds:
              - 0.005
              - 0.01
              - 0.025
              - 0.05
              - 0.075
              - 0.1
              - 0.25
              - 0.5
              - 0.75
              - 1
              - 2.5
              - 5
              - 7.5
              - 10
            bucket_counts:
              - 1
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
        temporality: Cumulative
    - name: http.client.response.body.size
      description: Size of HTTP response bodies received by the client
      unit: By
      data:
        type: Histogram
        data_points:
          - attributes:
              http.request.method: GET
              http.response.status_code: "200"
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
              url.scheme: http
            count: 1
            sum: 5
            min: 5
            max: 5
            bounds:
              - 0
              - 1024
              - 4096
              - 16384
              - 65536
              - 262144
              - 1048576
              - 4194304
              - 16777216
            bucket_counts:
              - 0
              - 1
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
        temporality: Cumulative
    "#);
}

/// A 404 response over H2 records `http.response.status_code: 404` and
/// `error.type: "404"` on the request duration histogram, with
/// `network.protocol.version: "2"`.
#[tokio::test]
async fn h2_4xx_response_records_status_and_error_type() {
    let ctx = integration_context();

    let addr =
        spawn_h2c_server(Router::new().route("/", get(|| async { http::StatusCode::NOT_FOUND })))
            .await;
    let client = new_client(&h2_config());
    let req = http::Request::builder()
        .method(http::Method::GET)
        .uri(format!("http://{addr}/"))
        .body(empty_body())
        .unwrap();

    let resp = client.clone().oneshot(req).await.expect("request ok");
    assert_eq!(resp.status(), http::StatusCode::NOT_FOUND);
    drop(resp);
    drop(client);

    snapshot!(ctx, @r#"
    - name: http.client.active_requests
      description: Number of HTTP requests currently in flight
      unit: "{request}"
      data:
        type: Sum
        data_points:
          - attributes:
              http.request.method: GET
              server.address: 127.0.0.1
              server.port: "<port>"
            value: 0
        is_monotonic: false
        temporality: Cumulative
    - name: http.client.open_connections
      description: Number of open connections in the HTTP client pool
      unit: "{connection}"
      data:
        type: Sum
        data_points:
          - attributes:
              http.connection.state: active
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
            value: 0
          - attributes:
              http.connection.state: idle
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
            value: 0
        is_monotonic: false
        temporality: Cumulative
    - name: http.client.request.duration
      description: Duration of HTTP client requests
      unit: s
      data:
        type: Histogram
        data_points:
          - attributes:
              error.type: "404"
              http.request.method: GET
              http.response.status_code: "404"
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
            count: 1
            sum: 0
            min: 0
            max: 0
            bounds:
              - 0.005
              - 0.01
              - 0.025
              - 0.05
              - 0.075
              - 0.1
              - 0.25
              - 0.5
              - 0.75
              - 1
              - 2.5
              - 5
              - 7.5
              - 10
            bucket_counts:
              - 1
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
              - 0
        temporality: Cumulative
    "#);
}

// --- H2: connection state -------------------------------------------------

/// After completed requests the H2 connection stays `idle: 1` as long as the
/// client is alive (the singleton holds it open for reuse), dropping to
/// `idle: 0` only when the client is dropped.
///
/// This contrasts with H1, where pooled connections sit in `active` state
/// between requests (idle is only set during `poll_ready`).
#[tokio::test]
async fn h2_connection_stays_idle_between_requests() {
    let ctx = h2_connections_context();

    let addr = spawn_h2c_server(Router::new().route("/", get(|| async { "ok" }))).await;
    let client = new_client(&h2_config());

    for _ in 0..2 {
        let req = http::Request::builder()
            .method(http::Method::GET)
            .uri(format!("http://{addr}/"))
            .body(empty_body())
            .unwrap();
        let resp = client.clone().oneshot(req).await.expect("request ok");
        resp.into_body().collect().await.unwrap();
    }

    // Connection is held open by the singleton — idle while no requests are in flight.
    snapshot!(ctx, @r#"
    - name: http.client.open_connections
      description: Number of open connections in the HTTP client pool
      unit: "{connection}"
      data:
        type: Sum
        data_points:
          - attributes:
              http.connection.state: active
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
            value: 0
          - attributes:
              http.connection.state: idle
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
            value: 1
        is_monotonic: false
        temporality: Cumulative
    "#);

    drop(client);

    // Connection released when the client (and its singleton) is dropped.
    snapshot!(ctx, @r#"
    - name: http.client.open_connections
      description: Number of open connections in the HTTP client pool
      unit: "{connection}"
      data:
        type: Sum
        data_points:
          - attributes:
              http.connection.state: active
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
            value: 0
          - attributes:
              http.connection.state: idle
              network.protocol.version: "2"
              server.address: 127.0.0.1
              server.port: "<port>"
            value: 0
        is_monotonic: false
        temporality: Cumulative
    "#);
}

/// `http.client.connection.duration` is recorded for H2 connections with
/// `network.protocol.version: "2"`. Verified with `assert_metric!` because the
/// wall-clock sum is non-deterministic.
#[tokio::test]
async fn h2_connection_duration_is_recorded() {
    let ctx = TelemetryContext::new();

    let addr = spawn_h2c_server(Router::new().route("/", get(|| async { "ok" }))).await;
    let req = http::Request::builder()
        .method(http::Method::GET)
        .uri(format!("http://{addr}/"))
        .body(empty_body())
        .unwrap();

    new_client(&h2_config())
        .oneshot(req)
        .await
        .expect("request ok");

    assert_metric!(
        ctx,
        "http.client.connection.duration",
        "network.protocol.version" = "2"
    );
}

/// Idle H2 connections are freed immediately when the client is dropped.
/// See [`h1_connections_freed_immediately_on_client_drop`] for the rationale.
#[tokio::test]
async fn h2_connections_freed_immediately_on_client_drop() {
    let ctx = TelemetryContext::new();
    let addr = spawn_h2c_server(Router::new().route("/", get(|| async { "ok" }))).await;
    let client = new_client(&h2_config());
    let req = http::Request::builder()
        .method(http::Method::GET)
        .uri(format!("http://{addr}/"))
        .body(empty_body())
        .unwrap();

    let resp = client.clone().oneshot(req).await.expect("request ok");
    resp.into_body().collect().await.unwrap();

    drop(client);
    assert_metric!(
        ctx,
        "http.client.connection.duration",
        "network.protocol.version" = "2"
    );
}

/// HTTP/2 doesn't use the Host header, but an :authority pseudo-header.
/// It's tempting to put the Host derivation at the front of the HttpClient, but that's not where it
/// belongs, and this test makes sure that we apply it to HTTP/1.1 only.
#[tokio::test]
async fn h2_does_not_derive_host_header() {
    let _ctx = TelemetryContext::new();

    let router = Router::new().route(
        "/",
        get(async move |req: axum::http::Request<axum::body::Body>| {
            assert_eq!(
                req.headers().get("host"),
                None,
                "should not have host header in http/2"
            );
            "hello world"
        }),
    );
    let addr = spawn_h2c_server(router).await;

    let client = new_client(&h2_config());
    let req = http::Request::builder()
        .method(http::Method::GET)
        .uri(format!("http://{addr}/"))
        .body(empty_body())
        .unwrap();

    let resp = client.oneshot(req).await.expect("request ok");

    let body = resp.into_body().collect().await.expect("should read body");
    let body = String::from_utf8(body.to_bytes().to_vec()).expect("body should be utf8");
    assert_eq!(body, "hello world", "received the expected response");
}