Skip to content

Commit 8339bd6

Browse files
committed
Revert "init connect"
This reverts commit 276f225.
1 parent 276f225 commit 8339bd6

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

examples/client.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ fn main() -> Result<(), async_h1::Exception> {
2020
println!("making request {}/2", i + 1);
2121
let url = Url::parse(&format!("http://{}/foo", peer_addr)).unwrap();
2222
let req = Request::new(Method::Get, dbg!(url));
23-
let res = client::connect(stream.clone(), req).await?;
23+
let mut req = client::encode(req).await?;
24+
io::copy(&mut req, &mut stream.clone()).await?;
25+
26+
// read the response
27+
let res = client::decode(stream.clone()).await?;
2428
println!("{:?}", res);
2529
}
2630
Ok(())

src/client.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Process HTTP connections on the client.
22
3-
use async_std::io::{self, BufReader, Read, Write};
3+
use async_std::io::{self, BufReader, Read};
44
use async_std::prelude::*;
55
use async_std::task::{Context, Poll};
66
use futures_core::ready;
@@ -48,19 +48,8 @@ impl Encoder {
4848
}
4949
}
5050

51-
/// Send an HTTP request over a stream.
52-
pub async fn connect<RW>(stream: RW, req: Request) -> Result<Response, std::io::Error>
53-
where
54-
RW: Read + Write + Clone + Send + Sync + Unpin + 'static,
55-
{
56-
let mut req = encode(req).await?;
57-
io::copy(&mut req, &mut stream.clone()).await?;
58-
let res = decode(stream.clone()).await.unwrap(); // todo: convert to http_types::Error
59-
Ok(res)
60-
}
61-
6251
/// Encode an HTTP request on the client.
63-
async fn encode(req: Request) -> Result<Encoder, std::io::Error> {
52+
pub async fn encode(req: Request) -> Result<Encoder, std::io::Error> {
6453
let mut buf: Vec<u8> = vec![];
6554

6655
let mut url = req.url().path().to_owned();
@@ -109,7 +98,7 @@ async fn encode(req: Request) -> Result<Encoder, std::io::Error> {
10998
}
11099

111100
/// Decode an HTTP response on the client.
112-
async fn decode<R>(reader: R) -> Result<Response, Exception>
101+
pub async fn decode<R>(reader: R) -> Result<Response, Exception>
113102
where
114103
R: Read + Unpin + Send + Sync + 'static,
115104
{

0 commit comments

Comments
 (0)