File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 544544 'metadata.sign.privatekey_pass ' => NULL ,
545545 'metadata.sign.certificate ' => NULL ,
546546
547- );
548547
548+ /*
549+ * Proxy to use for retrieving URLs.
550+ *
551+ * Example:
552+ * 'proxy' => 'tcp://proxy.example.com:5100'
553+ */
554+ 'proxy ' => NULL ,
549555
550- ?>
556+ );
Original file line number Diff line number Diff line change @@ -1950,6 +1950,39 @@ public static function debugMessage($message, $type) {
19501950 }
19511951 }
19521952
1953- }
19541953
1955- ?>
1954+ /**
1955+ * Helper function to retrieve a file or URL with proxy support.
1956+ *
1957+ * An exception will be thrown if we are unable to retrieve the data.
1958+ *
1959+ * @param string $path The path or URL we should fetch.
1960+ * @param array $context Extra context options. This parameter is optional.
1961+ * @return string The data we fetched.
1962+ */
1963+ public static function fetch ($ path , $ context = array ()) {
1964+ assert ('is_string($path) ' );
1965+
1966+ $ config = SimpleSAML_Configuration::getInstance ();
1967+
1968+ $ proxy = $ config ->getString ('proxy ' , NULL );
1969+ if ($ proxy !== NULL ) {
1970+ if (!isset ($ context ['http ' ]['proxy ' ])) {
1971+ $ context ['http ' ]['proxy ' ] = $ proxy ;
1972+ }
1973+ if (!isset ($ context ['http ' ]['request_fulluri ' ])) {
1974+ $ context ['http ' ]['request_fulluri ' ] = TRUE ;
1975+ }
1976+ }
1977+
1978+ $ context = stream_context_create ($ context );
1979+
1980+ $ data = file_get_contents ($ path , FALSE , $ context );
1981+ if ($ data === FALSE ) {
1982+ throw new SimpleSAML_Error_Exception ('Error fetching ' . var_export ($ path , TRUE ) . ': ' . self ::getLastError ());
1983+ }
1984+
1985+ return $ data ;
1986+ }
1987+
1988+ }
You can’t perform that action at this time.
0 commit comments