Skip to content
Snippets Groups Projects
Commit b7953df9 authored by Olav Morken's avatar Olav Morken
Browse files

Utilities: Add fetch()-function, for retrieving URLs via a proxy.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2659 44740490-163a-0410-bde0-09ae8108e29a
parent e70c8271
No related branches found
No related tags found
No related merge requests found
......@@ -544,7 +544,13 @@ $config = array (
'metadata.sign.privatekey_pass' => NULL,
'metadata.sign.certificate' => NULL,
);
/*
* Proxy to use for retrieving URLs.
*
* Example:
* 'proxy' => 'tcp://proxy.example.com:5100'
*/
'proxy' => NULL,
?>
\ No newline at end of file
);
......@@ -1950,6 +1950,39 @@ class SimpleSAML_Utilities {
}
}
}
?>
\ No newline at end of file
/**
* Helper function to retrieve a file or URL with proxy support.
*
* An exception will be thrown if we are unable to retrieve the data.
*
* @param string $path The path or URL we should fetch.
* @param array $context Extra context options. This parameter is optional.
* @return string The data we fetched.
*/
public static function fetch($path, $context = array()) {
assert('is_string($path)');
$config = SimpleSAML_Configuration::getInstance();
$proxy = $config->getString('proxy', NULL);
if ($proxy !== NULL) {
if (!isset($context['http']['proxy'])) {
$context['http']['proxy'] = $proxy;
}
if (!isset($context['http']['request_fulluri'])) {
$context['http']['request_fulluri'] = TRUE;
}
}
$context = stream_context_create($context);
$data = file_get_contents($path, FALSE, $context);
if ($data === FALSE) {
throw new SimpleSAML_Error_Exception('Error fetching ' . var_export($path, TRUE) . ':' . self::getLastError());
}
return $data;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment