Skip to content

Commit 47904d2

Browse files
author
Riley Apeldoorn
committed
Allow http(s) scheme in the producer client host string
1 parent 2c88705 commit 47904d2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

opsqueue/src/producer/client.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,20 @@ impl Client {
3131
/// Construct a new producer client.
3232
///
3333
/// `host` is where the `/producer/...` endpoints can be reached over http.
34-
/// Don't include the scheme or the `/producer` part.
34+
/// You can include the scheme if it's `http://` or `https://`. If it's not
35+
/// included, http is chosen by default. If it's not supported, this function
36+
/// panics.
3537
///
36-
/// Examples: `0.0.0.0:1312`, `my.opsueue.instance.example.com`, `services.example.com/opsqueue`
38+
/// Examples: `0.0.0.0:1312`, `my.opsqueue.instance.example.com`, `https://services.example.com/opsqueue`
3739
pub fn new(host: &str) -> Self {
3840
let http_client = reqwest::Client::new();
39-
let base_url = format!("http://{host}/producer").into_boxed_str();
41+
let base_url = match host.split_once("://") {
42+
Some(("http" | "https", _)) => format!("{host}/producer"),
43+
None => format!("http://{host}/producer"),
44+
Some((scheme, _)) => panic!("Unsupported scheme: {scheme}, must be 'http' or 'https'"),
45+
};
4046
Client {
41-
base_url,
47+
base_url: base_url.into_boxed_str(),
4248
http_client,
4349
}
4450
}

0 commit comments

Comments
 (0)