@@ -35,18 +35,18 @@ class PendingRequest
3535 protected $ bodyFormat ;
3636
3737 /**
38- * The pending files for the request.
38+ * The raw body for the request.
3939 *
40- * @var array
40+ * @var string
4141 */
42- protected $ pendingFiles = [] ;
42+ protected $ pendingBody ;
4343
4444 /**
45- * The binary for the request.
45+ * The pending files for the request.
4646 *
4747 * @var array
4848 */
49- protected $ pendingBinary ;
49+ protected $ pendingFiles = [] ;
5050
5151 /**
5252 * The request cookies.
@@ -131,6 +131,24 @@ public function baseUrl(string $url)
131131 return $ this ;
132132 }
133133
134+ /**
135+ * Attach a raw body to the request.
136+ *
137+ * @param resource|string $content
138+ * @param string $contentType
139+ * @return $this
140+ */
141+ public function withBody ($ content , $ contentType )
142+ {
143+ $ this ->bodyFormat ('body ' );
144+
145+ $ this ->pendingBody = $ content ;
146+
147+ $ this ->contentType ($ contentType );
148+
149+ return $ this ;
150+ }
151+
134152 /**
135153 * Indicate the request contains JSON.
136154 *
@@ -184,34 +202,6 @@ public function asMultipart()
184202 return $ this ->bodyFormat ('multipart ' );
185203 }
186204
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-
215205 /**
216206 * Specify the body format of the request.
217207 *
@@ -509,10 +499,8 @@ public function send(string $method, string $url, array $options = [])
509499 if (isset ($ options [$ this ->bodyFormat ])) {
510500 if ($ this ->bodyFormat === 'multipart ' ) {
511501 $ options [$ this ->bodyFormat ] = $ this ->parseMultipartBodyFormat ($ options [$ this ->bodyFormat ]);
512- }
513-
514- if ($ this ->bodyFormat === 'body ' ) {
515- $ options [$ this ->bodyFormat ] = $ this ->pendingBinary ;
502+ } elseif ($ this ->bodyFormat === 'body ' ) {
503+ $ options [$ this ->bodyFormat ] = $ this ->pendingBody ;
516504 }
517505
518506 if (is_array ($ options [$ this ->bodyFormat ])) {
@@ -522,7 +510,7 @@ public function send(string $method, string $url, array $options = [])
522510 }
523511 }
524512
525- $ this ->pendingFiles = [];
513+ [ $ this ->pendingBody , $ this -> pendingFiles ] = [null , [] ];
526514
527515 return retry ($ this ->tries ?? 1 , function () use ($ method , $ url , $ options ) {
528516 try {
0 commit comments