Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions couch_rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
couch_rs_derive = { version = "0.10.1", optional = true, path = "../couch_rs_derive" }
url = "2"
tokio = { version = "^1.32", features = ["rt-multi-thread"] }
tokio = { version = "^1.32", features = ["rt"] }
base64 = "0.22"
tokio-util = { version = "0.7", features = ["io"] }
bytes = "1"
Expand All @@ -39,7 +39,7 @@ default-features = false
tokio = { version = "^1.32", features = ["rt-multi-thread", "macros"] }

[features]
default = ["derive", "native-tls"]
default = ["derive", "native-tls", "tokio/rt-multi-thread"]
integration-tests = []

# Provide derive(CouchDocument) macros.
Expand Down
15 changes: 10 additions & 5 deletions couch_rs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,19 @@ impl Client {
headers.insert(header::AUTHORIZATION, auth_header);
}

let mut client_builder = reqwest::Client::builder().default_headers(headers).gzip(true);
if let Some(t) = timeout {
client_builder = client_builder.timeout(Duration::new(t, 0));
let mut client_builder = reqwest::Client::builder().default_headers(headers);

#[cfg(not(target_arch = "wasm32"))]
{
client_builder = client_builder.gzip(true);

if let Some(t) = timeout {
client_builder = client_builder.timeout(Duration::new(t, 0));
}
}
let client = client_builder.build()?;

Ok(Client {
_client: client,
_client: client_builder.build()?,
uri: parse_server(uri)?,
_gzip: true,
_timeout: timeout,
Expand Down
22 changes: 22 additions & 0 deletions couch_rs/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,32 @@ use std::{collections::HashMap, fmt::Debug, pin::Pin, sync::Arc};
use tokio::sync::mpsc::Sender;

trait CouchJsonExt {
#[cfg(target_arch = "wasm32")]
fn couch_json<T: DeserializeOwned>(self) -> Pin<Box<dyn Future<Output = Result<T, CouchError>>>>;
#[cfg(not(target_arch = "wasm32"))]
fn couch_json<T: DeserializeOwned>(self) -> Pin<Box<dyn Future<Output = Result<T, CouchError>> + Send>>;
}

impl CouchJsonExt for reqwest::Response {
#[cfg(target_arch = "wasm32")]
fn couch_json<T: DeserializeOwned>(self) -> Pin<Box<dyn Future<Output = Result<T, CouchError>>>> {
let fut = async move {
let x = self.json();

match x.await {
Ok(x) => Ok(x),
Err(e) if e.is_decode() => Err(CouchError::InvalidJson(ErrorMessage {
message: e.to_string(),
upstream: Some(Arc::new(e)),
})),
Err(e) => Err(e.into()),
}
};

Box::pin(fut)
}

#[cfg(not(target_arch = "wasm32"))]
fn couch_json<T: DeserializeOwned>(self) -> Pin<Box<dyn Future<Output = Result<T, CouchError>> + Send>> {
let fut = async move {
let x = self.json();
Expand Down