Skip to content

Commit 85473db

Browse files
author
Kyle LeNeau
committed
Adding a String constructor method for Client
1 parent 460e09e commit 85473db

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/target
22
**/*.rs.bk
3-
Cargo.lock
3+
Cargo.lock
4+
.idea
5+
.DS_Store

src/client.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::str::from_utf8;
44
use futures::future::{self, Future};
55
use futures::stream::Stream;
66
use reqwest as r;
7-
use reqwest::r#async as ra;
7+
use reqwest::{r#async as ra, Url};
88

99
/*
1010
* TODO remove debug output
@@ -136,6 +136,20 @@ impl Client {
136136
})
137137
}
138138

139+
/// Construct a new `Client` (via a [`ClientBuilder`]). This will not
140+
/// perform any network activity until [`.stream()`] is called.
141+
///
142+
/// [`ClientBuilder`]: struct.ClientBuilder.html
143+
/// [`.stream()`]: #method.stream
144+
pub fn for_str(str_url: &str) -> Result<ClientBuilder> {
145+
let url = Url::parse(str_url)
146+
.map_err(|e| Error::HttpRequest(Box::new(e)))?;
147+
Ok(ClientBuilder {
148+
url: url,
149+
headers: r::header::HeaderMap::new(),
150+
})
151+
}
152+
139153
/// Connect to the server and begin consuming the stream. Produces a
140154
/// [`Stream`] of [`Event`]s.
141155
///

0 commit comments

Comments
 (0)