Просмотр исходного кода

ZF-10645: allow passing content-type for PUT requests

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23309 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 15 лет назад
Родитель
Сommit
c194867836

+ 1 - 1
library/Zend/Http/Client.php

@@ -1108,7 +1108,7 @@ class Zend_Http_Client
         }
 
         // Set the Content-Type header
-        if ($this->method == self::POST &&
+        if (($this->method == self::POST || $this->method == self::PUT) &&
            (! isset($this->headers[strtolower(self::CONTENT_TYPE)]) && isset($this->enctype))) {
 
             $headers[] = self::CONTENT_TYPE . ': ' . $this->enctype;

+ 17 - 0
tests/Zend/Http/Client/CommonHttpTests.php

@@ -980,6 +980,23 @@ abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCa
         
         $this->assertEquals($expect, strlen($response->getBody()));
     }
+
+    /**
+     * @group ZF-10645
+     */
+    public function testPutRequestsHonorSpecifiedContentType()
+    {
+        $this->client->setUri($this->baseuri . 'ZF10645-PutContentType.php');
+        $this->client->setMethod(Zend_Http_Client::PUT);
+        $data = array('foo' => 'bar');
+        $this->client->setRawData(http_build_query($data), 'text/html; charset=ISO-8859-1');
+
+        $response = $this->client->request();
+        $request  = $this->client->getLastRequest();
+
+        $this->assertContains('text/html; charset=ISO-8859-1', $request, $request);
+        $this->assertContains('REQUEST_METHOD: PUT', $response->getBody(), $response->getBody());
+    }
     
     /**
      * Internal helpder function to get the contents of test files

+ 3 - 0
tests/Zend/Http/Client/_files/ZF10645-PutContentType.php

@@ -0,0 +1,3 @@
+<?php
+echo 'REQUEST_METHOD: ' . $_SERVER['REQUEST_METHOD'] . "\n\n";
+readfile('php://input');