use crate::client::agent::ResponseFuture;
use crate::client::Agent;
use crate::head_ext::HeaderMapExt;
use crate::Body;
use http::Request;
use std::str::FromStr;
pub trait RequestExt {
fn header(&self, key: &str) -> Option<&str>;
fn header_as<T: FromStr>(&self, key: &str) -> Option<T>;
fn send(self) -> ResponseFuture;
}
impl<B: Into<Body> + Send> RequestExt for Request<B> {
fn header(&self, key: &str) -> Option<&str> {
self.headers().get_str(key)
}
fn header_as<T: FromStr>(&self, key: &str) -> Option<T> {
self.headers().get_as(key)
}
fn send(self) -> ResponseFuture {
let agent = Agent::new();
let (parts, body) = self.into_parts();
let req = Request::from_parts(parts, body.into());
agent.send_future(req)
}
}