]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - extlib/HTTP/Request2/Adapter.php
PEAR::HTTP_Request2 updated to 2.2.1
[quix0rs-gnu-social.git] / extlib / HTTP / Request2 / Adapter.php
index 39b092b346e451f962412ea4f51d81e674efa7c6..4e4b0b10a3a3e660422ea7d8dc6775502e8fac82 100644 (file)
@@ -4,41 +4,18 @@
  *\r
  * PHP version 5\r
  *\r
- * LICENSE:\r
+ * LICENSE\r
  *\r
- * Copyright (c) 2008, 2009, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
+ * This source file is subject to BSD 3-Clause License that is bundled\r
+ * with this package in the file LICENSE and available at the URL\r
+ * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE\r
  *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- *    * Redistributions of source code must retain the above copyright\r
- *      notice, this list of conditions and the following disclaimer.\r
- *    * Redistributions in binary form must reproduce the above copyright\r
- *      notice, this list of conditions and the following disclaimer in the\r
- *      documentation and/or other materials provided with the distribution.\r
- *    * The names of the authors may not be used to endorse or promote products\r
- *      derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category   HTTP\r
- * @package    HTTP_Request2\r
- * @author     Alexey Borzov <avb@php.net>\r
- * @license    http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version    CVS: $Id: Adapter.php 274684 2009-01-26 23:07:27Z avb $\r
- * @link       http://pear.php.net/package/HTTP_Request2\r
+ * @category  HTTP\r
+ * @package   HTTP_Request2\r
+ * @author    Alexey Borzov <avb@php.net>\r
+ * @copyright 2008-2014 Alexey Borzov <avb@php.net>\r
+ * @license   http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @link      http://pear.php.net/package/HTTP_Request2\r
  */\r
 \r
 /**\r
@@ -50,69 +27,72 @@ require_once 'HTTP/Request2/Response.php';
  * Base class for HTTP_Request2 adapters\r
  *\r
  * HTTP_Request2 class itself only defines methods for aggregating the request\r
- * data, all actual work of sending the request to the remote server and \r
+ * data, all actual work of sending the request to the remote server and\r
  * receiving its response is performed by adapters.\r
  *\r
- * @category   HTTP\r
- * @package    HTTP_Request2\r
- * @author     Alexey Borzov <avb@php.net>\r
- * @version    Release: 0.4.1\r
+ * @category HTTP\r
+ * @package  HTTP_Request2\r
+ * @author   Alexey Borzov <avb@php.net>\r
+ * @license  http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version  Release: 2.2.1\r
+ * @link     http://pear.php.net/package/HTTP_Request2\r
  */\r
 abstract class HTTP_Request2_Adapter\r
 {\r
-   /**\r
-    * A list of methods that MUST NOT have a request body, per RFC 2616\r
-    * @var  array\r
-    */\r
+    /**\r
+     * A list of methods that MUST NOT have a request body, per RFC 2616\r
+     * @var  array\r
+     */\r
     protected static $bodyDisallowed = array('TRACE');\r
 \r
-   /**\r
-    * Methods having defined semantics for request body\r
-    *\r
-    * Content-Length header (indicating that the body follows, section 4.3 of\r
-    * RFC 2616) will be sent for these methods even if no body was added\r
-    *\r
-    * @var  array\r
-    * @link http://pear.php.net/bugs/bug.php?id=12900\r
-    * @link http://pear.php.net/bugs/bug.php?id=14740\r
-    */\r
+    /**\r
+     * Methods having defined semantics for request body\r
+     *\r
+     * Content-Length header (indicating that the body follows, section 4.3 of\r
+     * RFC 2616) will be sent for these methods even if no body was added\r
+     *\r
+     * @var  array\r
+     * @link http://pear.php.net/bugs/bug.php?id=12900\r
+     * @link http://pear.php.net/bugs/bug.php?id=14740\r
+     */\r
     protected static $bodyRequired = array('POST', 'PUT');\r
 \r
-   /**\r
-    * Request being sent\r
-    * @var  HTTP_Request2\r
-    */\r
+    /**\r
+     * Request being sent\r
+     * @var  HTTP_Request2\r
+     */\r
     protected $request;\r
 \r
-   /**\r
-    * Request body\r
-    * @var  string|resource|HTTP_Request2_MultipartBody\r
-    * @see  HTTP_Request2::getBody()\r
-    */\r
+    /**\r
+     * Request body\r
+     * @var  string|resource|HTTP_Request2_MultipartBody\r
+     * @see  HTTP_Request2::getBody()\r
+     */\r
     protected $requestBody;\r
 \r
-   /**\r
-    * Length of the request body\r
-    * @var  integer\r
-    */\r
+    /**\r
+     * Length of the request body\r
+     * @var  integer\r
+     */\r
     protected $contentLength;\r
 \r
-   /**\r
-    * Sends request to the remote server and returns its response\r
-    *\r
-    * @param    HTTP_Request2\r
-    * @return   HTTP_Request2_Response\r
-    * @throws   HTTP_Request2_Exception\r
-    */\r
+    /**\r
+     * Sends request to the remote server and returns its response\r
+     *\r
+     * @param HTTP_Request2 $request HTTP request message\r
+     *\r
+     * @return   HTTP_Request2_Response\r
+     * @throws   HTTP_Request2_Exception\r
+     */\r
     abstract public function sendRequest(HTTP_Request2 $request);\r
 \r
-   /**\r
-    * Calculates length of the request body, adds proper headers\r
-    *\r
-    * @param    array   associative array of request headers, this method will \r
-    *                   add proper 'Content-Length' and 'Content-Type' headers \r
-    *                   to this array (or remove them if not needed)\r
-    */\r
+    /**\r
+     * Calculates length of the request body, adds proper headers\r
+     *\r
+     * @param array &$headers associative array of request headers, this method\r
+     *                        will add proper 'Content-Length' and 'Content-Type'\r
+     *                        headers to this array (or remove them if not needed)\r
+     */\r
     protected function calculateRequestLength(&$headers)\r
     {\r
         $this->requestBody = $this->request->getBody();\r
@@ -130,22 +110,27 @@ abstract class HTTP_Request2_Adapter
             $this->requestBody->rewind();\r
         }\r
 \r
-        if (in_array($this->request->getMethod(), self::$bodyDisallowed) ||\r
-            0 == $this->contentLength\r
+        if (in_array($this->request->getMethod(), self::$bodyDisallowed)\r
+            || 0 == $this->contentLength\r
         ) {\r
-            unset($headers['content-type']);\r
             // No body: send a Content-Length header nonetheless (request #12900),\r
             // but do that only for methods that require a body (bug #14740)\r
             if (in_array($this->request->getMethod(), self::$bodyRequired)) {\r
                 $headers['content-length'] = 0;\r
             } else {\r
                 unset($headers['content-length']);\r
+                // if the method doesn't require a body and doesn't have a\r
+                // body, don't send a Content-Type header. (request #16799)\r
+                unset($headers['content-type']);\r
             }\r
         } else {\r
             if (empty($headers['content-type'])) {\r
                 $headers['content-type'] = 'application/x-www-form-urlencoded';\r
             }\r
-            $headers['content-length'] = $this->contentLength;\r
+            // Content-Length should not be sent for chunked Transfer-Encoding (bug #20125)\r
+            if (!isset($headers['transfer-encoding'])) {\r
+                $headers['content-length'] = $this->contentLength;\r
+            }\r
         }\r
     }\r
 }\r