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
9 changes: 7 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ license = "MIT"
[features]
openssl = ["hyper-tls"]
rustls = ["hyper-rustls"]
default = ["openssl"]
tokio-runtime = ["tokio"]
sidevm-runtime = ["sidevm"]
default = ["openssl", "tokio-runtime"]

[dependencies]
bytes = "1.0.1"
tokio = { version = "1.2", features = ["fs", "rt"]}
tokio = { version = "1.2", features = ["fs", "rt"], optional = true }
sidevm = { version = "0.1", optional = true }

tracing = "0.1.23"
tracing-futures = "0.2"
Expand All @@ -32,6 +36,7 @@ hyper = { version = "0.14", features = ["client", "http1"] }
hyper-tls = { version = "0.5", optional = true }
futures = "0.3"
hyper-rustls = { version = "0.22", optional = true }

[dev-dependencies]
tracing-subscriber = "0.2.15"
tokio = { version = "1.2", features = ["macros", "time", "fs", "rt-multi-thread"] }
7 changes: 5 additions & 2 deletions lib/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use std::sync::{
use std::time::Duration;

use futures::{Future, FutureExt};
use tokio::time::timeout;
#[cfg(feature = "sidevm-runtime")]
use sidevm::{spawn, time::timeout};
#[cfg(feature = "tokio-runtime")]
use tokio::{spawn, time::timeout};
use tracing_futures::Instrument;

use telegram_bot_raw::{HttpRequest, Request, ResponseType};
Expand Down Expand Up @@ -94,7 +97,7 @@ impl Api {
pub fn spawn<Req: Request>(&self, request: Req) {
let api = self.clone();
if let Ok(request) = request.serialize() {
tokio::spawn(async move {
spawn(async move {
let _ = api.send_http_request::<Req::Response>(request).await;
});
}
Expand Down
16 changes: 16 additions & 0 deletions lib/src/connector/hyper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::io::{Cursor, Read};
#[cfg(feature = "tokio-runtime")]
use std::path::Path;
use std::pin::Pin;
use std::str::FromStr;
Expand Down Expand Up @@ -76,6 +77,11 @@ impl<C: Connect + std::fmt::Debug + 'static + Clone + Send + Sync> Connector for
MultipartValue::Text(text) => {
fields.push((key, MultipartTemporaryValue::Text(text)))
}
#[cfg(feature = "sidevm-runtime")]
MultipartValue::Path { .. } => {
return Err(ErrorKind::InvalidMultipartFilename.into());
}
#[cfg(feature = "tokio-runtime")]
MultipartValue::Path { file_name, path } => {
let file_name = file_name
.or_else(|| {
Expand Down Expand Up @@ -157,6 +163,7 @@ impl<C: Connect + std::fmt::Debug + 'static + Clone + Send + Sync> Connector for
}
}

#[cfg(feature = "tokio-runtime")]
pub fn default_connector() -> Result<Box<dyn Connector>, Error> {
#[cfg(feature = "rustls")]
let connector = HttpsConnector::with_native_roots();
Expand All @@ -168,3 +175,12 @@ pub fn default_connector() -> Result<Box<dyn Connector>, Error> {
Client::builder().build(connector),
)))
}

#[cfg(feature = "sidevm-runtime")]
pub fn default_connector() -> Result<Box<dyn Connector>, Error> {
Ok(Box::new(HyperConnector::new(
Client::builder()
.executor(sidevm::exec::HyperExecutor)
.build(sidevm::net::HttpConnector),
)))
}