@@ -40,7 +40,7 @@ but the point here is just to show all the setup required. Once you have this,
4040you are set to make thousands of client requests efficiently.
4141
4242We have to setup some sort of runtime. You can use whichever async runtime you'd
43- like, but for this guide we're going to use tokio. If you've never used futures
43+ like, but for this guide we're going to use tokio. If you've never used futures
4444in Rust before, you may wish to read through [ Tokio's guide on Futures] [ Tokio-Futures ] .
4545
4646``` rust
@@ -59,19 +59,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
5959## Setup
6060
6161To get started we'll need to get a few things setup. For this guide we're
62- going to send a GET [ ` Request ` ] [ Request ] to [ http://httpbin.org/ip ] ( http://httpbin.org/ip ) ,
63- which will return a ` 200 OK ` and the Requester's IP address in the body.
62+ going to send a GET [ ` Request ` ] [ Request ] to [ http://httpbin.org/ip ] ( http://httpbin.org/ip ) ,
63+ which will return a ` 200 OK ` and the Requester's IP address in the body.
6464
6565We need to open a TCP connection to the remote host using a hostname and port,
6666which in this case is ` httpbin.org ` and the default port for HTTP: ` 80 ` . With our
6767connection opened, we pass it in to the ` client::conn::http1::handshake ` function,
68- performing a handshake to verify the remote is ready to receive our requests.
68+ performing a handshake to verify the remote is ready to receive our requests.
6969
7070A successful handshake will give us a [ Connection] [ Connection ] future that processes
71- all HTTP state, and a [ SendRequest] [ SendRequest ] struct that we can use to send our
72- ` Request ` s on the connection.
71+ all HTTP state, and a [ SendRequest] [ SendRequest ] struct that we can use to send our
72+ ` Request ` s on the connection.
7373
74- To start driving the HTTP state we have to poll the ` Connection ` , so to finish our
74+ To start driving the HTTP state we have to poll the ` Connection ` , so to finish our
7575setup we'll spawn a ` tokio::task ` and ` await ` it.
7676
7777``` rust
@@ -123,12 +123,12 @@ tokio::task::spawn(async move {
123123
124124## GET
125125
126- Now that we've set up our connection, we're ready to construct and send our first ` Request ` !
127- Since ` SendRequest ` doesn't require absolute-form ` URI ` s we are required to include a ` HOST `
126+ Now that we've set up our connection, we're ready to construct and send our first ` Request ` !
127+ Since ` SendRequest ` doesn't require absolute-form ` URI ` s we are required to include a ` HOST `
128128header in our requests. And while we can send our ` Request ` with an empty ` Body ` , we need to
129129explicitly set it, which we'll do with the [ ` Empty ` ] [ Empty ] utility struct.
130130
131- All we need to do now is pass the ` Request ` to ` SendRequest::send_request ` , this returns a
131+ All we need to do now is pass the ` Request ` to ` SendRequest::send_request ` , this returns a
132132future which will resolve to the [ ` Response ` ] [ Response ] from ` httpbin.org ` . We'll print the
133133status of the response to see that it returned the expected ` 200 OK ` status.
134134
@@ -179,7 +179,7 @@ We know that sending a GET `Request` to `httpbin.org/ip` will return our IP addr
179179the ` Response ` body. To see the returned body, we'll simply write it to ` stdout ` .
180180
181181Bodies in hyper are asynchronous streams of [ ` Frame ` ] [ Frame ] s, so we don't have to wait for the
182- whole body to arrive, buffering it into memory, and then writing it out. We can simply
182+ whole body to arrive, buffering it into memory, and then writing it out. We can simply
183183` await ` each ` Frame ` and write them directly to ` stdout ` as they arrive!
184184
185185In addition to importing ` stdout ` , we'll need to make use of the ` BodyExt ` trait:
@@ -188,7 +188,7 @@ In addition to importing `stdout`, we'll need to make use of the `BodyExt` trait
188188# extern crate http_body_util;
189189# extern crate tokio;
190190use http_body_util :: BodyExt ;
191- use tokio :: io :: {stdout, AsyncWriteExt as _};
191+ use tokio :: io :: {AsyncWriteExt as _, self };
192192```
193193
194194``` rust
@@ -225,7 +225,7 @@ use tokio::io::{stdout, AsyncWriteExt as _};
225225while let Some (next ) = res . frame (). await {
226226 let frame = next ? ;
227227 if let Some (chunk ) = frame . data_ref () {
228- io :: stdout (). write_all (& chunk ). await ? ;
228+ io :: stdout (). write_all (chunk ). await ? ;
229229 }
230230}
231231# Ok (())
0 commit comments