From ac161241e76c822f00b721804efef7e8a2717427 Mon Sep 17 00:00:00 2001 From: Jaime Perez <jaime.perez@uninett.no> Date: Thu, 7 Aug 2014 20:06:33 +0200 Subject: [PATCH] aggregator2: allow the user to specify the MIME type of the response. --- modules/aggregator2/www/get.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/modules/aggregator2/www/get.php b/modules/aggregator2/www/get.php index 016eef295..8ace0a506 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; -- GitLab