Permalink
Browse files

Adding getResponseBody() to the RequestInterface and uses a targeted …

…response body with redirects. Closes #228.
  • Loading branch information...
1 parent 449832b commit 7ec33608db269b268ee251368478d39599e67794 @mtdowling mtdowling committed Jan 31, 2013
Showing with 25 additions and 13 deletions.
  1. +12 −12 Message/Request.php
  2. +10 −1 Message/RequestInterface.php
  3. +3 −0 RedirectPlugin.php
View
@@ -562,6 +562,18 @@ public function setResponseBody($body)
/**
* {@inheritdoc}
*/
+ public function getResponseBody()
+ {
+ if ($this->responseBody === null) {
+ $this->responseBody = EntityBody::factory();
+ }
+
+ return $this->responseBody;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function isResponseBodyRepeatable()
{
return !$this->responseBody ? true : $this->responseBody->isSeekable() && $this->responseBody->isReadable();
@@ -698,18 +710,6 @@ protected function changedHeader($header)
}
/**
- * {@inheritdoc}
- */
- protected function getResponseBody()
- {
- if ($this->responseBody === null) {
- $this->responseBody = EntityBody::factory();
- }
-
- return $this->responseBody;
- }
-
- /**
* Get an array containing the request and response for event notifications
*
* @return array
@@ -257,7 +257,7 @@ public function getCurlOptions();
public function receiveResponseHeader($data);
/**
- * Set the EntityBody that will hold the response message's entity body.
+ * Set the EntityBody that will hold a successful response message's entity body.
*
* This method should be invoked when you need to send the response's entity body somewhere other than the normal
* php://temp buffer. For example, you can send the entity body to a socket, file, or some other custom stream.
@@ -269,6 +269,15 @@ public function receiveResponseHeader($data);
public function setResponseBody($body);
/**
+ * Get the EntityBody that will hold the resulting response message's entity body. This response body will only
+ * be used for successful responses. Intermediate responses (e.g. redirects) will not use the targeted response
+ * body.
+ *
+ * @return EntityBodyInterface
+ */
+ public function getResponseBody();
+
+ /**
* Determine if the response body is repeatable (readable + seekable)
*
* @return bool
View
@@ -114,6 +114,9 @@ protected function createRedirectRequest(
$redirectRequest = clone $request;
}
+ // Always use the same response body when redirecting
+ $redirectRequest->setResponseBody($request->getResponseBody());
+
$location = Url::factory($location);
// If the location is not absolute, then combine it with the original URL
if (!$location->isAbsolute()) {

0 comments on commit 7ec3360

Please sign in to comment.