Skip to content

Commit 8f6cfec

Browse files
authored
Merge pull request #9 from yoshuawuyts/upgrade-async-std
Upgrade async-std to 0.99.12
2 parents 46abc32 + 1c27d6b commit 8f6cfec

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ edition = "2018"
1414
[dependencies]
1515
httparse = "1.3.3"
1616
http = "0.1.17"
17-
futures-io-preview = "0.3.0-alpha.18"
18-
async-std = "0.99.8"
17+
futures-io = "0.3.0"
18+
async-std = "0.99.12"
1919
futures-core-preview = "0.3.0-alpha.18"
2020

2121
[dev-dependencies]
22-
futures-util-preview = "0.3.0-alpha.18"
22+
futures-util = "0.3.0"

src/body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use async_std::task::{Context, Poll};
22
use futures_io::AsyncRead;
33

4+
use async_std::io::{self, Cursor};
45
use std::fmt;
5-
use std::io::{self, Cursor};
66
use std::pin::Pin;
77

88
/// A streaming HTTP body.

src/client.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Process HTTP connections on the client.
22
33
use async_std::io::{self, BufReader};
4-
use async_std::task::{Context, Poll};
54
use async_std::prelude::*;
6-
use futures_io::AsyncRead;
5+
use async_std::task::{Context, Poll};
76
use futures_core::ready;
7+
use futures_io::AsyncRead;
88
use http::{Request, Response, Version};
99

1010
use std::pin::Pin;
@@ -28,7 +28,7 @@ pub struct Encoder<R: AsyncRead> {
2828
body_bytes_read: usize,
2929
}
3030

31-
impl <R: AsyncRead> Encoder<R> {
31+
impl<R: AsyncRead> Encoder<R> {
3232
/// Create a new instance.
3333
pub(crate) fn new(headers: Vec<u8>, body: Body<R>) -> Self {
3434
Self {
@@ -44,20 +44,20 @@ impl <R: AsyncRead> Encoder<R> {
4444

4545
/// Encode an HTTP request on the client.
4646
pub async fn encode<R: AsyncRead>(req: Request<Body<R>>) -> Result<Encoder<R>, std::io::Error> {
47-
use std::io::Write;
4847
let mut buf: Vec<u8> = vec![];
4948

5049
write!(
5150
&mut buf,
5251
"{} {} HTTP/1.1\r\n",
5352
req.method().as_str(),
54-
req.uri()
55-
)?;
53+
req.uri(),
54+
)
55+
.await?;
5656

5757
// If the body isn't streaming, we can set the content-length ahead of time. Else we need to
5858
// send all items in chunks.
5959
if let Some(len) = req.body().len() {
60-
write!(&mut buf, "Content-Length: {}\r\n", len)?;
60+
write!(&mut buf, "Content-Length: {}\r\n", len).await?;
6161
} else {
6262
// write!(&mut buf, "Transfer-Encoding: chunked\r\n")?;
6363
panic!("chunked encoding is not implemented yet");
@@ -71,17 +71,16 @@ pub async fn encode<R: AsyncRead>(req: Request<Body<R>>) -> Result<Encoder<R>, s
7171
"{}: {}\r\n",
7272
header.as_str(),
7373
value.to_str().unwrap()
74-
)?;
74+
)
75+
.await?;
7576
}
7677

77-
write!(&mut buf, "\r\n")?;
78+
write!(&mut buf, "\r\n").await?;
7879
Ok(Encoder::new(buf, req.into_body()))
7980
}
8081

8182
/// Decode an HTTP respons on the client.
82-
pub async fn decode<R>(
83-
reader: R,
84-
) -> Result<Response<Body<BufReader<R>>>, Exception>
83+
pub async fn decode<R>(reader: R) -> Result<Response<Body<BufReader<R>>>, Exception>
8584
where
8685
R: AsyncRead + Unpin + Send,
8786
{
@@ -138,7 +137,7 @@ where
138137
Ok(res.body(body)?)
139138
}
140139

141-
impl <R: AsyncRead + Unpin> AsyncRead for Encoder<R> {
140+
impl<R: AsyncRead + Unpin> AsyncRead for Encoder<R> {
142141
fn poll_read(
143142
mut self: Pin<&mut Self>,
144143
cx: &mut Context<'_>,

src/server.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,18 @@ pub async fn encode<R>(res: Response<Body<R>>) -> io::Result<Encoder<R>>
8383
where
8484
R: AsyncRead,
8585
{
86-
use std::io::Write;
8786
let mut buf: Vec<u8> = vec![];
8887

8988
let reason = res.status().canonical_reason().unwrap();
9089
let status = res.status();
91-
write!(&mut buf, "HTTP/1.1 {} {}\r\n", status.as_str(), reason)?;
90+
write!(&mut buf, "HTTP/1.1 {} {}\r\n", status.as_str(), reason).await?;
9291

9392
// If the body isn't streaming, we can set the content-length ahead of time. Else we need to
9493
// send all items in chunks.
9594
if let Some(len) = res.body().len() {
96-
write!(&mut buf, "Content-Length: {}\r\n", len)?;
95+
write!(&mut buf, "Content-Length: {}\r\n", len).await?;
9796
} else {
98-
write!(&mut buf, "Transfer-Encoding: chunked\r\n")?;
97+
write!(&mut buf, "Transfer-Encoding: chunked\r\n").await?;
9998
panic!("chunked encoding is not implemented yet");
10099
// See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding
101100
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer
@@ -107,10 +106,11 @@ where
107106
"{}: {}\r\n",
108107
header.as_str(),
109108
value.to_str().unwrap()
110-
)?;
109+
)
110+
.await?;
111111
}
112112

113-
write!(&mut buf, "\r\n")?;
113+
write!(&mut buf, "\r\n").await?;
114114
Ok(Encoder::new(buf, res.into_body()))
115115
}
116116

0 commit comments

Comments
 (0)