ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Auth_Yadis_PlainHTTPFetcher Class Reference
+ Inheritance diagram for Auth_Yadis_PlainHTTPFetcher:
+ Collaboration diagram for Auth_Yadis_PlainHTTPFetcher:

Public Member Functions

 supportsSSL ()
 Does this fetcher support SSL URLs?
 get ($url, $extra_headers=null)
 Fetches the specified URL using optional extra headers and returns the server's response.
 post ($url, $body, $extra_headers=null)
- Public Member Functions inherited from Auth_Yadis_HTTPFetcher
 canFetchURL ($url)
 Return whether a URL can be fetched.
 allowedURL ($url)
 Return whether a URL should be allowed.
 isHTTPS ($url)
 Is this an https URL?
 URLHasAllowedScheme ($url)
 Is this an http or https URL?
 _findRedirect ($headers, $url)
 private

Additional Inherited Members

- Data Fields inherited from Auth_Yadis_HTTPFetcher
 $timeout = 20

Detailed Description

Definition at line 28 of file PlainHTTPFetcher.php.

Member Function Documentation

Auth_Yadis_PlainHTTPFetcher::get (   $url,
  $headers = null 
)

Fetches the specified URL using optional extra headers and returns the server's response.

Parameters
string$urlThe URL to be fetched.
array$extra_headersAn array of header strings (e.g. "Accept: text/html").
Returns
mixed $result An array of ($code, $url, $headers, $body) if the URL could be fetched; null if the URL does not pass the URLHasAllowedScheme check or if the server's response is malformed.

Reimplemented from Auth_Yadis_HTTPFetcher.

Definition at line 37 of file PlainHTTPFetcher.php.

References Auth_Yadis_HTTPFetcher\$timeout, Auth_Yadis_HTTPFetcher\_findRedirect(), Auth_OpenID_FETCHER_MAX_RESPONSE_KB, Auth_OpenID_USER_AGENT, and Auth_Yadis_HTTPFetcher\canFetchURL().

{
if (!$this->canFetchURL($url)) {
return null;
}
$redir = true;
$stop = time() + $this->timeout;
while ($redir && ($off > 0)) {
$parts = parse_url($url);
$specify_port = true;
// Set a default port.
if (!array_key_exists('port', $parts)) {
$specify_port = false;
if ($parts['scheme'] == 'http') {
$parts['port'] = 80;
} elseif ($parts['scheme'] == 'https') {
$parts['port'] = 443;
} else {
return null;
}
}
if (!array_key_exists('path', $parts)) {
$parts['path'] = '/';
}
$host = $parts['host'];
if ($parts['scheme'] == 'https') {
$host = 'ssl://' . $host;
}
$user_agent = Auth_OpenID_USER_AGENT;
$headers = array(
"GET ".$parts['path'].
(array_key_exists('query', $parts) ?
"?".$parts['query'] : "").
" HTTP/1.0",
"User-Agent: $user_agent",
"Host: ".$parts['host'].
($specify_port ? ":".$parts['port'] : ""),
"Port: ".$parts['port']);
$errno = 0;
$errstr = '';
if ($extra_headers) {
foreach ($extra_headers as $h) {
$headers[] = $h;
}
}
@$sock = fsockopen($host, $parts['port'], $errno, $errstr,
$this->timeout);
if ($sock === false) {
return false;
}
stream_set_timeout($sock, $this->timeout);
fputs($sock, implode("\r\n", $headers) . "\r\n\r\n");
$data = "";
$kilobytes = 0;
while (!feof($sock) &&
$data .= fgets($sock, 1024);
$kilobytes += 1;
}
fclose($sock);
// Split response into header and body sections
list($headers, $body) = explode("\r\n\r\n", $data, 2);
$headers = explode("\r\n", $headers);
$http_code = explode(" ", $headers[0]);
$code = $http_code[1];
if (in_array($code, array('301', '302'))) {
$url = $this->_findRedirect($headers, $url);
$redir = true;
} else {
$redir = false;
}
$off = $stop - time();
}
$new_headers = array();
foreach ($headers as $header) {
if (preg_match("/:/", $header)) {
$parts = explode(": ", $header, 2);
if (count($parts) == 2) {
list($name, $value) = $parts;
$new_headers[$name] = $value;
}
}
}
return new Auth_Yadis_HTTPResponse($url, $code, $new_headers, $body);
}

+ Here is the call graph for this function:

Auth_Yadis_PlainHTTPFetcher::post (   $url,
  $body,
  $extra_headers = null 
)

Definition at line 151 of file PlainHTTPFetcher.php.

References Auth_Yadis_HTTPFetcher\canFetchURL().

{
if (!$this->canFetchURL($url)) {
return null;
}
$parts = parse_url($url);
$headers = array();
$post_path = $parts['path'];
if (isset($parts['query'])) {
$post_path .= '?' . $parts['query'];
}
$headers[] = "POST ".$post_path." HTTP/1.0";
$headers[] = "Host: " . $parts['host'];
$headers[] = "Content-type: application/x-www-form-urlencoded";
$headers[] = "Content-length: " . strval(strlen($body));
if ($extra_headers &&
is_array($extra_headers)) {
$headers = array_merge($headers, $extra_headers);
}
// Join all headers together.
$all_headers = implode("\r\n", $headers);
// Add headers, two newlines, and request body.
$request = $all_headers . "\r\n\r\n" . $body;
// Set a default port.
if (!array_key_exists('port', $parts)) {
if ($parts['scheme'] == 'http') {
$parts['port'] = 80;
} elseif ($parts['scheme'] == 'https') {
$parts['port'] = 443;
} else {
return null;
}
}
if ($parts['scheme'] == 'https') {
$parts['host'] = sprintf("ssl://%s", $parts['host']);
}
// Connect to the remote server.
$errno = 0;
$errstr = '';
$sock = fsockopen($parts['host'], $parts['port'], $errno, $errstr,
$this->timeout);
if ($sock === false) {
return null;
}
stream_set_timeout($sock, $this->timeout);
// Write the POST request.
fputs($sock, $request);
// Get the response from the server.
$response = "";
while (!feof($sock)) {
if ($data = fgets($sock, 128)) {
$response .= $data;
} else {
break;
}
}
// Split the request into headers and body.
list($headers, $response_body) = explode("\r\n\r\n", $response, 2);
$headers = explode("\r\n", $headers);
// Expect the first line of the headers data to be something
// like HTTP/1.1 200 OK. Split the line on spaces and take
// the second token, which should be the return code.
$http_code = explode(" ", $headers[0]);
$code = $http_code[1];
$new_headers = array();
foreach ($headers as $header) {
if (preg_match("/:/", $header)) {
list($name, $value) = explode(": ", $header, 2);
$new_headers[$name] = $value;
}
}
return new Auth_Yadis_HTTPResponse($url, $code,
$new_headers, $response_body);
}

+ Here is the call graph for this function:

Auth_Yadis_PlainHTTPFetcher::supportsSSL ( )

Does this fetcher support SSL URLs?

Reimplemented from Auth_Yadis_HTTPFetcher.

Definition at line 32 of file PlainHTTPFetcher.php.

{
return function_exists('openssl_open');
}

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