Skip to content

Commit 00852fb

Browse files
committed
init http request
Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent 69533ce commit 00852fb

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/request.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ type BodyReader = dyn BufRead + Unpin + Send + 'static;
1212

1313
pin_project_lite::pin_project! {
1414
/// An HTTP request.
15+
///
16+
/// ```
17+
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
18+
/// #
19+
/// use http_types::{Url, Method, Request};
20+
///
21+
/// let url = Url::parse("https://example.com")?;
22+
/// let mut req = Request::new(Method::Get, url)?;
23+
/// #
24+
/// # Ok(()) }
25+
/// ```
1526
pub struct Request {
1627
method: Method,
1728
url: Url,
@@ -24,14 +35,17 @@ pin_project_lite::pin_project! {
2435

2536
impl Request {
2637
/// Create a new request.
27-
pub fn new(method: Method, url: Url) -> Self {
28-
Self {
29-
method,
38+
pub fn new(
39+
method: impl Into<Method>,
40+
url: Url,
41+
) -> Result<Self, Box<dyn std::error::Error + Send + Sync + 'static>> {
42+
Ok(Self {
43+
method: method.into(),
3044
url,
3145
headers: Headers::new(),
3246
body_reader: Box::new(io::empty()),
3347
length: Some(0),
34-
}
48+
})
3549
}
3650

3751
/// Get the HTTP method

0 commit comments

Comments
 (0)