/** * Build and perform a request, following redirects * * @param string $url * @return void * @throws CAS_ProxyTicketException If there is a proxy-ticket failure. * The code of the Exception will be one of: * PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE * PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE * PHPCAS_SERVICE_PT_FAILURE * @throws CAS_ProxiedService_Exception If there is a failure sending the request to the target service. */ protected function makeRequest($url) { // Verify that we are not in a redirect loop $this->_numRequests++; if ($this->_numRequests > 4) { $message = 'Exceeded the maximum number of redirects (3) in proxied service request.'; phpCAS::trace($message); throw new CAS_ProxiedService_Exception($message); } // Create a new request. $request = clone $this->_requestHandler; $request->setUrl($url); // Add any cookies to the request. $request->addCookies($this->_cookieJar->getCookies($url)); // Add any other parts of the request needed by concrete classes $this->populateRequest($request); // Perform the request. phpCAS::trace('Performing proxied service request to \'' . $url . '\''); if (!$request->send()) { $message = 'Could not perform proxied service request to URL`' . $url . '\'. ' . $request->getErrorMessage(); phpCAS::trace($message); throw new CAS_ProxiedService_Exception($message); } // Store any cookies from the response; $this->_cookieJar->storeCookies($url, $request->getResponseHeaders()); // Follow any redirects if ($redirectUrl = $this->getRedirectUrl($request->getResponseHeaders())) { phpCAS::trace('Found redirect:' . $redirectUrl); $this->makeRequest($redirectUrl); } else { $this->_responseHeaders = $request->getResponseHeaders(); $this->_responseBody = $request->getResponseBody(); $this->_responseStatusCode = $request->getResponseStatusCode(); } }
/** * Answer the cookies from the response. This may include cookies set during * redirect responses. * * @return array An array containing cookies. E.g. array('name' => 'val'); */ public function getCookies() { return $this->_cookieJar->getCookies($this->getServiceUrl()); }
/** * Verify that cookies are getting stored in our storage array. * * @return void */ public function testPublicStoreCookies() { $array = array(); $cookieJar = new CAS_CookieJar($array); $this->assertEquals(0, count($array)); $cookieJar->storeCookies($this->serviceUrl_1, $this->responseHeaders_1); $this->assertEquals(1, count($array)); }