70 $this->_cookieJar = $cookieJar;
87 if (empty($this->_url)) {
89 'No URL set via ' . get_class($this) .
'->setUrl($url).' 112 'Cannot set the URL, request already sent.' 115 if (!is_string($url)) {
143 'Cannot send, request already sent.' 152 if (strstr($url,
'?') ===
false) {
160 }
catch (Exception $e) {
211 $this->_numRequests++;
212 if ($this->_numRequests > 4) {
213 $message =
'Exceeded the maximum number of redirects (3) in proxied service request.';
220 $request->setUrl($url);
223 $request->addCookies($this->_cookieJar->getCookies($url));
229 phpCAS::trace(
'Performing proxied service request to \'' . $url .
'\'');
230 if (!$request->send()) {
231 $message =
'Could not perform proxied service request to URL`' 232 . $url .
'\'.
' . $request->getErrorMessage(); 233 phpCAS::trace($message); 234 throw new CAS_ProxiedService_Exception($message); 237 // Store any cookies from the response; 238 $this->_cookieJar->storeCookies($url, $request->getResponseHeaders()); 240 // Follow any redirects 241 if ($redirectUrl = $this->getRedirectUrl($request->getResponseHeaders()) 243 phpCAS::trace('Found redirect:
' . $redirectUrl); 244 $this->makeRequest($redirectUrl); 247 $this->_responseHeaders = $request->getResponseHeaders(); 248 $this->_responseBody = $request->getResponseBody(); 249 $this->_responseStatusCode = $request->getResponseStatusCode(); 260 abstract protected function populateRequest( 261 CAS_Request_RequestInterface $request 271 protected function getRedirectUrl(array $responseHeaders) 273 // Check for the redirect after authentication 274 foreach ($responseHeaders as $header) { 275 if ( preg_match('/^(Location:|URI:)\s*([^\s]+.*)$/
', $header, $matches) 277 return trim(array_pop($matches)); 283 /********************************************************* 284 * 3. Access the response 285 *********************************************************/ 292 protected function hasBeenSent() 294 return ($this->_numRequests > 0); 303 public function getResponseHeaders() 305 if (!$this->hasBeenSent()) { 306 throw new CAS_OutOfSequenceException( 307 'Cannot access response, request not sent yet.
' 311 return $this->_responseHeaders; 320 public function getResponseStatusCode() 322 if (!$this->hasBeenSent()) { 323 throw new CAS_OutOfSequenceException( 324 'Cannot access response, request not sent yet.
' 328 return $this->_responseStatusCode; 337 public function getResponseBody() 339 if (!$this->hasBeenSent()) { 340 throw new CAS_OutOfSequenceException( 341 'Cannot access response, request not sent yet.
' 345 return $this->_responseBody; 354 public function getCookies() 356 return $this->_cookieJar->getCookies($this->getServiceUrl());
__construct(CAS_Request_RequestInterface $requestHandler, CAS_CookieJar $cookieJar)
populateRequest(CAS_Request_RequestInterface $request)