Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Allow StreamInterface as raw HTTP Client body #49705

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Illuminate/Http/Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class PendingRequest
/**
* The raw body for the request.
*
* @var string
* @var \Psr\Http\Message\StreamInterface|string
*/
protected $pendingBody;

Expand Down Expand Up @@ -259,7 +259,7 @@ public function baseUrl(string $url)
/**
* Attach a raw body to the request.
*
* @param string $content
* @param \Psr\Http\Message\StreamInterface|string $content
* @param string $contentType
* @return $this
*/
Expand Down
21 changes: 21 additions & 0 deletions tests/Http/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuzzleHttp\Middleware;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Psr7\Response as Psr7Response;
use GuzzleHttp\Psr7\Utils;
use GuzzleHttp\TransferStats;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Support\Arrayable;
Expand Down Expand Up @@ -357,6 +358,26 @@ public function testSendRequestBodyWithManyAmpersands()
$this->factory->withBody($body, 'text/plain')->send('post', 'http://foo.com/api');
}

public function testSendStreamRequestBody()
{
$string = 'Look at me, i am a stream!!';
$resource = fopen('php://temp', 'w');
fwrite($resource, $string);
rewind($resource);
$body = Utils::streamFor($resource);

$fakeRequest = function (Request $request) use ($string) {
self::assertSame($string, $request->body());
self::assertContains('text/plain', $request->header('Content-Type'));

return ['my' => 'response'];
};

$this->factory->fake($fakeRequest);

$this->factory->withBody($body, 'text/plain')->send('post', 'http://foo.com/api');
}

public function testUrlsCanBeStubbedByPath()
{
$this->factory->fake([
Expand Down