/src/h2/tests/h2-support/src/client_ext.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use bytes::Buf; |
2 | | use h2::client::{ResponseFuture, SendRequest}; |
3 | | use http::Request; |
4 | | |
5 | | /// Extend the `h2::client::SendRequest` type with convenience methods. |
6 | | pub trait SendRequestExt { |
7 | | /// Convenience method to send a GET request and ignore the SendStream |
8 | | /// (since GETs don't need to send a body). |
9 | | fn get(&mut self, uri: &str) -> ResponseFuture; |
10 | | } |
11 | | |
12 | | impl<B> SendRequestExt for SendRequest<B> |
13 | | where |
14 | | B: Buf, |
15 | | { |
16 | 0 | fn get(&mut self, uri: &str) -> ResponseFuture { |
17 | 0 | let req = Request::builder() |
18 | 0 | // method is GET by default |
19 | 0 | .uri(uri) |
20 | 0 | .body(()) |
21 | 0 | .expect("valid uri"); |
22 | 0 |
|
23 | 0 | let (fut, _tx) = self |
24 | 0 | .send_request(req, /*eos =*/ true) |
25 | 0 | .expect("send_request"); |
26 | 0 |
|
27 | 0 | fut |
28 | 0 | } |
29 | | } |