Skip to content

Commit

Permalink
tweak PR
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jun 23, 2020
1 parent 1e1f531 commit 7b0b437
Showing 1 changed file with 26 additions and 38 deletions.
64 changes: 26 additions & 38 deletions src/Illuminate/Http/Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ class PendingRequest
protected $bodyFormat;

/**
* The pending files for the request.
* The raw body for the request.
*
* @var array
* @var string
*/
protected $pendingFiles = [];
protected $pendingBody;

/**
* The binary for the request.
* The pending files for the request.
*
* @var array
*/
protected $pendingBinary;
protected $pendingFiles = [];

/**
* The request cookies.
Expand Down Expand Up @@ -131,6 +131,24 @@ public function baseUrl(string $url)
return $this;
}

/**
* Attach a raw body to the request.
*
* @param resource|string $content
* @param string $contentType
* @return $this
*/
public function withBody($content, $contentType)
{
$this->bodyFormat('body');

$this->pendingBody = $content;

$this->contentType($contentType);

return $this;
}

/**
* Indicate the request contains JSON.
*
Expand Down Expand Up @@ -184,34 +202,6 @@ public function asMultipart()
return $this->bodyFormat('multipart');
}

/**
* Attach a binary to the request.
*
* @param string $content
* @param string $contentType
* @return $this
*/
public function binary($content, $contentType)
{
$this->asBinary();

$this->pendingBinary = $content;

$this->contentType($contentType);

return $this;
}

/**
* Indicate the request contains form parameters.
*
* @return $this
*/
public function asBinary()
{
return $this->bodyFormat('body');
}

/**
* Specify the body format of the request.
*
Expand Down Expand Up @@ -509,10 +499,8 @@ public function send(string $method, string $url, array $options = [])
if (isset($options[$this->bodyFormat])) {
if ($this->bodyFormat === 'multipart') {
$options[$this->bodyFormat] = $this->parseMultipartBodyFormat($options[$this->bodyFormat]);
}

if ($this->bodyFormat === 'body') {
$options[$this->bodyFormat] = $this->pendingBinary;
} elseif ($this->bodyFormat === 'body') {
$options[$this->bodyFormat] = $this->pendingBody;
}

if (is_array($options[$this->bodyFormat])) {
Expand All @@ -522,7 +510,7 @@ public function send(string $method, string $url, array $options = [])
}
}

$this->pendingFiles = [];
[$this->pendingBody, $this->pendingFiles] = [null, []];

This comment has been minimized.

Copy link
@JaZo

JaZo Jun 25, 2020

Contributor

@taylorotwell, just curious about your reasons. Why do you use that instead of this?

$this->pendingBody = null;
$this->pendingFiles = [];

This comment has been minimized.

Copy link
@GrahamCampbell

GrahamCampbell Jun 25, 2020

Member

Doesn't matter. Is the same.


return retry($this->tries ?? 1, function () use ($method, $url, $options) {
try {
Expand Down

0 comments on commit 7b0b437

Please sign in to comment.