@@ -5,8 +5,9 @@ use cargo_util::{registry::make_dep_path, Sha256};
5
5
use flate2:: write:: GzEncoder ;
6
6
use flate2:: Compression ;
7
7
use std:: collections:: { BTreeMap , HashMap } ;
8
+ use std:: fmt;
8
9
use std:: fs:: { self , File } ;
9
- use std:: io:: { BufRead , BufReader , Write } ;
10
+ use std:: io:: { BufRead , BufReader , Read , Write } ;
10
11
use std:: net:: { SocketAddr , TcpListener , TcpStream } ;
11
12
use std:: path:: { Path , PathBuf } ;
12
13
use std:: thread;
@@ -466,15 +467,28 @@ impl Drop for HttpServerHandle {
466
467
}
467
468
468
469
/// Request to the test http server
469
- #[ derive( Debug ) ]
470
470
pub struct Request {
471
471
pub url : Url ,
472
472
pub method : String ,
473
+ pub body : Option < Vec < u8 > > ,
473
474
pub authorization : Option < String > ,
474
475
pub if_modified_since : Option < String > ,
475
476
pub if_none_match : Option < String > ,
476
477
}
477
478
479
+ impl fmt:: Debug for Request {
480
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
481
+ // body is not included as it can produce long debug outputs
482
+ f. debug_struct ( "Request" )
483
+ . field ( "url" , & self . url )
484
+ . field ( "method" , & self . method )
485
+ . field ( "authorization" , & self . authorization )
486
+ . field ( "if_modified_since" , & self . if_modified_since )
487
+ . field ( "if_none_match" , & self . if_none_match )
488
+ . finish ( )
489
+ }
490
+ }
491
+
478
492
/// Response from the test http server
479
493
pub struct Response {
480
494
pub code : u32 ,
@@ -539,6 +553,7 @@ impl HttpServer {
539
553
let mut if_modified_since = None ;
540
554
let mut if_none_match = None ;
541
555
let mut authorization = None ;
556
+ let mut content_len = None ;
542
557
loop {
543
558
line. clear ( ) ;
544
559
if buf. read_line ( & mut line) . unwrap ( ) == 0 {
@@ -556,15 +571,26 @@ impl HttpServer {
556
571
"if-modified-since" => if_modified_since = Some ( value) ,
557
572
"if-none-match" => if_none_match = Some ( value) ,
558
573
"authorization" => authorization = Some ( value) ,
574
+ "content-length" => content_len = Some ( value) ,
559
575
_ => { }
560
576
}
561
577
}
578
+
579
+ let mut body = None ;
580
+ if let Some ( con_len) = content_len {
581
+ let len = con_len. parse :: < u64 > ( ) . unwrap ( ) ;
582
+ let mut content = vec ! [ 0u8 ; len as usize ] ;
583
+ buf. read_exact ( & mut content) . unwrap ( ) ;
584
+ body = Some ( content)
585
+ }
586
+
562
587
let req = Request {
563
588
authorization,
564
589
if_modified_since,
565
590
if_none_match,
566
591
method,
567
592
url,
593
+ body,
568
594
} ;
569
595
println ! ( "req: {:#?}" , req) ;
570
596
let response = self . route ( & req) ;
0 commit comments