From b2996720689a9372524a556c09ac1fc1105e81f2 Mon Sep 17 00:00:00 2001
From: Dick Visser <dick.visser@geant.org>
Date: Sat, 13 Aug 2022 00:41:03 +0200
Subject: [PATCH] Actually handle ETag/If-None-Match logic (#1673)

* Actually handle ETag/If-None-Match logic

* send metadata when no match

* Simplify if else

* Fix syntax error + coding style

Co-authored-by: Tim van Dijen <tvdijen@gmail.com>
---
 www/saml2/idp/metadata.php | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/www/saml2/idp/metadata.php b/www/saml2/idp/metadata.php
index 93bc28b51..4315778bf 100644
--- a/www/saml2/idp/metadata.php
+++ b/www/saml2/idp/metadata.php
@@ -242,9 +242,15 @@ try {
         $t->data['metadataflat'] = htmlspecialchars($metaflat);
         $t->show();
     } else {
+        $etag = '"' . hash('sha256', $metaxml) . '"';
+        if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
+            if ($_SERVER['HTTP_IF_NONE_MATCH'] === $etag) {
+                header("HTTP/1.1 304 Not Modified");
+                exit(0);
+            }
+        }
         header('Content-Type: application/samlmetadata+xml');
-        header('ETag: "' . hash('sha256', $metaxml) . '"');
-
+        header('ETag: ' . $etag);
         echo $metaxml;
         exit(0);
     }
-- 
GitLab