io_http/rfc9110/send.rs
1//! Shared output and yield types for HTTP request-response coroutines.
2//!
3//! Both [`Http10Send`] and [`Http11Send`] return [`HttpSendOutput`] on
4//! success and emit [`HttpSendYield`] on every intermediate step.
5//!
6//! [`Http10Send`]: crate::rfc1945::send::Http10Send
7//! [`Http11Send`]: crate::rfc9112::send::Http11Send
8
9use alloc::vec::Vec;
10
11use url::Url;
12
13use crate::{coroutine::HttpYield, rfc9110::response::HttpResponse};
14
15/// Terminal output of a successful HTTP request-response exchange.
16#[derive(Clone, Debug)]
17pub struct HttpSendOutput {
18 pub response: HttpResponse,
19 pub remaining: Vec<u8>,
20 pub keep_alive: bool,
21}
22
23/// Per-step yield emitted by `Http10Send` / `Http11Send`; adds
24/// [`Self::WantsRedirect`] to the standard [`HttpYield`] for 3xx responses.
25#[derive(Debug)]
26pub enum HttpSendYield {
27 WantsRead,
28 WantsWrite(Vec<u8>),
29 WantsRedirect {
30 url: Url,
31 response: HttpResponse,
32 keep_alive: bool,
33 /// `false` when the redirect crosses scheme/host/port; do not
34 /// forward credentials without user consent (RFC 9110 ยง15.4).
35 same_origin: bool,
36 },
37}
38
39impl From<HttpYield> for HttpSendYield {
40 fn from(y: HttpYield) -> Self {
41 match y {
42 HttpYield::WantsRead => Self::WantsRead,
43 HttpYield::WantsWrite(bytes) => Self::WantsWrite(bytes),
44 }
45 }
46}