-
Jaime Perez Crespo authored
Be graceful with the 'baseurlpath' configuration option. We should not fail when the trailing slash is missing, just add it.
Jaime Perez Crespo authoredBe graceful with the 'baseurlpath' configuration option. We should not fail when the trailing slash is missing, just add it.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
HTTP.php 41.02 KiB
<?php
namespace SimpleSAML\Utils;
use SimpleSAML\Module;
use SimpleSAML\Logger;
/**
* HTTP-related utility methods.
*
* @package SimpleSAMLphp
*/
class HTTP
{
/**
* Obtain a URL where we can redirect to securely post a form with the given data to a specific destination.
*
* @param string $destination The destination URL.
* @param array $data An associative array containing the data to be posted to $destination.
*
* @return string A URL which allows to securely post a form to $destination.
*
* @author Jaime Perez, UNINETT AS <jaime.perez@uninett.no>
*/
private static function getSecurePOSTRedirectURL($destination, $data)
{
$session = \SimpleSAML_Session::getSessionFromRequest();
$id = self::savePOSTData($session, $destination, $data);
// encrypt the session ID and the random ID
$info = base64_encode(Crypto::aesEncrypt($session->getSessionId().':'.$id));
$url = Module::getModuleURL('core/postredirect.php', array('RedirInfo' => $info));
return preg_replace('#^https:#', 'http:', $url);
}
/**
* Retrieve Host value from $_SERVER environment variables.
*
* @return string The current host name, including the port if needed. It will use localhost when unable to
* determine the current host.
*
* @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
*/
private static function getServerHost()
{
if (array_key_exists('HTTP_HOST', $_SERVER)) {
$current = $_SERVER['HTTP_HOST'];
} elseif (array_key_exists('SERVER_NAME', $_SERVER)) {
$current = $_SERVER['SERVER_NAME'];
} else {
// almost certainly not what you want, but...
$current = 'localhost';
}
if (strstr($current, ":")) {
$decomposed = explode(":", $current);
$port = array_pop($decomposed);
if (!is_numeric($port)) {
array_push($decomposed, $port);
}
$current = implode($decomposed, ":");
}
return $current;
}
/**
* Retrieve HTTPS status from $_SERVER environment variables.