1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::{
client::ResponseFuture,
config::{internal::ConfigurableBase, Configurable},
{Body, Error},
};
use http::{Request, Response};
/// Extension methods on an HTTP request.
pub trait RequestExt<T> {
/// Send the HTTP request synchronously using the default client.
///
/// This is a convenience method that is equivalent to
/// [`send`](crate::send).
///
/// # Examples
///
/// ```no_run
/// use isahc::prelude::*;
///
/// let response = Request::post("https://httpbin.org/post")
/// .header("Content-Type", "application/json")
/// .body(r#"{
/// "speed": "fast",
/// "cool_name": true
/// }"#)?
/// .send()?;
/// # Ok::<(), isahc::Error>(())
/// ```
fn send(self) -> Result<Response<Body>, Error>
where
T: Into<Body>;
/// Sends the HTTP request asynchronously using the default client.
///
/// This is a convenience method that is equivalent to
/// [`send_async`](crate::send_async).
fn send_async(self) -> ResponseFuture<'static>
where
T: Into<Body>;
}
impl<T> RequestExt<T> for Request<T> {
fn send(self) -> Result<Response<Body>, Error>
where
T: Into<Body>,
{
crate::send(self)
}
fn send_async(self) -> ResponseFuture<'static>
where
T: Into<Body>,
{
crate::send_async(self)
}
}
impl Configurable for http::request::Builder {}
impl ConfigurableBase for http::request::Builder {
fn configure(self, option: impl Send + Sync + 'static) -> Self {
self.extension(option)
}
}