@@ -150,15 +150,8 @@ impl Client {
150
150
/// # }
151
151
/// ```
152
152
pub async fn publish ( & self , subject : String , payload : Bytes ) -> Result < ( ) , PublishError > {
153
- self . sender
154
- . send ( Command :: Publish {
155
- subject,
156
- payload,
157
- respond : None ,
158
- headers : None ,
159
- } )
160
- . await ?;
161
- Ok ( ( ) )
153
+ self . publish_with_headers ( subject, HeaderMap :: new ( ) , payload)
154
+ . await
162
155
}
163
156
164
157
/// Publish a [Message] with headers to a given subject.
@@ -191,7 +184,7 @@ impl Client {
191
184
subject,
192
185
payload,
193
186
respond : None ,
194
- headers : Some ( headers ) ,
187
+ headers,
195
188
} )
196
189
. await ?;
197
190
Ok ( ( ) )
@@ -223,15 +216,8 @@ impl Client {
223
216
reply : String ,
224
217
payload : Bytes ,
225
218
) -> Result < ( ) , PublishError > {
226
- self . sender
227
- . send ( Command :: Publish {
228
- subject,
229
- payload,
230
- respond : Some ( reply) ,
231
- headers : None ,
232
- } )
233
- . await ?;
234
- Ok ( ( ) )
219
+ self . publish_with_reply_and_headers ( subject, reply, HeaderMap :: new ( ) , payload)
220
+ . await
235
221
}
236
222
237
223
/// Publish a [Message] to a given subject with headers and specified response subject
@@ -269,7 +255,7 @@ impl Client {
269
255
subject,
270
256
payload,
271
257
respond : Some ( reply) ,
272
- headers : Some ( headers ) ,
258
+ headers,
273
259
} )
274
260
. await ?;
275
261
Ok ( ( ) )
@@ -338,14 +324,9 @@ impl Client {
338
324
if let Some ( inbox) = request. inbox {
339
325
let timeout = request. timeout . unwrap_or ( self . request_timeout ) ;
340
326
let mut sub = self . subscribe ( inbox. clone ( ) ) . await ?;
341
- let payload: Bytes = request. payload . unwrap_or_else ( Bytes :: new) ;
342
- match request. headers {
343
- Some ( headers) => {
344
- self . publish_with_reply_and_headers ( subject, inbox, headers, payload)
345
- . await ?
346
- }
347
- None => self . publish_with_reply ( subject, inbox, payload) . await ?,
348
- }
327
+ self . publish_with_reply_and_headers ( subject, inbox, request. headers , request. payload )
328
+ . await ?;
329
+
349
330
let request = match timeout {
350
331
Some ( timeout) => {
351
332
tokio:: time:: timeout ( timeout, sub. next ( ) )
@@ -372,9 +353,9 @@ impl Client {
372
353
} else {
373
354
let ( sender, receiver) = oneshot:: channel ( ) ;
374
355
375
- let payload = request. payload . unwrap_or_else ( Bytes :: new) ;
376
356
let respond = self . new_inbox ( ) ;
377
357
let headers = request. headers ;
358
+ let payload = request. payload ;
378
359
379
360
self . sender
380
361
. send ( Command :: Request {
@@ -542,8 +523,8 @@ impl Client {
542
523
/// Used for building customized requests.
543
524
#[ derive( Default ) ]
544
525
pub struct Request {
545
- payload : Option < Bytes > ,
546
- headers : Option < HeaderMap > ,
526
+ payload : Bytes ,
527
+ headers : HeaderMap ,
547
528
timeout : Option < Option < Duration > > ,
548
529
inbox : Option < String > ,
549
530
}
@@ -566,7 +547,7 @@ impl Request {
566
547
/// # }
567
548
/// ```
568
549
pub fn payload ( mut self , payload : Bytes ) -> Request {
569
- self . payload = Some ( payload) ;
550
+ self . payload = payload;
570
551
self
571
552
}
572
553
@@ -591,7 +572,7 @@ impl Request {
591
572
/// # }
592
573
/// ```
593
574
pub fn headers ( mut self , headers : HeaderMap ) -> Request {
594
- self . headers = Some ( headers) ;
575
+ self . headers = headers;
595
576
self
596
577
}
597
578
0 commit comments