ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
CAS_Request_CurlRequest Class Reference

Provides support for performing web-requests via curl. More...

+ Inheritance diagram for CAS_Request_CurlRequest:
+ Collaboration diagram for CAS_Request_CurlRequest:

Public Member Functions

 setCurlOptions (array $options)
 Set additional curl options. More...
 
 initAndConfigure ()
 Internal method to initialize our cURL handle and configure the request. More...
 
- Public Member Functions inherited from CAS_Request_AbstractRequest
 setUrl ($url)
 Set the URL of the Request. More...
 
 addCookie ($name, $value)
 Add a cookie to the request. More...
 
 addCookies (array $cookies)
 Add an array of cookies to the request. More...
 
 addHeader ($header)
 Add a header string to the request. More...
 
 addHeaders (array $headers)
 Add an array of header strings to the request. More...
 
 makePost ()
 Make the request a POST request rather than the default GET request. More...
 
 setPostBody ($body)
 Add a POST body to the request. More...
 
 setSslCaCert ($caCertPath, $validate_cn=true)
 Specify the path to an SSL CA certificate to validate the server with. More...
 
 send ()
 Perform the request. More...
 
 getResponseHeaders ()
 Answer the headers of the response. More...
 
 getResponseStatusCode ()
 Answer HTTP status code of the response. More...
 
 getResponseBody ()
 Answer the body of response. More...
 
 getErrorMessage ()
 Answer a message describing any errors if the request failed. More...
 
 setUrl ($url)
 Set the URL of the Request. More...
 
 addCookie ($name, $value)
 Add a cookie to the request. More...
 
 addCookies (array $cookies)
 Add an array of cookies to the request. More...
 
 addHeader ($header)
 Add a header string to the request. More...
 
 addHeaders (array $headers)
 Add an array of header strings to the request. More...
 
 makePost ()
 Make the request a POST request rather than the default GET request. More...
 
 setPostBody ($body)
 Add a POST body to the request. More...
 
 setSslCaCert ($caCertPath, $validate_cn=true)
 Specify the path to an SSL CA certificate to validate the server with. More...
 
 send ()
 Perform the request. More...
 
 getResponseHeaders ()
 Answer the headers of the response. More...
 
 getResponseStatusCode ()
 Answer HTTP status code of the response. More...
 
 getResponseBody ()
 Answer the body of response. More...
 
 getErrorMessage ()
 Answer a message describing any errors if the request failed. More...
 

Protected Member Functions

 sendRequest ()
 Send the request and store the results. More...
 
- Protected Member Functions inherited from CAS_Request_AbstractRequest
 sendRequest ()
 Send the request and store the results. More...
 
 storeResponseHeaders (array $headers)
 Store the response headers. More...
 
 storeResponseHeader ($header)
 Store a single response header to our array. More...
 
 storeResponseBody ($body)
 Store the response body. More...
 
 storeErrorMessage ($message)
 Add a string to our error message. More...
 

Private Member Functions

 _storeResponseBody ($body)
 Store the response body. More...
 
 _curlReadHeaders ($ch, $header)
 Internal method for capturing the headers from a curl request. More...
 

Private Attributes

 $_curlOptions = array()
 

Additional Inherited Members

- Protected Attributes inherited from CAS_Request_AbstractRequest
 $url = null
 
 $cookies = array()
 
 $headers = array()
 
 $isPost = false
 
 $postBody = null
 
 $caCertPath = null
 
 $validateCN = true
 

Detailed Description

Provides support for performing web-requests via curl.

Definition at line 40 of file CurlRequest.php.

Member Function Documentation

◆ _curlReadHeaders()

CAS_Request_CurlRequest::_curlReadHeaders (   $ch,
  $header 
)
private

Internal method for capturing the headers from a curl request.

Parameters
handle$chhandle of curl
string$headerheader
Returns
void

Definition at line 195 of file CurlRequest.php.

196 {
198 return strlen($header);
199 }
storeResponseHeader($header)
Store a single response header to our array.

References $header, and CAS_Request_AbstractRequest\storeResponseHeader().

+ Here is the call graph for this function:

◆ _storeResponseBody()

CAS_Request_CurlRequest::_storeResponseBody (   $body)
private

Store the response body.

This method should NOT be used outside of the CurlRequest or the CurlMultiRequest.

Parameters
string$bodybody to stor
Returns
void

Definition at line 182 of file CurlRequest.php.

183 {
184 $this->storeResponseBody($body);
185 }
storeResponseBody($body)
Store the response body.

References CAS_Request_AbstractRequest\storeResponseBody().

