From 6d8d90cff4487f2c6833e306c58f74461d99e2e4 Mon Sep 17 00:00:00 2001
From: Dominik Hebeler <dominik@suma-ev.de>
Date: Wed, 4 Sep 2019 08:59:30 +0200
Subject: [PATCH] fixed an error in location redirects

---
 app/Http/Controllers/ProxyController.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/app/Http/Controllers/ProxyController.php b/app/Http/Controllers/ProxyController.php
index f234207..f03eee2 100644
--- a/app/Http/Controllers/ProxyController.php
+++ b/app/Http/Controllers/ProxyController.php
@@ -132,13 +132,14 @@ class ProxyController extends Controller
 
         $targetUrl = str_replace("<<SLASH>>", "/", $url);
         $targetUrl = str_rot13(base64_decode($targetUrl));
+
         $this->password = $password;
         // Hash Value under which a possible cached file would've been stored
         $hash = md5($targetUrl);
         $result = [];
         $httpcode = 200;
 
-        if (!Cache::has($hash)) {
+        if (!Cache::has($hash) || env("CACHE_ENABLED") === false) {
             // Inits the Curl connection for being able to preload multiple URLs while using a keep-alive connection
             $this->initCurl();
             $result = $this->getUrlContent($targetUrl, false);
@@ -320,6 +321,7 @@ class ProxyController extends Controller
 
             $data = substr($data, $header_size);
             $headerArray = [];
+
             foreach (explode(PHP_EOL, $header) as $index => $value) {
                 if ($index > 0) {
                     $ar = explode(': ', $value);
@@ -330,15 +332,13 @@ class ProxyController extends Controller
                             $headerArray[strtolower(trim($ar[0]))] = strtolower(trim($ar[1]));
                         } elseif (strtolower($ar[0]) === "location") {
                             $redLink = $ar[1];
-
                             if (strpos($redLink, "/") === 0) {
                                 $parse = parse_url($url);
                                 $redLink = $parse["scheme"] . "://" . $parse["host"] . $redLink;
-                            } else if (preg_match("/\w+\.\w+/si", $redLink)) {
+                            } else if (preg_match("/^\w+\.\w+$/si", $redLink)) {
                                 $parse = parse_url($url);
                                 $redLink = $parse["scheme"] . "://" . $parse["host"] . "/" . $redLink;
                             }
-
                             $headerArray[trim($ar[0])] = $this->proxifyUrl($redLink, null, false);
                         } elseif (strtolower($ar[0]) === "content-disposition") {
                             $headerArray[strtolower(trim($ar[0]))] = strtolower(trim($ar[1]));
-- 
GitLab