1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
//! HTTP utility functions
//!
//! This module provides comprehensive HTTP client utilities,
//! inspired by Hutool's HttpUtil.
use crate::error::{Error, Result};
use reqwest::{Client, Method, Response, StatusCode, Url};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::time::Duration;
use tokio::fs::File;
use tokio::io::AsyncWriteExt;
/// HTTP utility functions
pub struct HttpUtil;
impl HttpUtil {
/// Create a new HTTP client with default configuration
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let client = HttpUtil::client();
/// Ok(())
/// }
/// ```
pub fn client() -> Client {
Client::builder()
.timeout(Duration::from_secs(30))
.user_agent("rutool/0.1.0")
.build()
.unwrap()
}
/// Create a new HTTP client with custom timeout
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
/// use std::time::Duration;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let client = HttpUtil::client_with_timeout(Duration::from_secs(60));
/// Ok(())
/// }
/// ```
pub fn client_with_timeout(timeout: Duration) -> Client {
Client::builder()
.timeout(timeout)
.user_agent("rutool/0.1.0")
.build()
.unwrap()
}
/// Perform a simple GET request
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let response = HttpUtil::get("https://httpbin.org/get").await?;
/// println!("Status: {}", response.status());
/// Ok(())
/// }
/// ```
pub async fn get(url: &str) -> Result<Response> {
let client = Self::client();
client
.get(url)
.send()
.await
.map_err(|e| Error::Http(e))
}
/// Perform a GET request and return response as text
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let text = HttpUtil::get_text("https://httpbin.org/get").await?;
/// println!("Response: {}", text);
/// Ok(())
/// }
/// ```
pub async fn get_text(url: &str) -> Result<String> {
let response = Self::get(url).await?;
response
.text()
.await
.map_err(|e| Error::Http(e))
}
/// Perform a GET request and return response as JSON
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
/// use serde::{Deserialize, Serialize};
///
/// #[derive(Deserialize)]
/// struct ApiResponse {
/// url: String,
/// }
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let response: ApiResponse = HttpUtil::get_json("https://httpbin.org/get").await?;
/// println!("URL: {}", response.url);
/// Ok(())
/// }
/// ```
pub async fn get_json<T: for<'de> Deserialize<'de>>(url: &str) -> Result<T> {
let response = Self::get(url).await?;
response
.json()
.await
.map_err(|e| Error::Http(e))
}
/// Perform a simple POST request with JSON body
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
/// use serde_json::json;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let payload = json!({"key": "value"});
/// let response = HttpUtil::post_json("https://httpbin.org/post", &payload).await?;
/// println!("Status: {}", response.status());
/// Ok(())
/// }
/// ```
pub async fn post_json<T: Serialize>(url: &str, json: &T) -> Result<Response> {
let client = Self::client();
client
.post(url)
.json(json)
.send()
.await
.map_err(|e| Error::Http(e))
}
/// Perform a POST request with form data
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
/// use std::collections::HashMap;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let mut form = HashMap::new();
/// form.insert("key", "value");
/// let response = HttpUtil::post_form("https://httpbin.org/post", &form).await?;
/// println!("Status: {}", response.status());
/// Ok(())
/// }
/// ```
pub async fn post_form(url: &str, form: &HashMap<&str, &str>) -> Result<Response> {
let client = Self::client();
client
.post(url)
.form(form)
.send()
.await
.map_err(|e| Error::Http(e))
}
/// Perform a POST request with text body
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let response = HttpUtil::post_text("https://httpbin.org/post", "Hello, World!").await?;
/// println!("Status: {}", response.status());
/// Ok(())
/// }
/// ```
pub async fn post_text(url: &str, text: &str) -> Result<Response> {
let client = Self::client();
client
.post(url)
.body(text.to_string())
.header("Content-Type", "text/plain")
.send()
.await
.map_err(|e| Error::Http(e))
}
/// Perform a PUT request with JSON body
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
/// use serde_json::json;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let payload = json!({"key": "updated_value"});
/// let response = HttpUtil::put_json("https://httpbin.org/put", &payload).await?;
/// println!("Status: {}", response.status());
/// Ok(())
/// }
/// ```
pub async fn put_json<T: Serialize>(url: &str, json: &T) -> Result<Response> {
let client = Self::client();
client
.put(url)
.json(json)
.send()
.await
.map_err(|e| Error::Http(e))
}
/// Perform a DELETE request
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let response = HttpUtil::delete("https://httpbin.org/delete").await?;
/// println!("Status: {}", response.status());
/// Ok(())
/// }
/// ```
pub async fn delete(url: &str) -> Result<Response> {
let client = Self::client();
client
.delete(url)
.send()
.await
.map_err(|e| Error::Http(e))
}
/// Perform a PATCH request with JSON body
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
/// use serde_json::json;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let payload = json!({"key": "patched_value"});
/// let response = HttpUtil::patch_json("https://httpbin.org/patch", &payload).await?;
/// println!("Status: {}", response.status());
/// Ok(())
/// }
/// ```
pub async fn patch_json<T: Serialize>(url: &str, json: &T) -> Result<Response> {
let client = Self::client();
client
.patch(url)
.json(json)
.send()
.await
.map_err(|e| Error::Http(e))
}
/// Perform a HEAD request
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let response = HttpUtil::head("https://httpbin.org/get").await?;
/// println!("Status: {}", response.status());
/// println!("Content-Length: {:?}", response.headers().get("content-length"));
/// Ok(())
/// }
/// ```
pub async fn head(url: &str) -> Result<Response> {
let client = Self::client();
client
.head(url)
.send()
.await
.map_err(|e| Error::Http(e))
}
/// Perform a request with custom method and headers
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
/// use reqwest::Method;
/// use std::collections::HashMap;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let mut headers = HashMap::new();
/// headers.insert("Authorization", "Bearer token123");
/// headers.insert("Custom-Header", "custom-value");
///
/// let response = HttpUtil::request(
/// Method::GET,
/// "https://httpbin.org/headers",
/// Some(&headers),
/// None::<&()>
/// ).await?;
/// println!("Status: {}", response.status());
/// Ok(())
/// }
/// ```
pub async fn request<T: Serialize>(
method: Method,
url: &str,
headers: Option<&HashMap<&str, &str>>,
body: Option<&T>,
) -> Result<Response> {
let client = Self::client();
let mut request = client.request(method, url);
if let Some(headers) = headers {
for (key, value) in headers {
request = request.header(*key, *value);
}
}
if let Some(body) = body {
request = request.json(body);
}
request
.send()
.await
.map_err(|e| Error::Http(e))
}
/// Download a file from URL to local path
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// HttpUtil::download_file(
/// "https://httpbin.org/json",
/// "/tmp/downloaded.json"
/// ).await?;
/// println!("File downloaded successfully");
/// Ok(())
/// }
/// ```
pub async fn download_file(url: &str, path: &str) -> Result<()> {
let response = Self::get(url).await?;
let bytes = response.bytes().await.map_err(|e| Error::Http(e))?;
let mut file = File::create(path).await.map_err(|e| Error::Io(e))?;
file.write_all(&bytes).await.map_err(|e| Error::Io(e))?;
Ok(())
}
/// Check if a URL is reachable (returns 2xx status code)
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let is_reachable = HttpUtil::is_reachable("https://httpbin.org/get").await?;
/// println!("URL reachable: {}", is_reachable);
/// Ok(())
/// }
/// ```
pub async fn is_reachable(url: &str) -> Result<bool> {
match Self::head(url).await {
Ok(response) => Ok(response.status().is_success()),
Err(_) => Ok(false),
}
}
/// Get HTTP status code for a URL
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let status = HttpUtil::get_status("https://httpbin.org/status/404").await?;
/// println!("Status code: {}", status);
/// Ok(())
/// }
/// ```
pub async fn get_status(url: &str) -> Result<StatusCode> {
let response = Self::head(url).await?;
Ok(response.status())
}
/// Get response headers for a URL
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let headers = HttpUtil::get_headers("https://httpbin.org/get").await?;
/// for (name, value) in &headers {
/// println!("{}: {}", name, value);
/// }
/// Ok(())
/// }
/// ```
pub async fn get_headers(url: &str) -> Result<HashMap<String, String>> {
let response = Self::head(url).await?;
let mut headers = HashMap::new();
for (name, value) in response.headers() {
if let Ok(value_str) = value.to_str() {
headers.insert(name.to_string(), value_str.to_string());
}
}
Ok(headers)
}
/// Perform multiple concurrent GET requests
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let urls = vec![
/// "https://httpbin.org/get",
/// "https://httpbin.org/headers",
/// "https://httpbin.org/user-agent",
/// ];
/// let responses = HttpUtil::get_multiple(&urls).await?;
/// println!("Fetched {} responses", responses.len());
/// Ok(())
/// }
/// ```
pub async fn get_multiple(urls: &[&str]) -> Result<Vec<Response>> {
let client = Self::client();
let futures: Vec<_> = urls.iter()
.map(|url| client.get(*url).send())
.collect();
let results = futures::future::join_all(futures).await;
let mut responses = Vec::new();
for result in results {
responses.push(result.map_err(|e| Error::Http(e))?);
}
Ok(responses)
}
/// Build a query string from parameters
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
/// use std::collections::HashMap;
///
/// let mut params = HashMap::new();
/// params.insert("key1", "value1");
/// params.insert("key2", "value with spaces");
///
/// let query = HttpUtil::build_query_string(¶ms);
/// println!("Query string: {}", query);
/// ```
pub fn build_query_string(params: &HashMap<&str, &str>) -> String {
use urlencoding::encode;
params.iter()
.map(|(key, value)| format!("{}={}", encode(key), encode(value)))
.collect::<Vec<_>>()
.join("&")
}
/// Parse query string into parameters
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// let query = "key1=value1&key2=value%20with%20spaces";
/// let params = HttpUtil::parse_query_string(query);
///
/// assert_eq!(params.get("key1"), Some(&"value1".to_string()));
/// assert_eq!(params.get("key2"), Some(&"value with spaces".to_string()));
/// ```
pub fn parse_query_string(query: &str) -> HashMap<String, String> {
use urlencoding::decode;
let mut params = HashMap::new();
for pair in query.split('&') {
if let Some((key, value)) = pair.split_once('=') {
if let (Ok(decoded_key), Ok(decoded_value)) = (decode(key), decode(value)) {
params.insert(decoded_key.to_string(), decoded_value.to_string());
}
}
}
params
}
/// Build a URL with query parameters
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
/// use std::collections::HashMap;
///
/// let mut params = HashMap::new();
/// params.insert("q", "rust programming");
/// params.insert("page", "1");
///
/// let url = HttpUtil::build_url("https://example.com/search", ¶ms);
/// println!("URL: {}", url);
/// ```
pub fn build_url(base_url: &str, params: &HashMap<&str, &str>) -> String {
if params.is_empty() {
return base_url.to_string();
}
let query = Self::build_query_string(params);
let separator = if base_url.contains('?') { "&" } else { "?" };
format!("{}{}{}", base_url, separator, query)
}
/// Extract domain from URL
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// let domain = HttpUtil::extract_domain("https://www.example.com/path?query=value");
/// assert_eq!(domain, Some("www.example.com".to_string()));
/// ```
pub fn extract_domain(url: &str) -> Option<String> {
if let Ok(parsed) = Url::parse(url) {
parsed.host_str().map(|s| s.to_string())
} else {
None
}
}
/// Check if URL is valid
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// assert!(HttpUtil::is_valid_url("https://www.example.com"));
/// assert!(!HttpUtil::is_valid_url("not-a-url"));
/// ```
pub fn is_valid_url(url: &str) -> bool {
Url::parse(url).is_ok()
}
}
// Blocking HTTP utilities for synchronous code
impl HttpUtil {
/// Perform a blocking GET request
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let response = HttpUtil::get_blocking("https://httpbin.org/get")?;
/// println!("Status: {}", response.status());
/// Ok(())
/// }
/// ```
pub fn get_blocking(url: &str) -> Result<reqwest::blocking::Response> {
let client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(30))
.user_agent("rutool/0.1.0")
.build()
.map_err(|e| Error::Http(e))?;
client
.get(url)
.send()
.map_err(|e| Error::Http(e))
}
/// Perform a blocking GET request and return response as text
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let text = HttpUtil::get_text_blocking("https://httpbin.org/get")?;
/// println!("Response: {}", text);
/// Ok(())
/// }
/// ```
pub fn get_text_blocking(url: &str) -> Result<String> {
let response = Self::get_blocking(url)?;
response
.text()
.map_err(|e| Error::Http(e))
}
/// Perform a blocking POST request with JSON body
///
/// # Examples
///
/// ```rust
/// use yimi_rutool::http::HttpUtil;
/// use serde_json::json;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let payload = json!({"key": "value"});
/// let response = HttpUtil::post_json_blocking("https://httpbin.org/post", &payload)?;
/// println!("Status: {}", response.status());
/// Ok(())
/// }
/// ```
pub fn post_json_blocking<T: Serialize>(url: &str, json: &T) -> Result<reqwest::blocking::Response> {
let client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(30))
.user_agent("rutool/0.1.0")
.build()
.map_err(|e| Error::Http(e))?;
client
.post(url)
.json(json)
.send()
.map_err(|e| Error::Http(e))
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::collections::HashMap;
#[test]
fn test_build_query_string() {
let mut params = HashMap::new();
params.insert("key1", "value1");
params.insert("key2", "value with spaces");
let query = HttpUtil::build_query_string(¶ms);
assert!(query.contains("key1=value1"));
assert!(query.contains("key2=value%20with%20spaces"));
}
#[test]
fn test_parse_query_string() {
let query = "key1=value1&key2=value%20with%20spaces";
let params = HttpUtil::parse_query_string(query);
assert_eq!(params.get("key1"), Some(&"value1".to_string()));
assert_eq!(params.get("key2"), Some(&"value with spaces".to_string()));
}
#[test]
fn test_build_url() {
let mut params = HashMap::new();
params.insert("q", "rust programming");
params.insert("page", "1");
let url = HttpUtil::build_url("https://example.com/search", ¶ms);
assert!(url.starts_with("https://example.com/search?"));
assert!(url.contains("q=rust%20programming"));
assert!(url.contains("page=1"));
}
#[test]
fn test_extract_domain() {
assert_eq!(
HttpUtil::extract_domain("https://www.example.com/path?query=value"),
Some("www.example.com".to_string())
);
assert_eq!(
HttpUtil::extract_domain("http://localhost:8080/api"),
Some("localhost".to_string())
);
assert_eq!(HttpUtil::extract_domain("invalid-url"), None);
}
#[test]
fn test_is_valid_url() {
assert!(HttpUtil::is_valid_url("https://www.example.com"));
assert!(HttpUtil::is_valid_url("http://localhost:8080"));
assert!(HttpUtil::is_valid_url("ftp://files.example.com"));
assert!(!HttpUtil::is_valid_url("not-a-url"));
assert!(!HttpUtil::is_valid_url(""));
}
#[test]
fn test_client_creation() {
let _client = HttpUtil::client();
// Just test that we can create a client without panicking
// Note: reqwest::Client doesn't expose user_agent() method
// We can't directly test the user agent, but we can test the client is created
assert!(true); // Client creation succeeded if we reach here
}
#[test]
fn test_client_with_timeout() {
let timeout = Duration::from_secs(60);
let _client = HttpUtil::client_with_timeout(timeout);
// Just test that we can create a client with custom timeout
assert!(true); // Client creation succeeded if we reach here
}
// Integration tests that require internet connection
#[cfg(feature = "integration_tests")]
mod integration_tests {
use super::*;
#[tokio::test]
async fn test_get_request() {
let response = HttpUtil::get("https://httpbin.org/get").await.unwrap();
assert!(response.status().is_success());
}
#[tokio::test]
async fn test_get_text() {
let text = HttpUtil::get_text("https://httpbin.org/get").await.unwrap();
assert!(!text.is_empty());
}
#[tokio::test]
async fn test_post_json() {
use serde_json::json;
let payload = json!({"key": "test_value"});
let response = HttpUtil::post_json("https://httpbin.org/post", &payload).await.unwrap();
assert!(response.status().is_success());
}
#[tokio::test]
async fn test_is_reachable() {
let reachable = HttpUtil::is_reachable("https://httpbin.org/get").await.unwrap();
assert!(reachable);
let unreachable = HttpUtil::is_reachable("https://invalid-domain-12345.com").await.unwrap();
assert!(!unreachable);
}
#[test]
fn test_blocking_get() {
let response = HttpUtil::get_blocking("https://httpbin.org/get").unwrap();
assert!(response.status().is_success());
}
}
}