Öffentliche Methoden | |
supportsSSL () | |
get ($url, $extra_headers=null) | |
post ($url, $body, $extra_headers=null) |
Definiert in Zeile 28 der Datei PlainHTTPFetcher.php.
get | ( | $ | url, | |
$ | headers = null | |||
) |
Fetches the specified URL using optional extra headers and returns the server's response.
string | $url The URL to be fetched. | |
array | $extra_headers An array of header strings (e.g. "Accept: text/html"). |
Erneute Implementation von Auth_Yadis_HTTPFetcher.
Definiert in Zeile 37 der Datei PlainHTTPFetcher.php.
00038 { 00039 if (!$this->canFetchURL($url)) { 00040 return null; 00041 } 00042 00043 $redir = true; 00044 00045 $stop = time() + $this->timeout; 00046 $off = $this->timeout; 00047 00048 while ($redir && ($off > 0)) { 00049 00050 $parts = parse_url($url); 00051 00052 $specify_port = true; 00053 00054 // Set a default port. 00055 if (!array_key_exists('port', $parts)) { 00056 $specify_port = false; 00057 if ($parts['scheme'] == 'http') { 00058 $parts['port'] = 80; 00059 } elseif ($parts['scheme'] == 'https') { 00060 $parts['port'] = 443; 00061 } else { 00062 return null; 00063 } 00064 } 00065 00066 if (!array_key_exists('path', $parts)) { 00067 $parts['path'] = '/'; 00068 } 00069 00070 $host = $parts['host']; 00071 00072 if ($parts['scheme'] == 'https') { 00073 $host = 'ssl://' . $host; 00074 } 00075 00076 $user_agent = Auth_OpenID_USER_AGENT; 00077 00078 $headers = array( 00079 "GET ".$parts['path']. 00080 (array_key_exists('query', $parts) ? 00081 "?".$parts['query'] : ""). 00082 " HTTP/1.0", 00083 "User-Agent: $user_agent", 00084 "Host: ".$parts['host']. 00085 ($specify_port ? ":".$parts['port'] : ""), 00086 "Port: ".$parts['port']); 00087 00088 $errno = 0; 00089 $errstr = ''; 00090 00091 if ($extra_headers) { 00092 foreach ($extra_headers as $h) { 00093 $headers[] = $h; 00094 } 00095 } 00096 00097 @$sock = fsockopen($host, $parts['port'], $errno, $errstr, 00098 $this->timeout); 00099 if ($sock === false) { 00100 return false; 00101 } 00102 00103 stream_set_timeout($sock, $this->timeout); 00104 00105 fputs($sock, implode("\r\n", $headers) . "\r\n\r\n"); 00106 00107 $data = ""; 00108 $kilobytes = 0; 00109 while (!feof($sock) && 00110 $kilobytes < Auth_OpenID_FETCHER_MAX_RESPONSE_KB ) { 00111 $data .= fgets($sock, 1024); 00112 $kilobytes += 1; 00113 } 00114 00115 fclose($sock); 00116 00117 // Split response into header and body sections 00118 list($headers, $body) = explode("\r\n\r\n", $data, 2); 00119 $headers = explode("\r\n", $headers); 00120 00121 $http_code = explode(" ", $headers[0]); 00122 $code = $http_code[1]; 00123 00124 if (in_array($code, array('301', '302'))) { 00125 $url = $this->_findRedirect($headers); 00126 $redir = true; 00127 } else { 00128 $redir = false; 00129 } 00130 00131 $off = $stop - time(); 00132 } 00133 00134 $new_headers = array(); 00135 00136 foreach ($headers as $header) { 00137 if (preg_match("/:/", $header)) { 00138 $parts = explode(": ", $header, 2); 00139 00140 if (count($parts) == 2) { 00141 list($name, $value) = $parts; 00142 $new_headers[$name] = $value; 00143 } 00144 } 00145 00146 } 00147 00148 return new Auth_Yadis_HTTPResponse($url, $code, $new_headers, $body); 00149 }
post | ( | $ | url, | |
$ | body, | |||
$ | extra_headers = null | |||
) |
Definiert in Zeile 151 der Datei PlainHTTPFetcher.php.
00152 { 00153 if (!$this->canFetchURL($url)) { 00154 return null; 00155 } 00156 00157 $parts = parse_url($url); 00158 00159 $headers = array(); 00160 00161 $post_path = $parts['path']; 00162 if (isset($parts['query'])) { 00163 $post_path .= '?' . $parts['query']; 00164 } 00165 00166 $headers[] = "POST ".$post_path." HTTP/1.0"; 00167 $headers[] = "Host: " . $parts['host']; 00168 $headers[] = "Content-type: application/x-www-form-urlencoded"; 00169 $headers[] = "Content-length: " . strval(strlen($body)); 00170 00171 if ($extra_headers && 00172 is_array($extra_headers)) { 00173 $headers = array_merge($headers, $extra_headers); 00174 } 00175 00176 // Join all headers together. 00177 $all_headers = implode("\r\n", $headers); 00178 00179 // Add headers, two newlines, and request body. 00180 $request = $all_headers . "\r\n\r\n" . $body; 00181 00182 // Set a default port. 00183 if (!array_key_exists('port', $parts)) { 00184 if ($parts['scheme'] == 'http') { 00185 $parts['port'] = 80; 00186 } elseif ($parts['scheme'] == 'https') { 00187 $parts['port'] = 443; 00188 } else { 00189 return null; 00190 } 00191 } 00192 00193 if ($parts['scheme'] == 'https') { 00194 $parts['host'] = sprintf("ssl://%s", $parts['host']); 00195 } 00196 00197 // Connect to the remote server. 00198 $errno = 0; 00199 $errstr = ''; 00200 00201 $sock = fsockopen($parts['host'], $parts['port'], $errno, $errstr, 00202 $this->timeout); 00203 00204 if ($sock === false) { 00205 return null; 00206 } 00207 00208 stream_set_timeout($sock, $this->timeout); 00209 00210 // Write the POST request. 00211 fputs($sock, $request); 00212 00213 // Get the response from the server. 00214 $response = ""; 00215 while (!feof($sock)) { 00216 if ($data = fgets($sock, 128)) { 00217 $response .= $data; 00218 } else { 00219 break; 00220 } 00221 } 00222 00223 // Split the request into headers and body. 00224 list($headers, $response_body) = explode("\r\n\r\n", $response, 2); 00225 00226 $headers = explode("\r\n", $headers); 00227 00228 // Expect the first line of the headers data to be something 00229 // like HTTP/1.1 200 OK. Split the line on spaces and take 00230 // the second token, which should be the return code. 00231 $http_code = explode(" ", $headers[0]); 00232 $code = $http_code[1]; 00233 00234 $new_headers = array(); 00235 00236 foreach ($headers as $header) { 00237 if (preg_match("/:/", $header)) { 00238 list($name, $value) = explode(": ", $header, 2); 00239 $new_headers[$name] = $value; 00240 } 00241 00242 } 00243 00244 return new Auth_Yadis_HTTPResponse($url, $code, 00245 $new_headers, $response_body); 00246 }
supportsSSL | ( | ) |
Does this fetcher support SSL URLs?
Erneute Implementation von Auth_Yadis_HTTPFetcher.
Definiert in Zeile 32 der Datei PlainHTTPFetcher.php.
Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved. MyOOS [Shopsystem] is Free Software released under the GNU/GPL License. Webmaster: info@r23.de (Impressum) |
|