Skip to content

Commit 032c38b

Browse files
authored
feat(tokio): add reqwest feature (#734)
Move the client ReqwestNetworkClient to ironrdp-tokio, so other clients can optionally use the implementation. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
1 parent 817abb9 commit 032c38b

8 files changed

Lines changed: 41 additions & 18 deletions

File tree

Cargo.lock

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

crates/ironrdp-async/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mod session;
1313
use core::future::Future;
1414
use core::pin::Pin;
1515

16+
pub use ironrdp_connector;
1617
use ironrdp_connector::sspi::generator::NetworkRequest;
1718
use ironrdp_connector::ConnectorResult;
1819

crates/ironrdp-client/Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@ ironrdp = { path = "../ironrdp", version = "0.9", features = [
4040
"rdpsnd",
4141
"cliprdr",
4242
"displaycontrol",
43-
"connector"
43+
"connector",
44+
] }
45+
ironrdp-core = { path = "../ironrdp-core", version = "0.1", features = [
46+
"alloc",
4447
] }
45-
ironrdp-core = { path = "../ironrdp-core", version = "0.1", features = ["alloc"] }
4648
ironrdp-cliprdr-native = { path = "../ironrdp-cliprdr-native", version = "0.2" }
4749
ironrdp-rdpsnd-native = { path = "../ironrdp-rdpsnd-native", version = "0.2" }
4850
ironrdp-tls = { path = "../ironrdp-tls", version = "0.1" }
49-
ironrdp-tokio = { path = "../ironrdp-tokio", version = "0.3" }
50-
sspi = { version = "0.15", features = ["network_client", "dns_resolver"] } # TODO: enable additional features
51+
ironrdp-tokio = { path = "../ironrdp-tokio", version = "0.3", features = [
52+
"reqwest",
53+
] }
5154

5255
# Windowing and rendering
5356
winit = { version = "0.30", features = ["rwh_06"] }
@@ -71,8 +74,6 @@ anyhow = "1"
7174
smallvec = "1.13"
7275
tap = "1"
7376
semver = "1"
74-
reqwest = "0.12"
75-
url = "2.5"
7677
raw-window-handle = "0.6"
7778
uuid = { version = "1.16" }
7879

crates/ironrdp-client/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ extern crate tracing;
1515
pub mod app;
1616
pub mod clipboard;
1717
pub mod config;
18-
pub mod network_client;
1918
pub mod rdp;

crates/ironrdp-client/src/rdp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use ironrdp::session::{fast_path, ActiveStage, ActiveStageOutput, GracefulDiscon
1010
use ironrdp::{cliprdr, connector, rdpdr, rdpsnd, session};
1111
use ironrdp_core::WriteBuf;
1212
use ironrdp_rdpsnd_native::cpal;
13+
use ironrdp_tokio::reqwest::ReqwestNetworkClient;
1314
use ironrdp_tokio::{single_sequence_step_read, split_tokio_framed, FramedWrite};
1415
use rdpdr::NoopRdpdrBackend;
1516
use smallvec::SmallVec;
@@ -146,7 +147,7 @@ async fn connect(
146147

147148
let mut upgraded_framed = ironrdp_tokio::TokioFramed::new(upgraded_stream);
148149

149-
let mut network_client = crate::network_client::ReqwestNetworkClient::new();
150+
let mut network_client = ReqwestNetworkClient::new();
150151
let connection_result = ironrdp_tokio::connect_finalize(
151152
upgraded,
152153
&mut upgraded_framed,

crates/ironrdp-tokio/Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ categories.workspace = true
1515
doctest = false
1616
test = false
1717

18+
[features]
19+
default = ["reqwest"]
20+
reqwest = ["dep:reqwest", "dep:sspi", "dep:url"]
21+
1822
[dependencies]
1923
bytes = "1"
2024
ironrdp-async = { path = "../ironrdp-async", version = "0.4" } # public
2125
tokio = { version = "1", features = ["io-util"] }
26+
reqwest = { version = "0.12", optional = true }
27+
sspi = { version = "0.15", features = [
28+
"network_client",
29+
"dns_resolver",
30+
], optional = true } # TODO: enable additional features
31+
url = { version = "2.5", optional = true }
2232

2333
[lints]
2434
workspace = true
25-

crates/ironrdp-tokio/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#[rustfmt::skip] // do not re-order this pub use
55
pub use ironrdp_async::*;
66

7+
#[cfg(feature = "reqwest")]
8+
pub mod reqwest;
9+
710
use core::pin::Pin;
811
use std::io;
912

crates/ironrdp-client/src/network_client.rs renamed to crates/ironrdp-tokio/src/reqwest.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ use core::future::Future;
22
use core::pin::Pin;
33
use std::net::{IpAddr, Ipv4Addr};
44

5-
use ironrdp::connector::{custom_err, ConnectorResult};
6-
use ironrdp_tokio::AsyncNetworkClient;
5+
use ironrdp_async::ironrdp_connector::{custom_err, ConnectorResult};
76
use reqwest::Client;
87
use sspi::{Error, ErrorKind};
98
use tokio::io::{AsyncReadExt, AsyncWriteExt};
109
use tokio::net::{TcpStream, UdpSocket};
1110
use url::Url;
1211

13-
pub(crate) struct ReqwestNetworkClient {
12+
use crate::AsyncNetworkClient;
13+
14+
pub struct ReqwestNetworkClient {
1415
client: Option<Client>,
1516
}
1617

@@ -32,11 +33,17 @@ impl AsyncNetworkClient for ReqwestNetworkClient {
3233
}
3334

3435
impl ReqwestNetworkClient {
35-
pub(crate) fn new() -> Self {
36+
pub fn new() -> Self {
3637
Self { client: None }
3738
}
3839
}
3940

41+
impl Default for ReqwestNetworkClient {
42+
fn default() -> Self {
43+
Self::new()
44+
}
45+
}
46+
4047
impl ReqwestNetworkClient {
4148
async fn send_tcp(&self, url: &Url, data: &[u8]) -> ConnectorResult<Vec<u8>> {
4249
let addr = format!("{}:{}", url.host_str().unwrap_or_default(), url.port().unwrap_or(88));
@@ -89,10 +96,12 @@ impl ReqwestNetworkClient {
8996
.recv(&mut buf)
9097
.await
9198
.map_err(|e| custom_err!("failed to receive UDP request", e))?;
99+
let buf = &buf[0..n];
92100

93101
let mut reply_buf = Vec::with_capacity(n + 4);
94-
reply_buf.extend_from_slice(&(n as u32).to_be_bytes());
95-
reply_buf.extend_from_slice(&buf[0..n]);
102+
let n = u32::try_from(n).map_err(|e| custom_err!("invalid length", e))?;
103+
reply_buf.extend_from_slice(&n.to_be_bytes());
104+
reply_buf.extend_from_slice(buf);
96105

97106
Ok(reply_buf)
98107
}

0 commit comments

Comments
 (0)