diff --git a/modules/aggregator2/www/get.php b/modules/aggregator2/www/get.php index 016eef2956118412f6948142a5d2d48b8820e5b0..8ace0a5061301ed683cd0df25ef070d85f2c8a4d 100644 --- a/modules/aggregator2/www/get.php +++ b/modules/aggregator2/www/get.php @@ -1,14 +1,29 @@ <?php if (!isset($_REQUEST['id'])) { - throw new SimpleSAML_Error_BadRequest('Missing required id-parameter.'); + throw new SimpleSAML_Error_BadRequest('Missing required parameter "id".'); } -$id = (string)$_REQUEST['id']; +$id = (string) $_REQUEST['id']; $aggregator = sspmod_aggregator2_Aggregator::getAggregator($id); $xml = $aggregator->getMetadata(); -header('Content-Type: application/samlmetadata+xml'); +$mimetype = 'application/samlmetadata+xml'; +$allowedmimetypes = array( + 'text/plain', + 'application/samlmetadata-xml', + 'application/xml', +); + +if (isset($_GET['mimetype']) && in_array($_GET['mimetype'], $allowedmimetypes)) { + $mimetype = $_GET['mimetype']; +} + +if ($mimetype === 'text/plain') { + $xml = SimpleSAML_Utilities::formatXMLString($xml); +} + +header('Content-Type: '.$mimetype); header('Content-Length: ' . strlen($xml)); /* @@ -17,4 +32,4 @@ header('Content-Length: ' . strlen($xml)); */ header('Content-Disposition: filename='.$id.'.xml'); -echo($xml); +echo $xml;