1- use std:: sync:: Arc ;
1+ use std:: { collections :: HashMap , sync:: Arc } ;
22
33use reqwest:: { header:: HeaderMap , Client , Method } ;
44
@@ -9,6 +9,7 @@ pub struct Scheduler<'a> {
99 method : Method ,
1010 url : String ,
1111 body : Option < String > ,
12+ form_params : HashMap < String , String > ,
1213 concurrency : u64 ,
1314 duration : u64 ,
1415 headers : HeaderMap ,
@@ -20,15 +21,17 @@ impl<'a> Scheduler<'a> {
2021 method : Method ,
2122 url : String ,
2223 body : Option < String > ,
24+ form_params : HashMap < String , String > ,
25+ headers : HeaderMap ,
2326 concurrency : u64 ,
2427 duration : u64 ,
25- headers : HeaderMap ,
2628 ) -> Self {
2729 Scheduler {
2830 metrics,
2931 method,
3032 url,
3133 body,
34+ form_params,
3235 concurrency,
3336 duration,
3437 headers,
@@ -46,13 +49,23 @@ impl<'a> Scheduler<'a> {
4649 let method = self . method . clone ( ) ;
4750 let url = url. clone ( ) ;
4851 let body = self . body . clone ( ) ;
52+ let form_params = self . form_params . clone ( ) ;
4953 let headers = headers. clone ( ) ;
5054 let duration = self . duration ;
5155 let metrics = Arc :: clone ( self . metrics ) ;
5256
5357 tasks. push ( tokio:: spawn ( async move {
54- Scheduler :: run_client ( & metrics, start_bench, method, url, body, duration, headers)
55- . await ;
58+ Scheduler :: run_client (
59+ & metrics,
60+ start_bench,
61+ method,
62+ url,
63+ body,
64+ form_params,
65+ duration,
66+ headers,
67+ )
68+ . await ;
5669 } ) ) ;
5770 }
5871
@@ -93,13 +106,15 @@ impl<'a> Scheduler<'a> {
93106 method : Method ,
94107 url : String ,
95108 body : Option < String > ,
109+ form_params : HashMap < String , String > ,
96110 duration : u64 ,
97111 headers : HeaderMap ,
98112 ) {
99113 let client = Client :: builder ( ) . default_headers ( headers) . build ( ) . unwrap ( ) ;
100114
101115 loop {
102- let result = Self :: make_request ( metrics, & client, & method, & url, & body) . await ;
116+ let result =
117+ Self :: make_request ( metrics, & client, & method, & url, & body, & form_params) . await ;
103118 Self :: handle_request_result ( metrics, result) . await ;
104119
105120 if std:: time:: Instant :: now ( ) >= start_bench + std:: time:: Duration :: from_secs ( duration) {
@@ -114,10 +129,16 @@ impl<'a> Scheduler<'a> {
114129 method : & Method ,
115130 url : & str ,
116131 body : & Option < String > ,
132+ form_params : & HashMap < String , String > ,
117133 ) -> Result < String , reqwest:: Error > {
118134 let start = std:: time:: Instant :: now ( ) ;
119135
120136 let req_builder = client. request ( method. clone ( ) , url) ;
137+ let req_builder = if form_params. len ( ) > 0 {
138+ req_builder. form ( form_params)
139+ } else {
140+ req_builder
141+ } ;
121142 let req_builder = match body {
122143 Some ( b) => req_builder. body ( b. clone ( ) ) ,
123144 None => req_builder,
0 commit comments