@@ -41,6 +41,13 @@ class PendingRequest
4141 */
4242 protected $ pendingFiles = [];
4343
44+ /**
45+ * The binary for the request.
46+ *
47+ * @var array
48+ */
49+ protected $ pendingBinary ;
50+
4451 /**
4552 * The request cookies.
4653 *
@@ -177,6 +184,34 @@ public function asMultipart()
177184 return $ this ->bodyFormat ('multipart ' );
178185 }
179186
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+
180215 /**
181216 * Specify the body format of the request.
182217 *
@@ -476,9 +511,15 @@ public function send(string $method, string $url, array $options = [])
476511 $ options [$ this ->bodyFormat ] = $ this ->parseMultipartBodyFormat ($ options [$ this ->bodyFormat ]);
477512 }
478513
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+ }
482523 }
483524
484525 $ this ->pendingFiles = [];
0 commit comments