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

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 191 changed files with 3,565 additions and 2,054 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zendframework/zend-http",
"description": "Zend\\Http component",
"description": "provides an easy interface for preforming Hyper-Text Transfer Protocol (HTTP) requests",
"license": "BSD-3-Clause",
"keywords": [
"zf2",
Expand All @@ -9,11 +9,11 @@
"homepage": "https://github.com/zendframework/zend-http",
"autoload": {
"psr-4": {
"Zend\\Http\\": "src/"
"Zend\\Http": "src/"
}
},
"require": {
"php": ">=5.3.23",
"php": ">=5.3.3",
"zendframework/zend-loader": "self.version",
"zendframework/zend-stdlib": "self.version",
"zendframework/zend-uri": "self.version",
Expand All @@ -25,14 +25,14 @@
"dev-develop": "2.5-dev"
}
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/PHPUnit": "~4.0"
},
"autoload-dev": {
"psr-4": {
"ZendTest\\Http\\": "test/"
}
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/PHPUnit": "~4.0"
}
}
108 changes: 108 additions & 0 deletions src/AbstractMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?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;

use Zend\Stdlib\Message;

/**
* HTTP standard message (Request/Response)
*
* @category Zend
* @package Zend_Http
* @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4
*/
abstract class AbstractMessage extends Message
{
/**#@+
* @const string Version constant numbers
*/
const VERSION_10 = '1.0';
const VERSION_11 = '1.1';
/**#@-*/

/**
* @var string
*/
protected $version = self::VERSION_11;

/**
* @var Headers|null
*/
protected $headers = null;

/**
* Set the HTTP version for this object, one of 1.0 or 1.1
* (AbstractMessage::VERSION_10, AbstractMessage::VERSION_11)
*
* @param string $version (Must be 1.0 or 1.1)
* @return AbstractMessage
* @throws Exception\InvalidArgumentException
*/
public function setVersion($version)
{
if ($version != self::VERSION_10 && $version != self::VERSION_11) {
throw new Exception\InvalidArgumentException(
'Not valid or not supported HTTP version: ' . $version
);
}
$this->version = $version;
return $this;
}

/**
* Return the HTTP version for this request
*
* @return string
*/
public function getVersion()
{
return $this->version;
}

/**
* Provide an alternate Parameter Container implementation for headers in this object,
* (this is NOT the primary API for value setting, for that see getHeaders())
*
* @see getHeaders()
* @param Headers $headers
* @return AbstractMessage
*/
public function setHeaders(Headers $headers)
{
$this->headers = $headers;
return $this;
}

/**
* Return the header container responsible for headers
*
* @return Headers
*/
public function getHeaders()
{
if ($this->headers === null || is_string($this->headers)) {
// this is only here for fromString lazy loading
$this->headers = (is_string($this->headers)) ? Headers::fromString($this->headers) : new Headers();
}

return $this->headers;
}

/**
* Allow PHP casting of this object
*
* @return string
*/
public function __toString()
{
return $this->toString();
}
}
74 changes: 31 additions & 43 deletions src/Client.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend\Http
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @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;

use ArrayIterator;
use Traversable;
use Zend\Stdlib;
use Zend\Stdlib\ArrayUtils;
use ArrayIterator,
Zend\Uri\Http,
Zend\Stdlib;
use Zend\Uri\Http;

/**
* Http client
*
* @category Zend
* @package Zend\Http
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Client implements Stdlib\DispatchableInterface
{
Expand Down Expand Up @@ -135,7 +123,7 @@ class Client implements Stdlib\DispatchableInterface
*
* @var resource
*/
static protected $_fileInfoDb = null;
protected static $_fileInfoDb = null;

/**
* Constructor
Expand Down Expand Up @@ -334,7 +322,7 @@ public function setUri($uri)
*/
public function getUri()
{
return $this->getRequest()->uri();
return $this->getRequest()->getUri();
}

/**
Expand Down Expand Up @@ -415,7 +403,7 @@ public function setRawBody($body)
*/
public function setParameterPost(array $post)
{
$this->getRequest()->post()->fromArray($post);
$this->getRequest()->getPost()->fromArray($post);
return $this;
}

Expand All @@ -427,7 +415,7 @@ public function setParameterPost(array $post)
*/
public function setParameterGet(array $query)
{
$this->getRequest()->query()->fromArray($query);
$this->getRequest()->getQuery()->fromArray($query);
return $this;
}

