tests: reduce boilerplate of sending GET requests
This adds a `SendRequestExt` trait to h2-support, with a `get` method that does a lot of the repeated request building stuff many test cases were doing. As a first step, the cleans up stream_states tests to use it.
This commit is contained in:
30
tests/h2-support/src/client_ext.rs
Normal file
30
tests/h2-support/src/client_ext.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use bytes::IntoBuf;
|
||||
use http::Request;
|
||||
use h2::client::{ResponseFuture, SendRequest};
|
||||
|
||||
/// Extend the `h2::client::SendRequest` type with convenience methods.
|
||||
pub trait SendRequestExt {
|
||||
/// Convenience method to send a GET request and ignore the SendStream
|
||||
/// (since GETs don't need to send a body).
|
||||
fn get(&mut self, uri: &str) -> ResponseFuture;
|
||||
}
|
||||
|
||||
impl<B> SendRequestExt for SendRequest<B>
|
||||
where
|
||||
B: IntoBuf,
|
||||
B::Buf: 'static,
|
||||
{
|
||||
fn get(&mut self, uri: &str) -> ResponseFuture {
|
||||
let req = Request::builder()
|
||||
// method is GET by default
|
||||
.uri(uri)
|
||||
.body(())
|
||||
.expect("valid uri");
|
||||
|
||||
let (fut, _tx) = self
|
||||
.send_request(req, /*eos =*/true)
|
||||
.expect("send_request");
|
||||
|
||||
fut
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user