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
65
66
67
68
69
70
71
72
73
use crate::core::data::uuid::UUID;
use crate::core::Transport;
use derive_builder::Builder;
use getset::Getters;
use hyper::{client::HttpConnector, Body, Client};
use hyper_tls::HttpsConnector;
use std::time::Duration;
pub mod error;
pub mod presence;
pub mod pubsub;
#[macro_use]
mod util;
type HttpClient = Client<HttpsConnector<HttpConnector>>;
#[derive(Debug, Clone, Builder, Getters)]
#[getset(get = "pub")]
pub struct Hyper {
#[builder(default = "Self::default_http_client()")]
http_client: HttpClient,
#[builder(setter(into))]
subscribe_key: String,
#[builder(setter(into))]
publish_key: String,
#[builder(setter(into), default = "\"ps.pndsn.com\".to_owned()")]
origin: String,
#[builder(setter(into), default = "\"Rust-Agent\".to_owned()")]
agent: String,
#[builder(setter(into), default = "Self::default_uuid()")]
uuid: UUID,
}
impl Hyper {
#[must_use]
#[allow(clippy::new_ret_no_self)]
pub fn new() -> HyperBuilder {
HyperBuilder::default()
}
}
impl Transport for Hyper {
type Error = error::Error;
}
impl HyperBuilder {
fn default_http_client() -> HttpClient {
let https = HttpsConnector::new();
Client::builder()
.pool_idle_timeout(Some(Duration::from_secs(300)))
.pool_max_idle_per_host(10000)
.build::<_, Body>(https)
}
fn default_uuid() -> UUID {
UUID::random()
}
}