|
1 | 1 | use super::{response::IncomingBody, Body, Error, Request, Response, Result};
|
2 |
| -use crate::io::{self, AsyncWrite}; |
| 2 | +use crate::io::{self, AsyncOutputStream}; |
3 | 3 | use crate::runtime::Reactor;
|
4 | 4 | use crate::time::Duration;
|
5 | 5 | use wasi::http::types::{OutgoingBody, RequestOptions as WasiRequestOptions};
|
@@ -27,9 +27,7 @@ impl Client {
|
27 | 27 | let res = wasi::http::outgoing_handler::handle(wasi_req, self.wasi_options()?).unwrap();
|
28 | 28 |
|
29 | 29 | // 2. Start sending the request body
|
30 |
| - io::copy(body, OutputStream::new(body_stream)) |
31 |
| - .await |
32 |
| - .expect("io::copy broke oh no"); |
| 30 | + io::copy(body, AsyncOutputStream::new(body_stream)).await?; |
33 | 31 |
|
34 | 32 | // 3. Finish sending the request body
|
35 | 33 | let trailers = None;
|
@@ -74,33 +72,6 @@ impl Client {
|
74 | 72 | }
|
75 | 73 | }
|
76 | 74 |
|
77 |
| -struct OutputStream { |
78 |
| - stream: wasi::http::types::OutputStream, |
79 |
| -} |
80 |
| - |
81 |
| -impl OutputStream { |
82 |
| - fn new(stream: wasi::http::types::OutputStream) -> Self { |
83 |
| - Self { stream } |
84 |
| - } |
85 |
| -} |
86 |
| - |
87 |
| -impl AsyncWrite for OutputStream { |
88 |
| - async fn write(&mut self, buf: &[u8]) -> io::Result<usize> { |
89 |
| - let max = self.stream.check_write().unwrap() as usize; |
90 |
| - let max = max.min(buf.len()); |
91 |
| - let buf = &buf[0..max]; |
92 |
| - self.stream.write(buf).unwrap(); |
93 |
| - Reactor::current().wait_for(self.stream.subscribe()).await; |
94 |
| - Ok(max) |
95 |
| - } |
96 |
| - |
97 |
| - async fn flush(&mut self) -> io::Result<()> { |
98 |
| - self.stream.flush().unwrap(); |
99 |
| - Reactor::current().wait_for(self.stream.subscribe()).await; |
100 |
| - Ok(()) |
101 |
| - } |
102 |
| -} |
103 |
| - |
104 | 75 | #[derive(Default, Debug)]
|
105 | 76 | struct RequestOptions {
|
106 | 77 | connect_timeout: Option<Duration>,
|
|
0 commit comments