mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-25 02:22:57 +01:00
[Http] Attempting to seek to the beginning of a stream when sending EntityEnclosingRequest objects so that they can be reused without having to seek manually
This commit is contained in:
parent
e3fd5c227b
commit
ce8cdd8f67
@ -153,6 +153,8 @@ class CurlHandle
|
||||
// Add a callback for curl to read data to send with the request
|
||||
// only if a body was specified
|
||||
$curlOptions[CURLOPT_READFUNCTION] = array($mediator, 'readRequestBody');
|
||||
// Attempt to seek to the start of the stream
|
||||
$request->getBody()->seek(0);
|
||||
} elseif ($request->getMethod() == 'POST') {
|
||||
// Need to remove CURLOPT_POST to prevent chunked encoding
|
||||
unset($curlOptions[CURLOPT_POST]);
|
||||
|
@ -929,4 +929,23 @@ class CurlHandleTest extends \Guzzle\Tests\GuzzleTestCase
|
||||
$this->assertEquals(2, count($received));
|
||||
$this->assertEquals($method, $received[1]->getMethod());
|
||||
}
|
||||
|
||||
public function testSeeksToBeginningOfStreamWhenSending()
|
||||
{
|
||||
$this->getServer()->flush();
|
||||
$this->getServer()->enqueue(array(
|
||||
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
|
||||
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"
|
||||
));
|
||||
|
||||
$client = new Client($this->getServer()->getUrl());
|
||||
$request = $client->put('/', null, 'test');
|
||||
$request->send();
|
||||
$request->send();
|
||||
|
||||
$received = $this->getServer()->getReceivedRequests(true);
|
||||
$this->assertEquals(2, count($received));
|
||||
$this->assertEquals('test', (string) $received[0]->getBody());
|
||||
$this->assertEquals('test', (string) $received[1]->getBody());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user