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
//! Streaming HTTP client for both native and WASM.
//!
//! Requires the `streaming` feature to be enabled.
//!
//! Example:
//! ```
//! let your_chunk_handler = std::sync::Arc::new(|chunk: Vec<u8>| {
//! if chunk.is_empty() {
//! return std::ops::ControlFlow::Break(());
//! }
//!
//! println!("received chunk: {} bytes", chunk.len());
//! std::ops::ControlFlow::Continue(())
//! });
//!
//! let url = "https://www.example.com";
//! let request = ehttp::Request::get(url);
//! ehttp::streaming::fetch(request, move |result: ehttp::Result<ehttp::streaming::Part>| {
//! let part = match result {
//! Ok(part) => part,
//! Err(err) => {
//! eprintln!("an error occurred while streaming `{url}`: {err}");
//! return std::ops::ControlFlow::Break(());
//! }
//! };
//!
//! match part {
//! ehttp::streaming::Part::Response(response) => {
//! println!("Status code: {:?}", response.status);
//! if response.ok {
//! std::ops::ControlFlow::Continue(())
//! } else {
//! std::ops::ControlFlow::Break(())
//! }
//! }
//! ehttp::streaming::Part::Chunk(chunk) => {
//! your_chunk_handler(chunk)
//! }
//! }
//! });
//! ```
//!
//! The streaming fetch works like the non-streaming fetch, but instead
//! of receiving the response in full, you receive parts of the response
//! as they are streamed in.
use ControlFlow;
use crateRequest;
/// Performs a HTTP requests and calls the given callback once for the initial response,
/// and then once for each chunk in the response body.
///
/// You can abort the fetch by returning [`ControlFlow::Break`] from the callback.
pub use fetch_streaming_blocking;
pub use fetch_async_streaming;
pub use Part;