Source code for file /openid/Services/Yadis/PlainHTTPFetcher.php
Documentation is available at PlainHTTPFetcher.php
* This module contains the plain non-curl HTTP fetcher
* LICENSE: See the COPYING file included in this distribution.
* @copyright 2005 Janrain, Inc.
* @license http://www.gnu.org/copyleft/lesser.html LGPL
require_once "Services/Yadis/HTTPFetcher.php";
* This class implements a plain, hand-built socket-based fetcher
* which will be used in the event that CURL is unavailable.
function get($url, $extra_headers =
null)
if (!$this->allowedURL($url)) {
$stop =
time() +
$this->timeout;
while ($redir &&
($off >
0)) {
if ($parts['scheme'] ==
'http') {
} elseif ($parts['scheme'] ==
'https') {
" scheme '" .
$parts['scheme'] .
"', no default port available",
if ($parts['scheme'] ==
'https') {
$host =
'ssl://' .
$host;
$user_agent =
"PHP Yadis Library Fetcher";
"?".
$parts['query'] :
"").
"User-Agent: $user_agent",
($specify_port ?
":".
$parts['port'] :
""),
"Port: ".
$parts['port']);
foreach ($extra_headers as $h) {
@$sock =
fsockopen($host, $parts['port'], $errno, $errstr,
$data .=
fgets($sock, 1024);
// 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]);
if (in_array($code, array('301', '302'))) {
$url =
$this->_findRedirect($headers);
foreach ($headers as $header) {
list
($name, $value) =
explode(": ", $header, 2);
$new_headers[$name] =
$value;
function post($url, $body, $extra_headers =
null)
if (!$this->allowedURL($url)) {
$headers[] =
"POST ".
$parts['path'].
" HTTP/1.0";
$headers[] =
"Host: " .
$parts['host'];
$headers[] =
"Content-type: application/x-www-form-urlencoded";
// 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;
if ($parts['scheme'] ==
'http') {
} elseif ($parts['scheme'] ==
'https') {
"', no default port available",
if ($parts['scheme'] ==
'https') {
$parts['host'] =
sprintf("ssl://%s", $parts['host']);
// Connect to the remote server.
$sock =
fsockopen($parts['host'], $parts['port'], $errno, $errstr,
" port " .
$parts['port'],
// Write the POST request.
// Get the response from the server.
if ($data =
fgets($sock, 128)) {
// 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]);
foreach ($headers as $header) {
list
($name, $value) =
explode(": ", $header, 2);
$new_headers[$name] =
$value;
$headers, $response_body);