@@ -513,16 +513,12 @@ fn test_http_module() {
513513 let port = listener. local_addr ( ) . unwrap ( ) . port ( ) ;
514514
515515 thread:: spawn ( move || {
516- for _ in 0 ..2 {
517- if let Ok ( ( mut stream, _) ) = listener. accept ( ) {
518- let mut buf = [ 0 ; 1024 ] ;
519- if stream. read ( & mut buf) . is_ok ( ) {
520- let response = "HTTP/1.1 200 OK\r \n Content-Length: 13\r \n Content-Type: text/plain\r \n \r \n Hello Server!" ;
521- stream. write_all ( response. as_bytes ( ) ) . ok ( ) ;
522- let _ = stream. flush ( ) ;
523- let _ = stream. shutdown ( std:: net:: Shutdown :: Write ) ;
524- }
525- }
516+ while let Ok ( ( mut stream, _) ) = listener. accept ( ) {
517+ let mut buf = [ 0 ; 4096 ] ;
518+ let _ = stream. read ( & mut buf) ;
519+ let response = "HTTP/1.1 200 OK\r \n Content-Length: 13\r \n Content-Type: text/plain\r \n Connection: close\r \n \r \n Hello Server!" ;
520+ let _ = stream. write_all ( response. as_bytes ( ) ) ;
521+ let _ = stream. flush ( ) ;
526522 }
527523 } ) ;
528524
@@ -595,15 +591,26 @@ fn test_http_module() {
595591 panic ! ( "get did not return a Map" ) ;
596592 }
597593
598- let res2 = post
599- . call (
600- & mut ctx,
601- vec ! [
602- RuntimeValue :: Str ( format!( "http://127.0.0.1:{}" , port) ) ,
603- RuntimeValue :: Str ( "body" . to_string( ) ) ,
604- ] ,
605- )
606- . unwrap ( ) ;
594+ let res2 = match post. call (
595+ & mut ctx,
596+ vec ! [
597+ RuntimeValue :: Str ( format!( "http://127.0.0.1:{}" , port) ) ,
598+ RuntimeValue :: Str ( "body" . to_string( ) ) ,
599+ ] ,
600+ ) {
601+ Ok ( v) => v,
602+ Err ( _) => {
603+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 50 ) ) ;
604+ post. call (
605+ & mut ctx,
606+ vec ! [
607+ RuntimeValue :: Str ( format!( "http://127.0.0.1:{}" , port) ) ,
608+ RuntimeValue :: Str ( "body" . to_string( ) ) ,
609+ ] ,
610+ )
611+ . unwrap ( )
612+ }
613+ } ;
607614
608615 if let RuntimeValue :: Map { entries, .. } = res2 {
609616 let entries_borrow = entries. borrow ( ) ;
0 commit comments