-
Notifications
You must be signed in to change notification settings - Fork 768
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tokio-quiche: add support for sending additional headers
Since quiche will reject multiple calls to `send_response*()` on the same stream, we need to call `send_additional_headers()` after the initial headers are sent.
- Loading branch information
Showing
4 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (C) 2025, Cloudflare, Inc. | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright notice, | ||
// this list of conditions and the following disclaimer. | ||
// | ||
// * Redistributions in binary form must reproduce the above copyright | ||
// notice, this list of conditions and the following disclaimer in the | ||
// documentation and/or other materials provided with the distribution. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
use crate::fixtures::*; | ||
|
||
use futures::SinkExt; | ||
|
||
use tokio_quiche::http3::driver::H3Event; | ||
use tokio_quiche::http3::driver::IncomingH3Headers; | ||
use tokio_quiche::http3::driver::OutboundFrame; | ||
use tokio_quiche::http3::driver::ServerH3Event; | ||
|
||
#[tokio::test] | ||
async fn test_additional_headers() { | ||
let hook = TestConnectionHook::new(); | ||
|
||
let url = start_server_with_settings( | ||
QuicSettings::default(), | ||
Http3Settings::default(), | ||
hook, | ||
move |mut h3_conn| async move { | ||
let event_rx = h3_conn.h3_controller.event_receiver_mut(); | ||
|
||
while let Some(frame) = event_rx.recv().await { | ||
let ServerH3Event::Core(frame) = frame; | ||
|
||
match frame { | ||
H3Event::IncomingHeaders(headers) => { | ||
let IncomingH3Headers { mut send, .. } = headers; | ||
|
||
// Send initial headers. | ||
send.send(OutboundFrame::Headers(vec![ | ||
quiche::h3::Header::new(b":status", b"103"), | ||
])) | ||
.await | ||
.unwrap(); | ||
|
||
tokio::task::yield_now().await; | ||
|
||
// Send additional headers. | ||
send.send(OutboundFrame::Headers(vec![ | ||
quiche::h3::Header::new(b":status", b"200"), | ||
])) | ||
.await | ||
.unwrap(); | ||
}, | ||
|
||
H3Event::ConnectionShutdown(_) => break, | ||
|
||
_ => (), | ||
} | ||
} | ||
}, | ||
); | ||
|
||
let summary = h3i_fixtures::request(&url, 1) | ||
.await | ||
.expect("request failed"); | ||
|
||
let mut headers = summary.stream_map.headers_on_stream(0).into_iter(); | ||
|
||
assert_eq!(headers.next().expect("initial headers").headers(), &[ | ||
quiche::h3::Header::new(b":status", b"103") | ||
]); | ||
assert_eq!(headers.next().expect("additional headers").headers(), &[ | ||
quiche::h3::Header::new(b":status", b"200") | ||
]); | ||
assert!(headers.next().is_none()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters