From a24565003bf6bcd052cdc80f084166b662c79f9f Mon Sep 17 00:00:00 2001
From: David Maus <maus@hab.de>
Date: Thu, 19 Apr 2018 13:28:54 +0200
Subject: [PATCH] =?UTF-8?q?303=20Redirect=20f=C3=BCr=20OPAC-Daten?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 public/instance/proxy/opac-de-23/index.php | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/public/instance/proxy/opac-de-23/index.php b/public/instance/proxy/opac-de-23/index.php
index 55c4b34fd..70c35042d 100644
--- a/public/instance/proxy/opac-de-23/index.php
+++ b/public/instance/proxy/opac-de-23/index.php
@@ -4,6 +4,9 @@ require_once __DIR__ . '/../../../../vendor/autoload.php';
 
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\RedirectResponse;
+
+use Negotiation\Negotiator;
 
 use HAB\Pica\Record\Record;
 use HAB\Pica\Reader\PicaNormReader;
@@ -11,6 +14,7 @@ use HAB\Pica\Writer\PicaXmlWriter;
 
 define('PSI_TEMPLATE', 'http://opac.lbs-braunschweig.gbv.de/DB=2/PLAIN=Y/CHARSET=UTF8/PLAINTTLCHARSET=UTF8/PPN?PPN=%s');
 define('PICA_TEMPLATE', 'http://uri.hab.de/instance/proxy/opac-de-23/%s.xml');
+define('RDF_TEMPLATE', 'http://uri.hab.de/instance/proxy/opac-de-23/%s.rdf');
 
 function terminate (Request $request, Response $response) {
     $response->prepare($request);
@@ -47,7 +51,14 @@ function transform ($sourceUri, $templateUri) {
 $request = Request::createFromGlobals();
 
 $route = basename($request->server->get('REQUEST_URI'));
-if (!preg_match('@^[0-9]{8}[0-9X]\.[a-z]+@', $route)) {
+
+
+if (preg_match('@^(?<ident>[0-9]{8}[0-9X])(?<format>\.[a-z]+)?$@', $route, $match)) {
+    if (!array_key_exists('format', $match)) {
+        $response = new RedirectResponse(sprintf(RDF_TEMPLATE, $match['ident']), 303);
+        terminate($request, $response);
+    }
+} else {
     $response = new Response('<h1>400 Bad Request</h1>', 400, array('Content-Type' => 'text/html'));
     terminate($request, $response);
 }
-- 
GitLab