Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3049'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Dec 10, 2012
2 parents 3d06cbf + 052bf28 commit a44d7dd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Client/Adapter/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod
ErrorHandler::start();
$test = fwrite($this->socket, $request);
$error = ErrorHandler::stop();
if (!$test) {
if (false === $test) {
throw new AdapterException\RuntimeException('Error writing request to server', 0, $error);
}

Expand Down
12 changes: 12 additions & 0 deletions test/Client/SocketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace ZendTest\Http\Client;

use Zend\Http\Client\Adapter;
use Zend\Uri\Uri;

/**
* This Testsuite includes all Zend_Http_Client that require a working web
Expand Down Expand Up @@ -249,6 +250,17 @@ public function testMultibyteChunkedResponseZF6218()
$this->assertEquals($md5, md5($response->getBody()));
}

/**
* Verifies that writing on a socket is considered valid even if 0 bytes
* were written.
*/
public function testAllowsZeroWrittenBytes()
{
$this->_adapter->connect('localhost');
require_once __DIR__ . '/_files/fwrite.php';
$this->_adapter->write('GET', new Uri('tcp://localhost:80/'), '1.1', array(), 'test body');
}

/**
* Data Providers
*/
Expand Down
22 changes: 22 additions & 0 deletions test/Client/_files/fwrite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Http
*/

namespace Zend\Http\Client\Adapter;

/**
* This is a stub for PHP's `fwrite` function. It
* allows us to check that a write operation to a
* socket producing a returned "0 bytes" written
* is actually valid.
*/
function fwrite($socket, $request)
{
return 0;
}

0 comments on commit a44d7dd

Please # to comment.