@@ -41,6 +41,13 @@ class PendingRequest
41
41
*/
42
42
protected $ pendingFiles = [];
43
43
44
+ /**
45
+ * The binary for the request.
46
+ *
47
+ * @var array
48
+ */
49
+ protected $ pendingBinary ;
50
+
44
51
/**
45
52
* The request cookies.
46
53
*
@@ -177,6 +184,34 @@ public function asMultipart()
177
184
return $ this ->bodyFormat ('multipart ' );
178
185
}
179
186
187
+ /**
188
+ * Attach a binary to the request.
189
+ *
190
+ * @param string $content
191
+ * @param string $contentType
192
+ * @return $this
193
+ */
194
+ public function binary ($ content , $ contentType )
195
+ {
196
+ $ this ->asBinary ();
197
+
198
+ $ this ->pendingBinary = $ content ;
199
+
200
+ $ this ->contentType ($ contentType );
201
+
202
+ return $ this ;
203
+ }
204
+
205
+ /**
206
+ * Indicate the request contains form parameters.
207
+ *
208
+ * @return $this
209
+ */
210
+ public function asBinary ()
211
+ {
212
+ return $ this ->bodyFormat ('body ' );
213
+ }
214
+
180
215
/**
181
216
* Specify the body format of the request.
182
217
*
@@ -476,9 +511,15 @@ public function send(string $method, string $url, array $options = [])
476
511
$ options [$ this ->bodyFormat ] = $ this ->parseMultipartBodyFormat ($ options [$ this ->bodyFormat ]);
477
512
}
478
513
479
- $ options [$ this ->bodyFormat ] = array_merge (
480
- $ options [$ this ->bodyFormat ], $ this ->pendingFiles
481
- );
514
+ if ($ this ->bodyFormat === 'body ' ) {
515
+ $ options [$ this ->bodyFormat ] = $ this ->pendingBinary ;
516
+ }
517
+
518
+ if (is_array ($ options [$ this ->bodyFormat ])) {
519
+ $ options [$ this ->bodyFormat ] = array_merge (
520
+ $ options [$ this ->bodyFormat ], $ this ->pendingFiles
521
+ );
522
+ }
482
523
}
483
524
484
525
$ this ->pendingFiles = [];
0 commit comments