Skip to content

Commit fd44afa

Browse files
committed
Revert "Merge pull request #1825 from tursodatabase/lucio/sync-switch-hyper"
This reverts commit 265bd83, reversing changes made to 909b8af because it breaks the example app: ``` thread 'main' panicked at /Users/penberg/src/tursodatabase/libsql/libsql/src/local/database.rs:502:49: called `Result::unwrap()` on an `Err` value: hyper::Error(Connect, "invalid URL, scheme is not http") note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ```
1 parent 265bd83 commit fd44afa

File tree

3 files changed

+206
-30
lines changed

3 files changed

+206
-30
lines changed

Cargo.lock

Lines changed: 198 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libsql/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ fallible-iterator = { version = "0.3", optional = true }
4242

4343
libsql_replication = { version = "0.6", path = "../libsql-replication", optional = true }
4444
async-stream = { version = "0.3.5", optional = true }
45+
reqwest = { version = "0.12.9", default-features = false, features = [ "rustls-tls", "json" ], optional = true }
4546

4647
[dev-dependencies]
4748
criterion = { version = "0.5", features = ["html_reports", "async", "async_futures", "async_tokio"] }
@@ -104,6 +105,7 @@ sync = [
104105
"dep:bytes",
105106
"dep:tokio",
106107
"dep:futures",
108+
"dep:reqwest",
107109
"dep:serde_json",
108110
]
109111
hrana = [

libsql/src/local/database.rs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -476,40 +476,21 @@ impl Database {
476476
) -> Result<u32> {
477477
let mut nr_retries = 0;
478478
loop {
479-
// TODO(lucio): add custom connector + tls support here
480-
let client = hyper::client::Client::builder().build_http::<hyper::Body>();
481-
482-
let mut req = http::Request::post(uri.clone());
483-
479+
let client = reqwest::Client::new();
480+
let mut builder = client.post(uri.to_owned());
484481
match auth_token {
485482
Some(ref auth_token) => {
486-
let auth_header =
487-
http::HeaderValue::try_from(format!("Bearer {}", auth_token.to_owned()))
488-
.unwrap();
489-
490-
req.headers_mut()
491-
.expect("valid http request")
492-
.insert("Authorization", auth_header);
483+
builder = builder
484+
.header("Authorization", format!("Bearer {}", auth_token.to_owned()));
493485
}
494486
None => {}
495487
}
496-
497-
// TODO(lucio): convert this to use bytes to make this clone cheap, it should be
498-
// to possible use BytesMut when reading frames from the WAL and efficiently use Bytes
499-
// from that.
500-
let req = req.body(frame.clone().into()).expect("valid body");
501-
502-
let res = client.request(req).await.unwrap();
503-
504-
// TODO(lucio): only retry on server side errors
488+
let res = builder.body(frame.to_vec()).send().await.unwrap();
505489
if res.status().is_success() {
506-
let res_body = hyper::body::to_bytes(res.into_body()).await.unwrap();
507-
let resp = serde_json::from_slice::<serde_json::Value>(&res_body[..]).unwrap();
508-
490+
let resp = res.json::<serde_json::Value>().await.unwrap();
509491
let max_frame_no = resp.get("max_frame_no").unwrap().as_u64().unwrap();
510492
return Ok(max_frame_no as u32);
511493
}
512-
513494
if nr_retries > max_retries {
514495
return Err(crate::errors::Error::ConnectionFailed(format!(
515496
"Failed to push frame: {}",

0 commit comments

Comments
 (0)