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

ZF-8397: Make sure that any If-Match headers that are present are cleared after performing an HTTP request using Zend_Gdata_App.

This fixes a bug which prevented getEntry() from working after calling updateEntry().

Patch by: Alexander Steshenko (lcf)

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19510 44c647ce-9c0f-0410-b52a-842ac1e357ba
tjohns 16 лет назад
Родитель
Сommit
48183a6323
2 измененных файлов с 32 добавлено и 2 удалено
  1. 2 2
      library/Zend/Gdata/App.php
  2. 30 0
      tests/Zend/Gdata/AppTest.php

+ 2 - 2
library/Zend/Gdata/App.php

@@ -634,9 +634,9 @@ class Zend_Gdata_App
 
         // Make sure the HTTP client object is 'clean' before making a request
         // In addition to standard headers to reset via resetParameters(),
-        // also reset the Slug header
+        // also reset the Slug and If-Match headers
         $this->_httpClient->resetParameters();
-        $this->_httpClient->setHeaders('Slug', null);
+        $this->_httpClient->setHeaders(array('Slug', 'If-Match'));
 
         // Set the params for the new request to be performed
         $this->_httpClient->setHeaders($headers);

+ 30 - 0
tests/Zend/Gdata/AppTest.php

@@ -442,6 +442,36 @@ class Zend_Gdata_AppTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($found, 'If-None-Match header not found or incorrect');
     }
 
+    /**
+     * @group ZF-8397
+     */
+    public function testIfMatchHTTPHeaderIsResetEachRequest()
+    {
+        // Update an entry
+        $etag = 'ABCD1234';
+        $this->adapter->setResponse("HTTP/1.1 201 Created");
+        $this->service->setMajorProtocolVersion(2);
+        $entry = new Zend_Gdata_App_Entry();
+        $entry->link = array(new Zend_Gdata_App_Extension_Link(
+                'http://www.example.com',
+                'edit',
+                'application/atom+xml'));
+        $entry->setEtag($etag);
+        $this->service->updateEntry($entry);
+
+        // Get another entry without ETag set,
+        // Previous value of If-Match HTTP header should not be sent
+        $this->adapter->setResponse($this->httpEntrySample);
+        $entry = $this->service->getEntry('http://www.example.com');
+        $headers = $this->adapter->popRequest()->headers;
+        $found = false;
+        foreach ($headers as $header) {
+            if ($header == 'If-Match: ' . $etag)
+                $found = true;
+        }
+        $this->assertFalse($found, 'If-Match header found');
+    }
+
     public function testGenerateIfMatchHeaderDataReturnsEtagIfV2() {
         $etag = 'ABCD1234';
         $this->service->setMajorProtocolVersion(2);