@@ -66,6 +66,8 @@ pub struct ClientBuilder {
66
66
reconnect_opts : ReconnectOptions ,
67
67
read_timeout : Option < Duration > ,
68
68
last_event_id : String ,
69
+ method : String ,
70
+ body : Option < String > ,
69
71
}
70
72
71
73
impl ClientBuilder {
@@ -85,9 +87,23 @@ impl ClientBuilder {
85
87
reconnect_opts : ReconnectOptions :: default ( ) ,
86
88
read_timeout : None ,
87
89
last_event_id : String :: new ( ) ,
90
+ method : String :: from ( "GET" ) ,
91
+ body : None ,
88
92
} )
89
93
}
90
94
95
+ /// Set the request method used for the initial connection to the SSE endpoint.
96
+ pub fn method ( mut self , method : String ) -> ClientBuilder {
97
+ self . method = method;
98
+ self
99
+ }
100
+
101
+ /// Set the request body used for the initial connection to the SSE endpoint.
102
+ pub fn body ( mut self , body : String ) -> ClientBuilder {
103
+ self . body = Some ( body) ;
104
+ self
105
+ }
106
+
91
107
/// Set the last event id for a stream when it is created. If it is set, it will be sent to the
92
108
/// server in case it can replay missed events.
93
109
pub fn last_event_id ( mut self , last_event_id : String ) -> ClientBuilder {
@@ -139,6 +155,8 @@ impl ClientBuilder {
139
155
request_props : RequestProps {
140
156
url : self . url ,
141
157
headers : self . headers ,
158
+ method : self . method ,
159
+ body : self . body ,
142
160
reconnect_opts : self . reconnect_opts ,
143
161
} ,
144
162
last_event_id : self . last_event_id ,
@@ -167,6 +185,8 @@ impl ClientBuilder {
167
185
request_props : RequestProps {
168
186
url : self . url ,
169
187
headers : self . headers ,
188
+ method : self . method ,
189
+ body : self . body ,
170
190
reconnect_opts : self . reconnect_opts ,
171
191
} ,
172
192
last_event_id : self . last_event_id ,
@@ -178,6 +198,8 @@ impl ClientBuilder {
178
198
struct RequestProps {
179
199
url : Uri ,
180
200
headers : HeaderMap ,
201
+ method : String ,
202
+ body : Option < String > ,
181
203
reconnect_opts : ReconnectOptions ,
182
204
}
183
205
@@ -276,7 +298,9 @@ impl<C> ReconnectingRequest<C> {
276
298
where
277
299
C : Connect + Clone + Send + Sync + ' static ,
278
300
{
279
- let mut request_builder = Request :: builder ( ) . uri ( & self . props . url ) ;
301
+ let mut request_builder = Request :: builder ( )
302
+ . method ( self . props . method . as_str ( ) )
303
+ . uri ( & self . props . url ) ;
280
304
281
305
for ( name, value) in & self . props . headers {
282
306
request_builder = request_builder. header ( name, value) ;
@@ -289,7 +313,10 @@ impl<C> ReconnectingRequest<C> {
289
313
) ;
290
314
}
291
315
292
- let body = Body :: empty ( ) ;
316
+ let body = match & self . props . body {
317
+ Some ( body) => Body :: from ( body. to_string ( ) ) ,
318
+ None => Body :: empty ( ) ,
319
+ } ;
293
320
294
321
let request = request_builder
295
322
. body ( body)
0 commit comments