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
//! Shared yield enum emitted by the three redirect-capable RFC 8620 coroutines
//! (session-get, blob-download, blob-upload). Their HTTP/1.1 exchange may
//! surface a 3xx; the caller chooses whether to follow it or treat it as an
//! error.
use alloc::vec::Vec;
use io_http::rfc9110::send::HttpSendYield;
use url::Url;
/// Per-step yield for redirect-capable JMAP coroutines: standard I/O variants
/// plus [`Self::WantsRedirect`].
#[derive(Debug)]
pub enum JmapRedirectYield {
/// The caller reads more bytes and feeds them back on the next resume.
WantsRead,
/// The caller writes these bytes; the next resume typically takes `None`.
WantsWrite(Vec<u8>),
/// Server responded with a 3xx. The caller opens a new connection when
/// `!keep_alive || !same_origin` and builds a fresh coroutine for `url`.
WantsRedirect {
/// Resolved redirect target (from the `Location` header).
url: Url,
/// Whether the server will keep the connection open.
keep_alive: bool,
/// Whether the redirect stays on the same scheme, host, and port.
same_origin: bool,
},
}
impl From<HttpSendYield> for JmapRedirectYield {
fn from(y: HttpSendYield) -> Self {
match y {
HttpSendYield::WantsRead => Self::WantsRead,
HttpSendYield::WantsWrite(bytes) => Self::WantsWrite(bytes),
HttpSendYield::WantsRedirect {
url,
keep_alive,
same_origin,
..
} => Self::WantsRedirect {
url,
keep_alive,
same_origin,
},
}
}
}