Skip to content

Commit 29a0d45

Browse files
committed
Remove urlencoding dependence
Create a new function percent_encode_string to encode entire strings. Use this instead of urlencoding::encode.
1 parent 77cf501 commit 29a0d45

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

bitreq/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ rust-version = "1.75.0"
1616
maintenance = { status = "experimental" }
1717

1818
[dependencies]
19-
# For the urlencoding feature:
20-
urlencoding = { version = "2.1.0", optional = true }
2119
# For the punycode feature:
2220
punycode = { version = "0.4.1", optional = true }
2321
# For the json-using-serde feature:
@@ -53,6 +51,7 @@ json-using-serde = ["serde", "serde_json"]
5351
proxy = ["base64", "std"]
5452
async = ["tokio", "std"]
5553
async-https = ["async", "https-rustls", "tokio-rustls"]
54+
urlencoding = []
5655

5756
[[example]]
5857
name = "hello"

bitreq/src/http_url.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,13 @@ pub(crate) fn percent_encode_char(c: char, result: &mut String) {
201201
}
202202
}
203203
}
204+
205+
/// Percent-encodes the entire input string and returns the encoded version.
206+
#[cfg(feature = "urlencoding")]
207+
pub(crate) fn percent_encode_string(input: &str) -> String {
208+
let mut encoded = String::with_capacity(input.len());
209+
for ch in input.chars() {
210+
percent_encode_char(ch, &mut encoded);
211+
}
212+
encoded
213+
}

bitreq/src/request.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use core::fmt::Write;
77
use crate::connection::AsyncConnection;
88
#[cfg(feature = "std")]
99
use crate::connection::Connection;
10+
#[cfg(feature = "urlencoding")]
11+
use crate::http_url::percent_encode_string;
1012
#[cfg(feature = "std")]
1113
use crate::http_url::{HttpUrl, Port};
1214
#[cfg(feature = "proxy")]
@@ -159,10 +161,10 @@ impl Request {
159161
pub fn with_param<T: Into<String>, U: Into<String>>(mut self, key: T, value: U) -> Request {
160162
let key = key.into();
161163
#[cfg(feature = "urlencoding")]
162-
let key = urlencoding::encode(&key);
164+
let key = percent_encode_string(&key);
163165
let value = value.into();
164166
#[cfg(feature = "urlencoding")]
165-
let value = urlencoding::encode(&value);
167+
let value = percent_encode_string(&value);
166168

167169
if !self.params.is_empty() {
168170
self.params.push('&');

0 commit comments

Comments
 (0)