Skip to content

Commit 30c81d0

Browse files
committed
feat: v8.91.88
1 parent 870a0ed commit 30c81d0

File tree

8 files changed

+35
-34
lines changed

8 files changed

+35
-34
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "http-request"
3-
version = "8.91.87"
3+
version = "8.91.88"
44
readme = "README.md"
55
edition = "2024"
66
authors = ["root@ltpp.vip"]
@@ -14,7 +14,7 @@ exclude = ["target", "Cargo.lock", "sh", ".github"]
1414
[dependencies]
1515
serde = "1.0.228"
1616
futures = "0.3.31"
17-
http-type = "11.0.0"
17+
http-type = "13.0.0"
1818
serde_json = "1.0.149"
1919
tungstenite = "0.28.0"
2020
webpki-roots = "1.0.5"

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ use {
5656
futures::{Future, Sink, SinkExt, Stream, StreamExt},
5757
http_type::{
5858
ACCEPT, ACCEPT_ANY, BR_BYTES, COLON_U8, CONNECTION, CONTENT_LENGTH, CONTENT_TYPE, Compress,
59-
ContentType, DEFAULT_BUFFER_SIZE, DEFAULT_HTTP_PATH, DEFAULT_MAX_REDIRECT_TIMES,
60-
DEFAULT_TIMEOUT, EMPTY_STR, HOST, HTTP_BR_BYTES, HttpStatus, HttpUrlComponents,
61-
HttpVersion, LOCATION, Method, Protocol, QUERY, RequestBody, RequestBodyString,
62-
RequestHeaders, ResponseHeaders, ResponseStatusCode, SEC_WEBSOCKET_KEY,
59+
ContentType, DEFAULT_BUFFER_SIZE, DEFAULT_HIGH_SECURITY_HTTP_READ_TIMEOUT_MS,
60+
DEFAULT_HTTP_PATH, DEFAULT_MAX_REDIRECT_TIMES, EMPTY_STR, HOST, HTTP_BR_BYTES, HttpStatus,
61+
HttpUrlComponents, HttpVersion, LOCATION, Method, Protocol, QUERY, RequestBody,
62+
RequestBodyString, RequestHeaders, ResponseHeaders, ResponseStatusCode, SEC_WEBSOCKET_KEY,
6363
SEC_WEBSOCKET_VERSION, SPACE_U8, TAB_U8, UPGRADE, USER_AGENT,
6464
tokio::{
6565
io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf},

src/request/config/impl.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@ use crate::*;
44
///
55
/// # Returns
66
///
7-
/// - `Config` - A configuration instance with default values:
8-
/// - timeout: DEFAULT_TIMEOUT
9-
/// - redirect: false
10-
/// - max_redirect_times: DEFAULT_MAX_REDIRECT_TIMES
11-
/// - buffer: DEFAULT_BUFFER_SIZE
12-
/// - decode: true
7+
/// - `Config` - A configuration instance with default values
138
impl Default for Config {
149
#[inline(always)]
1510
fn default() -> Self {
1611
Self {
17-
timeout: DEFAULT_TIMEOUT,
12+
timeout: DEFAULT_HIGH_SECURITY_HTTP_READ_TIMEOUT_MS,
1813
url_obj: HttpUrlComponents::default(),
1914
redirect: false,
2015
max_redirect_times: DEFAULT_MAX_REDIRECT_TIMES,

src/request/http_request/impl.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use http_type::HTTPS_LOWERCASE;
2+
13
use crate::*;
24

35
/// Blanket implementation for AsyncReadWrite trait.
@@ -100,10 +102,10 @@ impl HttpRequest {
100102
///
101103
/// # Returns
102104
///
103-
/// - `Protocol` - The HTTP protocol.
105+
/// - `String` - The HTTP protocol.
104106
#[inline(always)]
105-
pub(crate) fn get_protocol(config: &Config) -> Protocol {
106-
config.url_obj.protocol.clone()
107+
pub(crate) fn get_protocol(config: &Config) -> String {
108+
config.url_obj.protocol.to_lowercase()
107109
}
108110

109111
/// Gets the HTTP methods.
@@ -567,8 +569,8 @@ impl HttpRequest {
567569
if port != 0 {
568570
return port;
569571
}
570-
let protocol: Protocol = Self::get_protocol(config);
571-
protocol.get_port()
572+
let protocol: String = Self::get_protocol(config);
573+
Protocol::get_port(&protocol)
572574
}
573575

574576
/// Establishes a connection stream to the specified host and port.
@@ -612,7 +614,7 @@ impl HttpRequest {
612614
.set_write_timeout(Some(timeout))
613615
.map_err(|error| RequestError::Request(error.to_string()))?;
614616
let stream: Result<Box<dyn ReadWrite>, RequestError> =
615-
if Self::get_protocol(&config).is_https() {
617+
if Self::get_protocol(&config) == HTTPS_LOWERCASE {
616618
match self.tmp.clone().read() {
617619
Ok(tmp) => {
618620
let roots: RootCertStore = tmp.root_cert.clone();
@@ -647,7 +649,9 @@ impl HttpRequest {
647649
let timeout: Duration = Duration::from_millis(
648650
self.config
649651
.read()
650-
.map_or(DEFAULT_TIMEOUT, |config| config.timeout),
652+
.map_or(DEFAULT_HIGH_SECURITY_HTTP_READ_TIMEOUT_MS, |config| {
653+
config.timeout
654+
}),
651655
);
652656
match proxy_config.proxy_type {
653657
ProxyType::Http | ProxyType::Https => {
@@ -744,7 +748,7 @@ impl HttpRequest {
744748
.config
745749
.read()
746750
.map_or(Config::default(), |config| config.clone());
747-
if Self::get_protocol(&config).is_https() {
751+
if Self::get_protocol(&config) == HTTPS_LOWERCASE {
748752
match self.tmp.clone().read() {
749753
Ok(tmp) => {
750754
let roots: RootCertStore = tmp.root_cert.clone();
@@ -894,7 +898,7 @@ impl HttpRequest {
894898
.config
895899
.read()
896900
.map_or(Config::default(), |config| config.clone());
897-
if Self::get_protocol(&config).is_https() {
901+
if Self::get_protocol(&config) == HTTPS_LOWERCASE {
898902
match self.tmp.clone().read() {
899903
Ok(tmp) => {
900904
let roots: RootCertStore = tmp.root_cert.clone();
@@ -1184,7 +1188,7 @@ impl HttpRequest {
11841188
let tcp_stream: AsyncTcpStream = AsyncTcpStream::connect(host_port.clone())
11851189
.await
11861190
.map_err(|error| RequestError::Request(error.to_string()))?;
1187-
if Self::get_protocol(&config).is_https() {
1191+
if Self::get_protocol(&config) == HTTPS_LOWERCASE {
11881192
let roots: RootCertStore = {
11891193
match self.tmp.clone().read() {
11901194
Ok(tmp) => tmp.root_cert.clone(),
@@ -1329,7 +1333,7 @@ impl HttpRequest {
13291333
.config
13301334
.read()
13311335
.map_or(Config::default(), |config| config.clone());
1332-
if Self::get_protocol(&config).is_https() {
1336+
if Self::get_protocol(&config) == HTTPS_LOWERCASE {
13331337
let roots: RootCertStore = {
13341338
match self.tmp.clone().read() {
13351339
Ok(tmp) => tmp.root_cert.clone(),
@@ -1497,7 +1501,7 @@ impl HttpRequest {
14971501
.config
14981502
.read()
14991503
.map_or(Config::default(), |config| config.clone());
1500-
if Self::get_protocol(&config).is_https() {
1504+
if Self::get_protocol(&config) == HTTPS_LOWERCASE {
15011505
let roots: RootCertStore = {
15021506
match self.tmp.clone().read() {
15031507
Ok(tmp) => tmp.root_cert.clone(),

src/request/socket/config/impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ impl Default for WebSocketConfig {
44
#[inline(always)]
55
fn default() -> Self {
66
Self {
7-
timeout: DEFAULT_TIMEOUT,
7+
timeout: DEFAULT_HIGH_SECURITY_HTTP_READ_TIMEOUT_MS,
88
url_obj: HttpUrlComponents::default(),
99
buffer: DEFAULT_BUFFER_SIZE,
1010
protocols: Vec::new(),

src/request/socket/shared/impl.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
use http_type::{HTTP_LOWERCASE, HTTP_UPPERCASE};
2+
13
use crate::*;
24

35
impl std::fmt::Display for WebSocketError {
46
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
57
match self.kind {
68
WebSocketErrorKind::Connection => write!(f, "Connection error: {}", self.message),
7-
WebSocketErrorKind::Protocol => write!(f, "Protocol error: {}", self.message),
9+
WebSocketErrorKind::String => write!(f, "String error: {}", self.message),
810
WebSocketErrorKind::Timeout => write!(f, "Timeout error: {}", self.message),
911
WebSocketErrorKind::InvalidUrl => write!(f, "Invalid URL: {}", self.message),
1012
WebSocketErrorKind::Io => write!(f, "IO error: {}", self.message),
@@ -25,7 +27,7 @@ impl WebSocketError {
2527

2628
pub(crate) fn protocol<T: ToString>(message: T) -> Self {
2729
Self {
28-
kind: WebSocketErrorKind::Protocol,
30+
kind: WebSocketErrorKind::String,
2931
message: message.to_string(),
3032
}
3133
}
@@ -66,10 +68,10 @@ impl SharedWebSocketBuilder {
6668
}
6769
let mut url_obj: HttpUrlComponents = HttpUrlComponents::default();
6870
if url.starts_with("ws://") {
69-
url_obj.protocol = Protocol::Http;
71+
url_obj.protocol = HTTP_LOWERCASE.to_string();
7072
url_obj.port = Some(80);
7173
} else if url.starts_with("wss://") {
72-
url_obj.protocol = Protocol::Https;
74+
url_obj.protocol = HTTP_UPPERCASE.to_string();
7375
url_obj.port = Some(443);
7476
} else {
7577
return Err(WebSocketError::invalid_url("Invalid WebSocket URL scheme"));

src/request/socket/shared/struct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct WebSocketError {
1212
#[derive(Debug, Clone, PartialEq)]
1313
pub enum WebSocketErrorKind {
1414
Connection,
15-
Protocol,
15+
String,
1616
Timeout,
1717
InvalidUrl,
1818
Io,

src/request/socket/websocket/impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl WebSocket {
4444
self.config
4545
.read()
4646
.map(|c| c.timeout)
47-
.unwrap_or(DEFAULT_TIMEOUT),
47+
.unwrap_or(DEFAULT_HIGH_SECURITY_HTTP_READ_TIMEOUT_MS),
4848
);
4949
let headers: Vec<(String, String)> = self.get_headers();
5050
let mut request_builder = Request::builder().uri(&url);
@@ -89,7 +89,7 @@ impl WebSocket {
8989
.unwrap_or_default();
9090
if !protocols.is_empty() {
9191
proxy_request_builder =
92-
proxy_request_builder.header("Sec-WebSocket-Protocol", protocols.join(", "));
92+
proxy_request_builder.header("Sec-WebSocket-String", protocols.join(", "));
9393
}
9494
let proxy_request: Request = proxy_request_builder.body(()).map_err(|e| {
9595
WebSocketError::invalid_url(format!("Failed to build proxy request: {e}"))
@@ -171,7 +171,7 @@ impl WebSocket {
171171
self.config
172172
.read()
173173
.map(|c| c.timeout)
174-
.unwrap_or(DEFAULT_TIMEOUT),
174+
.unwrap_or(DEFAULT_HIGH_SECURITY_HTTP_READ_TIMEOUT_MS),
175175
);
176176
let mut connection: AsyncMutexGuard<'_, Option<WebSocketConnectionType>> =
177177
self.connection.lock().await;

0 commit comments

Comments
 (0)