use buffet::IntoHalves;
use loona_h2::PREFACE;
use crate::{rfc9113::default_settings, Conn, ErrorC, FrameT};
pub async fn sends_client_connection_preface<IO: IntoHalves>(
mut conn: Conn<IO>,
) -> eyre::Result<()> {
conn.send(PREFACE).await?;
let settings = default_settings();
conn.write_settings(settings).await?;
let (frame, _) = conn.wait_for_frame(FrameT::Settings).await.unwrap();
assert!(!frame.is_ack(), "The server connection preface MUST be the first frame the server sends in the HTTP/2 connection.");
Ok(())
}
pub async fn sends_invalid_connection_preface<IO: IntoHalves>(
mut conn: Conn<IO>,
) -> eyre::Result<()> {
conn.send("INVALID CONNECTION PREFACE\r\n\r\n").await?;
conn.verify_connection_error(ErrorC::ProtocolError).await?;
Ok(())
}