@@ -8,6 +8,7 @@ pub struct Scheduler<'a> {
88 metrics : & ' a Arc < Metrics > ,
99 method : Method ,
1010 url : String ,
11+ body : Option < String > ,
1112 concurrency : u64 ,
1213 duration : u64 ,
1314 headers : HeaderMap ,
@@ -18,6 +19,7 @@ impl<'a> Scheduler<'a> {
1819 metrics : & ' a Arc < Metrics > ,
1920 method : Method ,
2021 url : String ,
22+ body : Option < String > ,
2123 concurrency : u64 ,
2224 duration : u64 ,
2325 headers : HeaderMap ,
@@ -26,6 +28,7 @@ impl<'a> Scheduler<'a> {
2628 metrics,
2729 method,
2830 url,
31+ body,
2932 concurrency,
3033 duration,
3134 headers,
@@ -42,12 +45,14 @@ impl<'a> Scheduler<'a> {
4245 for _ in 0 ..self . concurrency {
4346 let method = self . method . clone ( ) ;
4447 let url = url. clone ( ) ;
48+ let body = self . body . clone ( ) ;
4549 let headers = headers. clone ( ) ;
4650 let duration = self . duration ;
4751 let metrics = Arc :: clone ( self . metrics ) ;
4852
4953 tasks. push ( tokio:: spawn ( async move {
50- Scheduler :: run_client ( & metrics, start_bench, method, url, duration, headers) . await ;
54+ Scheduler :: run_client ( & metrics, start_bench, method, url, body, duration, headers)
55+ . await ;
5156 } ) ) ;
5257 }
5358
@@ -87,13 +92,14 @@ impl<'a> Scheduler<'a> {
8792 start_bench : std:: time:: Instant ,
8893 method : Method ,
8994 url : String ,
95+ body : Option < String > ,
9096 duration : u64 ,
9197 headers : HeaderMap ,
9298 ) {
9399 let client = Client :: builder ( ) . default_headers ( headers) . build ( ) . unwrap ( ) ;
94100
95101 loop {
96- let result = Self :: make_request ( metrics, & client, & method, & url) . await ;
102+ let result = Self :: make_request ( metrics, & client, & method, & url, & body ) . await ;
97103 Self :: handle_request_result ( metrics, result) . await ;
98104
99105 if std:: time:: Instant :: now ( ) >= start_bench + std:: time:: Duration :: from_secs ( duration) {
@@ -107,10 +113,17 @@ impl<'a> Scheduler<'a> {
107113 client : & Client ,
108114 method : & Method ,
109115 url : & str ,
116+ body : & Option < String > ,
110117 ) -> Result < String , reqwest:: Error > {
111118 let start = std:: time:: Instant :: now ( ) ;
112119
113- let resp = client. request ( method. clone ( ) , url) . send ( ) . await ?;
120+ let req_builder = client. request ( method. clone ( ) , url) ;
121+ let req_builder = match body {
122+ Some ( b) => req_builder. body ( b. clone ( ) ) ,
123+ None => req_builder,
124+ } ;
125+
126+ let resp = req_builder. send ( ) . await ?;
114127 let _status = resp. status ( ) ;
115128 let body = resp. text ( ) . await ?;
116129
0 commit comments