Permalink
Browse files

attempt to capture / send cookies

  • Loading branch information...
1 parent 209e63e commit 342df19acb31ae0c9f9a59ac9dd587a3f76a782b Shahar Evron committed Feb 21, 2012
Showing with 23 additions and 4 deletions.
  1. +23 −4 library/Zend/Http/Client.php
@@ -466,6 +466,19 @@ protected function prepareRequest(Request $request)
$request->headers()->addHeader($header);
}
}
+
+ $existingCookies = $request->cookie();
+ $cookieHeader = $this->prepareCookies(
+ $existingCookies,
+ $request->uri()->getHost(),
+ $request->uri()->getPath(),
+ $request->uri()->getScheme() == 'https'
+ );
+
+ if ($existingCookies) {
+ $request->headers()->removeHeader($existingCookies);
+ }
+ $request->headers()->addHeader($cookieHeader);
}
protected function handleResponse(Response $response)
@@ -480,12 +493,13 @@ protected function handleResponse(Response $response)
/**
* Prepare Cookies
*
- * @param string $uri
- * @param string $domain
- * @param boolean $secure
+ * @param Zend\Http\Header\Cookie $existingCookies
+ * @param string $domain
+ * @param string $path
+ * @param boolean $secure
* @return Cookie|boolean
*/
- protected function prepareCookies($domain, $path, $secure)
+ protected function prepareCookies($existingCookies, $domain, $path, $secure)
{
$validCookies = array();
@@ -503,6 +517,11 @@ protected function prepareCookies($domain, $path, $secure)
}
$cookies = Cookie::fromSetCookieArray($validCookies);
+ if ($existingCookies instanceof Cookie) {
+ foreach($existingCookies as $cookie) {
+ $cookies->append($cookie);
+ }
+ }
return $cookies;
}

0 comments on commit 342df19

Please sign in to comment.