Skip to content

Commit e1831dc

Browse files
JiggyDownsamstokes
andauthored
Allow specifying HTTP client directly (#8)
The hyper client builder allows specifying many useful options, notably pool_idle_timeout and http2_keep_alive_interval, which are super useful to make sure persistent connections stay alive. This extends the rust-eventsource-client builder with the ability to pass the hyper client directly, which allows for maximal flexibility. Co-authored-by: JiggyDown <anh@jumpinvest.com.br> Co-authored-by: Sam Stokes <sstokes@launchdarkly.com>
1 parent cc418db commit e1831dc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/client.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ impl ClientBuilder {
7979
let conn = HttpsConnector::with_native_roots();
8080
self.build_with_conn(conn)
8181
}
82+
83+
pub fn build_with_http_client<C>(self, http: hyper::Client<C>) -> Client<C> {
84+
Client {
85+
http,
86+
request_props: RequestProps {
87+
url: self.url,
88+
headers: self.headers,
89+
reconnect_opts: self.reconnect_opts,
90+
},
91+
}
92+
}
8293
}
8394

8495
#[derive(Clone)]

src/decode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<S: Stream> Decoded<S> {
199199
.unwrap();
200200
trace!(
201201
"extending line from previous chunk: {:?}+{:?}",
202-
logify(&incomplete_line),
202+
logify(incomplete_line),
203203
logify(line)
204204
);
205205
incomplete_line.extend_from_slice(line);
@@ -224,7 +224,7 @@ impl<S: Stream> Decoded<S> {
224224
trace!("chunk ended with a line terminator");
225225
} else {
226226
// last line needs to be buffered as it may be incomplete
227-
trace!("buffering incomplete line: {:?}", logify(&line));
227+
trace!("buffering incomplete line: {:?}", logify(line));
228228
*this.incomplete_line = Some(line.to_vec());
229229
}
230230
}

0 commit comments

Comments
 (0)