Skip to content

Commit

Permalink
0.31.1: translate libsql to https before matching
Browse files Browse the repository at this point in the history
  • Loading branch information
psarna committed Jun 26, 2023
1 parent 9f4ec9b commit 8618039
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libsql-client"
version = "0.31.0"
version = "0.31.1"
edition = "2021"
license = "Apache-2.0"
description = "HTTP-based client for libSQL and sqld"
Expand Down Expand Up @@ -31,7 +31,7 @@ tracing = "0.1.37"
futures = "0.3.28"

[features]
default = ["local_backend", "hrana_backend", "reqwest_backend"]
default = ["local_backend", "reqwest_backend"]
workers_backend = ["worker", "futures-util"]
reqwest_backend = ["reqwest"]
local_backend = ["rusqlite"]
Expand Down
22 changes: 8 additions & 14 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,14 @@ impl Client {
/// # }
/// ```
#[allow(unreachable_patterns)]
pub async fn from_config<'a>(config: Config) -> anyhow::Result<Client> {
pub async fn from_config<'a>(mut config: Config) -> anyhow::Result<Client> {
config.url = if config.url.scheme() == "libsql" {
// We cannot use url::Url::set_scheme() because it prevents changing the scheme to http...
// Safe to unwrap, because we know that the scheme is libsql
url::Url::parse(&config.url.as_str().replace("libsql://", "https://")).unwrap()
} else {
config.url
};
let scheme = config.url.scheme();
Ok(match scheme {
#[cfg(feature = "local_backend")]
Expand All @@ -194,19 +201,6 @@ impl Client {
Client::Hrana(crate::hrana::Client::from_config(config).await?)
},
#[cfg(feature = "reqwest_backend")]
"libsql" => {
let inner = crate::http::InnerClient::Reqwest(crate::reqwest::HttpClient::new());
let mut config = config;
config.url = if config.url.scheme() == "libsql" {
// We cannot use url::Url::set_scheme() because it prevents changing the scheme to http...
// Safe to unwrap, because we know that the scheme is libsql
url::Url::parse(&config.url.as_str().replace("libsql://", "https://")).unwrap()
} else {
config.url
};
Client::Http(crate::http::Client::from_config(inner, config)?)
}
#[cfg(feature = "reqwest_backend")]
"http" | "https" => {
let inner = crate::http::InnerClient::Reqwest(crate::reqwest::HttpClient::new());
Client::Http(crate::http::Client::from_config(inner, config)?)
Expand Down

0 comments on commit 8618039

Please sign in to comment.