History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: ZF-2723
Type: Patch Patch
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Matthew Weier O'Phinney
Reporter: Ben Ramsey
Votes: 8
Watchers: 4
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

Support checking other HTTP requests and retrieving raw entity body in Zend_Controller_Request_Http

Created: 24/Feb/08 01:38 PM   Updated: 21/Mar/08 05:31 PM  Due: 07/Mar/08
Component/s: Zend_Controller
Affects Version/s: 1.5.0RC1
Fix Version/s: 1.5.0

Time Tracking:
Original Estimate: 30 minutes
Original Estimate - 30 minutes
Remaining Estimate: 30 minutes
Remaining Estimate - 30 minutes
Time Spent: Not Specified
Remaining Estimate - 30 minutes

Fix Version Priority: Should Have


 Description  « Hide
For some recent RESTful architecture development I was working on, I came across the need to to use Zend_Controller_Request_Http to check for other HTTP requests than POST and to also access the raw entity body of the posted or put request. To achieve this, we extended Zend_Controller_Request_Http and added the needed methods and then set the Zend Framework request to our child class using the front controller's setRequest() method. However, I think these methods should be incorporated back into the Zend Framework itself.

Patch follows...

library.diff
--- library/Zend/Controller/Request/Http.php	(revision 8365)
+++ library/Zend/Controller/Request/Http.php	(working copy)
@@ -742,6 +742,92 @@
     }
 
     /**
+     * Was the request made by GET?
+     *
+     * @return boolean
+     */
+    public function isGet()
+    {
+        if ('GET' == $this->getMethod()) {
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * Was the request made by PUT?
+     *
+     * @return boolean
+     */
+    public function isPut()
+    {
+        if ('PUT' == $this->getMethod()) {
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * Was the request made by DELETE?
+     *
+     * @return boolean
+     */
+    public function isDelete()
+    {
+        if ('DELETE' == $this->getMethod()) {
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * Was the request made by HEAD?
+     *
+     * @return boolean
+     */
+    public function isHead()
+    {
+        if ('HEAD' == $this->getMethod()) {
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * Was the request made by OPTIONS?
+     *
+     * @return boolean
+     */
+    public function isOptions()
+    {
+        if ('OPTIONS' == $this->getMethod()) {
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * Return the raw entity body of the request, if present
+     *
+     * @return string|false Raw entity body, or false if not present
+     */
+    public function getEntityBody()
+    {
+        $body = file_get_contents('php://input');
+
+        if (strlen(trim($body)) > 0) {
+            return $body;
+        }
+
+        return false;
+    }
+
+    /**
      * Return the value of the given HTTP header. Pass the header name as the
      * plain, HTTP-specified header name. Ex.: Ask for 'Accept' to get the
      * Accept header, 'Accept-Encoding' to get the Accept-Encoding header.


 All   Comments   Work Log   Change History   FishEye   Crucible      Sort Order: Ascending order - Click to sort in descending order
Matthew Weier O'Phinney - 06/Mar/08 09:07 AM
Scheduling for 1.5.0 RC2

Matthew Weier O'Phinney - 06/Mar/08 09:34 PM
Committed to trunk and 1.5 release branch, with one change: getEntityBody() was changed to getRawBody() to more closely follow PHP docs and typical descriptions of that particular request usage.

Documentation was commited to the request documentation to cover the new functionality.


Ben Ramsey - 12/Mar/08 12:53 PM
Changing the name to getRawBody() is fine since all the PHP documentation already refers to it as the "raw" body. Though, my usage of "entity" more properly reflects the terminology used by RFC 2616, specifically http://tools.ietf.org/html/rfc2616#section-7. There is no distinction in HTTP of "raw" versus "processed" data in the entity body. This distinction occurs in PHP because of the $_POST superglobal array that processes the url-encoded entity body and constructs a PHP array out the parameters.

Just wanted to give my reasoning for using "entity" instead of "raw."