bt_http_utils 0.8.0

A simple HTTP wrapper to simplify POST and GET calls. Default headers with set and get headers. Support cookies. Request generic function for GET, POST, PUT, PATCH, and DELETE.
Documentation
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
#[cfg(test)]
mod http_utils_tests {
use std::collections::HashMap;

use bt_http_utils::{self, ContentType, HttpClient, DANGER_ACCEPT_INVALID_CERTS, DANGER_ACCEPT_INVALID_HOSTNAMES};
use bt_logger::{LogLevel, LogTarget, build_logger, log_verbose};

#[cfg(test)]
const SERVER: &str = "://localhost";

#[tokio::test]
async fn test_streaming_post(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    let url = "http://localhost:11434/api/chat";
    let http_client = HttpClient::new(false, true, None);
    let param = "{\"model\": \"deepseek-r1-tool:latest\",\"messages\":[{\"role\": \"user\",\"content\": \"Write a hello world program in Rust\"}]}";
    let resp = http_client.post_stream(url, None, param, ContentType::JSON).await;
    let mut r = resp.unwrap();
    let hr = r.read_stream().await.unwrap();
    println!("Ans: {:?}",hr);
    assert_eq!(hr.is_error(), false);
    assert!(hr.body.len() > 0);
}

#[tokio::test]
async fn test_post_stream_unknown_ep(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    let url = "http://localhost:11434/api/unknown";
    let http_client = HttpClient::new(false, true, None);
    let param = "{\"nothing\":\"nothing\"}";
    let resp = http_client.post_stream(url, None, param, ContentType::JSON).await;
    let mut r = resp.unwrap();
    let hr = r.read_stream().await.unwrap();
    println!("Ans: {:?}",&hr);
    assert_eq!(hr.is_error(), true);
    assert_eq!(hr.body,"ERROR: Failed to read stream response from http://localhost:11434/api/unknown. Status: Not Found.");
}

#[tokio::test]
async fn test_post_stream_reach_end(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    let url = "http://localhost:11434/api/chat";
    let http_client = HttpClient::new(false, true, None);
    let param = "{\"model\": \"deepseek-r1-tool:latest\",\"messages\":[{\"role\": \"user\",\"content\": \"Write a hello world program in Rust\"}]}";
    let resp = http_client.post_stream(url, None, param, ContentType::JSON).await;
    //println!("RESP: {:?}",&resp);
    let mut r = resp.unwrap();
    //println!("R: {:?}",&r);
    //let hr = r.read_stream().await.unwrap();
    while let Some(hr) = r.read_stream().await{
        //println!("HR: {:?}",&hr);
        assert_eq!(hr.is_error(), false);
        assert!(hr.body.len() > 0);
    }
}

#[tokio::test]
async fn test_request_err_notfound_no_hickory(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let url = format!("{}{}/uh/api.php","http",SERVER);

    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.request("get",&url, None, None, None, ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().status_code,404);
}

#[tokio::test]
async fn test_request_err_missparam_no_hickory(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let url = format!("{}{}/uh/api.php/posts/","http",SERVER);

    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.request("post",&url, None, None, None, ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().status_code,400);
}

#[tokio::test]
async fn test_request_post_no_hickory(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let url = format!("{}{}/uh/api.php/users/","http",SERVER);

    let mut param: HashMap<String, String> = HashMap::new();
    param.insert("name".to_string(), "C.Brown".to_string());
    let test_content = "{\"id\":3,\"name\":\"C.Brown\"}";

    let http_client = HttpClient::new(false, true, None);

    let resp = http_client.request("post",&url, None, Some(param), None, ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}


#[tokio::test]
async fn test_request_post_all(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let url = format!("{}{}/test/param.php/{{name}}/","http",SERVER);

    let mut param: HashMap<String, String> = HashMap::new();
    param.insert("name".to_string(), "omega".to_string());
    param.insert("lastname".to_string(),"alpha".to_string());
    let mut bodyp: HashMap<String, String> = HashMap::new();
    bodyp.insert("age".to_string(), "25".to_string());
    let mut headerp: HashMap<String, String> = HashMap::new();
    headerp.insert("key".to_string(), "Key1".to_string());

    let test_content = "Key: Key1, Name: omega, Last Name: No last name provided, Age: 25";

    let http_client = HttpClient::new(false, true, None);

    let resp = http_client.request("post",&url, Some(headerp), Some(bodyp), Some(param), ContentType::TEXT).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_request_get_all(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let url = format!("{}{}/test/param.php/{{name}}/","http",SERVER);

    let mut param: HashMap<String, String> = HashMap::new();
    param.insert("name".to_string(), "omega".to_string());
    param.insert("lastname".to_string(),"alpha".to_string());
    let mut bodyp: HashMap<String, String> = HashMap::new();
    bodyp.insert("age".to_string(), "25".to_string());
    let mut headerp: HashMap<String, String> = HashMap::new();
    headerp.insert("key".to_string(), "Key1".to_string());

    let test_content = "Key: Key1, Name: omega, Last Name: alpha, Age: No age provided";

    let http_client = HttpClient::new(false, true, None);

    let resp = http_client.request("get",&url, Some(headerp), Some(bodyp), Some(param), ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_request_get_sec(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    let url = "https://www.bachuetech.biz/";
    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.request("get",&url, None, None, None, ContentType::TEXT).await;
    //println!("Body: {:?}",&resp);
    assert!(resp.is_ok());
    assert!(resp.unwrap().body.len() > 0);
}

#[tokio::test]
async fn test_request_post_text_no_hickory_sec_only(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS_TEST", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    //env_logger::init();
    //tracing_subscriber::fmt::init();

    let url = format!("{}{}:8081/uh/apitxt1.php/users/","https",SERVER);

    let mut param: HashMap<String, String> = HashMap::new();
    param.insert("name".to_string(), "John".to_string());
    param.insert("last_name".to_string(), "Smith".to_string());
    let test_content = "John Smith";
    let dar = vec![(DANGER_ACCEPT_INVALID_HOSTNAMES.to_string() , true),(DANGER_ACCEPT_INVALID_CERTS.to_owned(), true)];

    let http_client = HttpClient::new(false, true, Some(dar));

    let resp = http_client.request("post",&url, None, Some(param), None, ContentType::TEXT).await;
    log_verbose!("test_request_post_text_no_hickory_sec_only","Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_request_post_text_no_hickory_sec_invalid(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    //env_logger::init();
    //tracing_subscriber::fmt::init();

    let url = format!("{}{}:8081/uh/apitxt1.php/users/","https",SERVER);

    let mut param: HashMap<String, String> = HashMap::new();
    param.insert("name".to_string(), "John".to_string());
    param.insert("last_name".to_string(), "Smith".to_string());
    let test_content = "John Smith";
    let dar = vec![(DANGER_ACCEPT_INVALID_CERTS.to_string(), true), ("invalid_key".to_string(),true)];

    let http_client = HttpClient::new(false, true, Some(dar));

    let resp = http_client.request("post",&url, None, Some(param), None, ContentType::TEXT).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_request_post_text_no_hickory(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let url = format!("{}{}/uh/apitxt1.php/users/","http",SERVER);

    let mut param: HashMap<String, String> = HashMap::new();
    param.insert("name".to_string(), "John".to_string());
    param.insert("last_name".to_string(), "Smith".to_string());
    let test_content = "John Smith";

    let http_client = HttpClient::new(false, true, None);

    let resp = http_client.request("post",&url, None, Some(param), None, ContentType::TEXT).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_request_delete_direct_param_no_hickory(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "{\"status\":\"success\",\"message\":\"User deleted\"}";
    let url = format!("{}{}/uh/api.php/delete/1","http",SERVER);

    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.request("delete",&url, None, None, None, ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_request_delete_qry_param_no_hickory(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "{\"status\":\"success\",\"message\":\"User deleted\"}";
    let mut param: HashMap<String, String> = HashMap::new();
    param.insert("userid".to_string(), "1".to_string());
    let url = format!("{}{}/uh/api.php/delete/{{userid}}","http",SERVER);

    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.request("delete",&url, None, None, Some(param), ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_request_get_noparam_no_hickory(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "[{\"id\":1,\"userId\":1},{\"id\":2,\"userId\":2}]";
    let url = format!("{}{}/uh/api.php/get","http",SERVER);

    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.request("get",&url, None, None, None, ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_request_put_with_direct_param_no_hickory(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "[{\"id\":3,\"userId\":2,\"title\":\"Write Documentation\",\"completed\":false}]";
    let url = format!("{}{}/uh/api.php/todos/2","http",SERVER);

    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.request("put",&url, None, None, None, ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_request_patch_with_direct_param_no_hickory(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "[{\"id\":3,\"userId\":2,\"title\":\"Write Documentation\",\"completed\":false}]";
    let url = format!("{}{}/uh/api.php/todos/2","http",SERVER);

    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.request("patch",&url, None, None, None, ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_request_get_with_direct_param_no_hickory(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "{\"id\":2,\"userId\":2}";
    let url = format!("{}{}/uh/api.php/get/2","http",SERVER);

    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.request("get",&url, None, None, None, ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_request_get_qry_param_no_hickory(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "{\"id\":2,\"userId\":2}";
    let mut param: HashMap<String, String> = HashMap::new();
    param.insert("id".to_string(), "2".to_string());

    let url = format!("{}{}/uh/api.php/get/{{id}}","http",SERVER);

    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.request("get",&url, None, None, Some(param), ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_request_get_extra_qry_param_no_hickory(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "{\"id\":2,\"userId\":2}";
    let mut param: HashMap<String, String> = HashMap::new();
    param.insert("id".to_string(), "2".to_string());
    param.insert("qry".to_string(), "Extra".to_string());

    let url = format!("{}{}/uh/api.php/get/{{id}}/","http",SERVER);

    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.request("get",&url, None, None, Some(param), ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_plain_get_no_hickory(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "Hello World! to Bachuetech!";
    let url = format!("{}{}/test_get.php?name=Bachuetech","http",SERVER);

    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.get(&url, None).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}


#[tokio::test]
async fn test_plain_get_no_hickory_new_header(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "Hello World!";
    let url = format!("{}{}/test_get.html","http",SERVER);
    let mut extra: HashMap<String, String> = HashMap::new();
    extra.insert("btai_session_id".to_string(), "A_12dkk3dsd".to_string());

    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.get(&url, Some(extra)).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}


#[tokio::test]
async fn test_plain_get_hickory_new_header(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "Hello World! BachueTech!";
    let url = format!("{}{}/test_get.php","http",SERVER);
    let mut extra: HashMap<String, String> = HashMap::new();
    extra.insert("Last-Name".to_string(), "BachueTech".to_string());

    let http_client = HttpClient::new(true, true, None);
    let resp = http_client.get(&url, Some(extra)).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_plain_get_hickory_new_header_chk(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "hello BachueTech";
    let url = format!("{}{}/test_get.php","http",SERVER);
    let mut extra: HashMap<String, String> = HashMap::new();
    extra.insert("Last-Name".to_string(), "BachueTech".to_string());

    let http_client = HttpClient::new(true, true, None);
    let resp = http_client.get(&url, Some(extra)).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().header.get("answer").unwrap(),test_content);
}

#[tokio::test]
async fn test_plain_get_hickory(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "Hello World!";
    let url = format!("{}{}/test_get.html","http",SERVER);

    let http_client = HttpClient::new(true, true, None);
    let resp = http_client.get(&url, None).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_plain_get_dns_fail(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.get("http://http://www.google.com/page/", None).await;
    println!("Staus: {:?}",&resp);
    assert_eq!(resp.is_err(),true);
}

#[tokio::test]
async fn test_plain_get_fail(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let http_client = HttpClient::new(false, true, None);
    let resp = http_client.get("http:/www.google.com/page/", None).await;
    println!("Staus: {:?}",&resp);
    assert_eq!(resp.unwrap().is_error(),true);
}

#[tokio::test]
async fn test_json_post_hickory(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "Hello Bachuetech";
    let body = "{\"name\":\"Bachuetech\"}";
    let url = format!("{}{}/test_post.php","http",SERVER);

    let http_client = HttpClient::new(true, true, None);
    let resp = http_client.post(&url, None, body, ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_text_post_hickory(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "Hello Bachuetech";
    let body = "{\"name\":\"Bachuetech\"}";
    let url = format!("{}{}/test_post.php","http",SERVER);

    let http_client = HttpClient::new(true, true, None);
    let resp = http_client.post(&url, None, body, ContentType::TEXT).await;
    println!("Body: {:?}",&resp); 


    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_text_post_hickory_extra_headers(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "Hello Bachuetech";
    let body = "{\"name\":\"Bachuetech\"}";
    let url = format!("{}{}/test_post.php","http",SERVER);

    let mut extra: HashMap<String, String> = HashMap::new();
    extra.insert("btai_session_id".to_string(), "A_12dkk3dsd".to_string());

    let http_client = HttpClient::new(true, true, None);
    let resp = http_client.post(&url, Some(extra), body, ContentType::TEXT).await;
    println!("Body: {:?}",&resp); 


    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_json_post_hickory_fail(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );

    let url = format!("{}{}/test_post_fake.php","http",SERVER);

    let http_client = HttpClient::new(true, true, None);
    let resp = http_client.post(&url, None, "", ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().is_error(),true);
}

#[test]
fn test_set_headers(){
    let header_val =  "HEADER_VALUE";
    let header_name = "bt_header";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    let mut http_client = HttpClient::new(false, true, None);
    http_client.set_header(&header_name, &header_val);

    println!("Headers: {:?}",&http_client.get_default_headers());
    assert_eq!(http_client.get_default_headers().get(header_name).unwrap(),header_val); 
}

#[test]
fn test_change_headers(){
    let header_val =  "HEADER_VALUE";
    let header_name = "user-agent";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    let mut http_client = HttpClient::new(false, true, None);
    http_client.set_header(&header_name, &header_val);

    println!("Headers: {:?}",&http_client.get_default_headers());
    assert_eq!(http_client.get_default_headers().get(header_name).unwrap(),header_val); 
}

//NO COOKIES TESTS
#[tokio::test]
async fn test_plain_get_no_hickory_nc(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "Hello World!";
    let url = format!("{}{}/test_get.html","http",SERVER);

    let http_client = HttpClient::new(false, false, None);
    let resp = http_client.get(&url, None).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_plain_get_hickory_nc(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "Hello World!";
    let url = format!("{}{}/test_get.html","http",SERVER);

    let http_client = HttpClient::new(true, false, None);
    let resp = http_client.get(&url, None).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_plain_get_dns_fail_nc(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let http_client = HttpClient::new(false, false, None);
    let resp = http_client.get("http://http://www.google.com/page/", None).await;
    println!("Staus: {:?}",&resp);
    assert_eq!(resp.is_err(),true);
}

#[tokio::test]
async fn test_plain_get_fail_nc(){
    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let http_client = HttpClient::new(false, false, None);
    let resp = http_client.get("http:/www.google.com/page/", None).await;
    println!("Staus: {:?}",&resp);
    assert_eq!(resp.unwrap().is_error(),true);
}

#[tokio::test]
async fn test_json_post_hickory_nc(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "Hello Bachuetech";
    let body = "{\"name\":\"Bachuetech\"}";
    let url = format!("{}{}/test_post.php","http",SERVER);

    let http_client = HttpClient::new(true, false, None);
    let resp = http_client.post(&url, None, body, ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_text_post_hickory_nc(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    
    let test_content = "Hello Bachuetech";
    let body = "{\"name\":\"Bachuetech\"}";
    let url = format!("{}{}/test_post.php","http",SERVER);

    let http_client = HttpClient::new(true, false, None);
    let resp = http_client.post(&url, None, body, ContentType::TEXT).await;
    println!("Body: {:?}",&resp); 


    assert_eq!(resp.unwrap().body,test_content);
}

#[tokio::test]
async fn test_json_post_hickory_fail_nc(){
    //const SERVER: &str = "http://localhost";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );

    let url = format!("{}{}/test_post_fake.php","http",SERVER);

    let http_client = HttpClient::new(true, false, None);
    let resp = http_client.post(&url, None, "", ContentType::JSON).await;
    println!("Body: {:?}",&resp);
    assert_eq!(resp.unwrap().is_error(),true);
}

#[test]
fn test_set_headers_nc(){
    let header_val =  "HEADER_VALUE";
    let header_name = "bt_header";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    let mut http_client = HttpClient::new(false, false, None);
    http_client.set_header(&header_name, &header_val);

    println!("Headers: {:?}",&http_client.get_default_headers());
    assert_eq!(http_client.get_default_headers().get(header_name).unwrap(),header_val); 
}

#[test]
fn test_change_headers_nc(){
    let header_val =  "HEADER_VALUE";
    let header_name = "user-agent";

    build_logger("BACHUETECH", "BT.HTTP.UTILS", LogLevel::VERBOSE, LogTarget::STD_ERROR, None );
    let mut http_client = HttpClient::new(false, false, None);
    http_client.set_header(&header_name, &header_val);

    println!("Headers: {:?}",&http_client.get_default_headers());
    assert_eq!(http_client.get_default_headers().get(header_name).unwrap(),header_val); 
}
}