Expand Down Expand Up @@ -545,7 +533,7 @@ public function setHeaders($headers)
*/
public function hasHeader($name)
{
$headers = $this->getRequest()->headers();
$headers = $this->getRequest()->getHeaders();

if ($headers instanceof Headers) {
return $headers->has($name);
Expand All @@ -562,7 +550,7 @@ public function hasHeader($name)
*/
public function getHeader($name)
{
$headers = $this->getRequest()->headers();
$headers = $this->getRequest()->getHeaders();

if ($headers instanceof Headers) {
if ($headers->get($name)) {
Expand Down Expand Up @@ -590,7 +578,7 @@ public function setStream($streamfile = true)
*/
public function getStream()
{
return $this->config["outputstream"];
return $this->config['outputstream'];
}

/**
Expand Down Expand Up @@ -766,7 +754,7 @@ public function send(Request $request = null)
$uri = $this->getUri();

// query
$query = $this->getRequest()->query();
$query = $this->getRequest()->getQuery();

if (!empty($query)) {
$queryArray = $query->toArray();
Expand Down Expand Up @@ -855,17 +843,17 @@ public function send(Request $request = null)
}

// Get the cookies from response (if any)
$setCookie = $response->cookie();
$setCookie = $response->getCookie();
if (!empty($setCookie)) {
$this->addCookie($setCookie);
}

// If we got redirected, look for the Location header
if ($response->isRedirect() && ($response->headers()->has('Location'))) {
if ($response->isRedirect() && ($response->getHeaders()->has('Location'))) {

// Avoid problems with buggy servers that add whitespace at the
// end of some headers
$location = trim($response->headers()->get('Location')->getFieldValue());
$location = trim($response->getHeaders()->get('Location')->getFieldValue());

// Check whether we send the exact same request again, or drop the parameters
// and send a GET request
Expand Down Expand Up @@ -946,7 +934,7 @@ public function setFileUpload($filename, $formname, $data = null, $ctype = null)
}
}

$this->getRequest()->file()->set($filename, array(
$this->getRequest()->getFiles()->set($filename, array(
'formname' => $formname,
'filename' => basename($filename),
'ctype' => $ctype,
Expand All @@ -964,9 +952,9 @@ public function setFileUpload($filename, $formname, $data = null, $ctype = null)
*/
public function removeFileUpload($filename)
{
$file = $this->getRequest()->file()->get($filename);
$file = $this->getRequest()->getFiles()->get($filename);
if (!empty($file)) {
$this->getRequest()->file()->set($filename, null);
$this->getRequest()->getFiles()->set($filename, null);
return true;
}
return false;
Expand Down Expand Up @@ -1026,7 +1014,7 @@ protected function prepareHeaders($body, $uri)
}

// Set the connection header
if (!$this->getRequest()->headers()->has('Connection')) {
if (!$this->getRequest()->getHeaders()->has('Connection')) {
if (!$this->config['keepalive']) {
$headers['Connection'] = 'close';
}
Expand All @@ -1044,7 +1032,7 @@ protected function prepareHeaders($body, $uri)


// Set the user agent header
if (!$this->getRequest()->headers()->has('User-Agent') && isset($this->config['useragent'])) {
if (!$this->getRequest()->getHeaders()->has('User-Agent') && isset($this->config['useragent'])) {
$headers['User-Agent'] = $this->config['useragent'];
}

Expand Down Expand Up @@ -1078,7 +1066,7 @@ protected function prepareHeaders($body, $uri)
}

// Merge the headers of the request (if any)
$requestHeaders = $this->getRequest()->headers()->toArray();
$requestHeaders = $this->getRequest()->getHeaders()->toArray();
foreach ($requestHeaders as $key => $value) {
$headers[$key] = $value;
}
Expand Down Expand Up @@ -1107,8 +1095,8 @@ protected function prepareBody()
$body = '';
$totalFiles = 0;

if (!$this->getRequest()->headers()->has('Content-Type')) {
$totalFiles = count($this->getRequest()->file()->toArray());
if (!$this->getRequest()->getHeaders()->has('Content-Type')) {
$totalFiles = count($this->getRequest()->getFiles()->toArray());
// If we have files to upload, force encType to multipart/form-data
if ($totalFiles > 0) {
$this->setEncType(self::ENC_FORMDATA);
Expand All @@ -1118,26 +1106,26 @@ protected function prepareBody()
}

// If we have POST parameters or files, encode and add them to the body
if (count($this->getRequest()->post()->toArray()) > 0 || $totalFiles > 0) {
if (count($this->getRequest()->getPost()->toArray()) > 0 || $totalFiles > 0) {
if (stripos($this->getEncType(), self::ENC_FORMDATA) === 0) {
$boundary = '---ZENDHTTPCLIENT-' . md5(microtime());
$this->setEncType(self::ENC_FORMDATA, $boundary);

// Get POST parameters and encode them
$params = self::flattenParametersArray($this->getRequest()->post()->toArray());
$params = self::flattenParametersArray($this->getRequest()->getPost()->toArray());
foreach ($params as $pp) {
$body .= $this->encodeFormData($boundary, $pp[0], $pp[1]);
}

// Encode files
foreach ($this->getRequest()->file()->toArray() as $key => $file) {
foreach ($this->getRequest()->getFiles()->toArray() as $key => $file) {
$fhead = array('Content-Type' => $file['ctype']);
$body .= $this->encodeFormData($boundary, $file['formname'], $file['data'], $file['filename'], $fhead);
}
$body .= "--{$boundary}--\r\n";
} elseif (stripos($this->getEncType(), self::ENC_URLENCODED) === 0) {
// Encode body as application/x-www-form-urlencoded
$body = http_build_query($this->getRequest()->post()->toArray());
$body = http_build_query($this->getRequest()->getPost()->toArray());
} else {
throw new Client\Exception\RuntimeException("Cannot handle content type '{$this->encType}' automatically");
}
Expand Down
Loading

0 comments on commit 7f76d90

Please sign in to comment.