+ Here is the call graph for this function:

◆ initAndConfigure()

CAS_Request_CurlRequest::initAndConfigure ( )

Internal method to initialize our cURL handle and configure the request.

This method should NOT be used outside of the CurlRequest or the CurlMultiRequest.

Returns
resource The cURL handle on success, false on failure

Definition at line 102 of file CurlRequest.php.

103 {
104 /*********************************************************
105 * initialize the CURL session
106 *********************************************************/
107 $ch = curl_init($this->url);
108
109 if (version_compare(PHP_VERSION, '5.1.3', '>=')) {
110 //only avaible in php5
111 curl_setopt_array($ch, $this->_curlOptions);
112 } else {
113 foreach ($this->_curlOptions as $key => $value) {
114 curl_setopt($ch, $key, $value);
115 }
116 }
117
118 /*********************************************************
119 * Set SSL configuration
120 *********************************************************/
121 if ($this->caCertPath) {
122 if ($this->validateCN) {
123 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
124 } else {
125 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
126 }
127 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
128 curl_setopt($ch, CURLOPT_CAINFO, $this->caCertPath);
129 phpCAS::trace('CURL: Set CURLOPT_CAINFO ' . $this->caCertPath);
130 } else {
131 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
132 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
133 }
134
135 /*********************************************************
136 * Configure curl to capture our output.
137 *********************************************************/
138 // return the CURL output into a variable
139 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
140
141 // get the HTTP header with a callback
142 curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, '_curlReadHeaders'));
143
144 /*********************************************************
145 * Add cookie headers to our request.
146 *********************************************************/
147 if (count($this->cookies)) {
148 $cookieStrings = array();
149 foreach ($this->cookies as $name => $val) {
150 $cookieStrings[] = $name.'='.$val;
151 }
152 curl_setopt($ch, CURLOPT_COOKIE, implode(';', $cookieStrings));
153 }
154
155 /*********************************************************
156 * Add any additional headers
157 *********************************************************/
158 if (count($this->headers)) {
159 curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
160 }
161
162 /*********************************************************
163 * Flag and Body for POST requests
164 *********************************************************/
165 if ($this->isPost) {
166 curl_setopt($ch, CURLOPT_POST, 1);
167 curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postBody);
168 }
169
170 return $ch;
171 }
$key
Definition: croninfo.php:18
static trace($str)
This method is used to log something in debug mode.
Definition: CAS.php:579
if($format !==null) $name
Definition: metadata.php:146

References $key, $name, and phpCAS\trace().

Referenced by sendRequest().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendRequest()

CAS_Request_CurlRequest::sendRequest ( )
protected

Send the request and store the results.

Returns
bool true on success, false on failure.

Reimplemented from CAS_Request_AbstractRequest.

Definition at line 63 of file CurlRequest.php.

64 {
66
67 /*********************************************************
68 * initialize the CURL session
69 *********************************************************/
70 $ch = $this->initAndConfigure();
71
72 /*********************************************************
73 * Perform the query
74 *********************************************************/
75 $buf = curl_exec($ch);
76 if ( $buf === false ) {
77 phpCAS::trace('curl_exec() failed');
78 $this->storeErrorMessage(
79 'CURL error #'.curl_errno($ch).': '.curl_error($ch)
80 );
81 $res = false;
82 } else {
83 $this->storeResponseBody($buf);
84 phpCAS::trace("Response Body: \n".$buf."\n");
85 $res = true;
86
87 }
88 // close the CURL session
89 curl_close($ch);
90
92 return $res;
93 }
storeErrorMessage($message)
Add a string to our error message.
initAndConfigure()
Internal method to initialize our cURL handle and configure the request.
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
Definition: CAS.php:638
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode.
Definition: CAS.php:591
foreach($_POST as $key=> $value) $res

References $res, initAndConfigure(), CAS_Request_AbstractRequest\storeErrorMessage(), CAS_Request_AbstractRequest\storeResponseBody(), phpCAS\trace(), phpCAS\traceBegin(), and phpCAS\traceEnd().

+ Here is the call graph for this function:

◆ setCurlOptions()

CAS_Request_CurlRequest::setCurlOptions ( array  $options)

Set additional curl options.

Parameters
array$optionsoption to set
Returns
void

Definition at line 52 of file CurlRequest.php.

53 {
54 $this->_curlOptions = $options;
55 }
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20

References $options.

Field Documentation

◆ $_curlOptions

CAS_Request_CurlRequest::$_curlOptions = array()
private

Definition at line 56 of file CurlRequest.php.


The documentation for this class was generated from the following file: