]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Request.php
Added more complexity in an attempt to make ldap host failover fit
[bookstack] / app / Http / Request.php
index 183686f67b4eef3a6299c2cb2e25893b4f4c4a61..4cbdf34bae6ac266463776d9e825be5128abdc9c 100644 (file)
@@ -1,25 +1,45 @@
-<?php namespace BookStack\Http;
+<?php
+
+namespace BookStack\Http;
 
 use Illuminate\Http\Request as LaravelRequest;
 
 class Request extends LaravelRequest
 {
-
     /**
      * Override the default request methods to get the scheme and host
-     * to set the custom APP_URL, if set.
-     * @return \Illuminate\Config\Repository|mixed|string
+     * to directly use the custom APP_URL, if set.
+     *
+     * @return string
      */
     public function getSchemeAndHttpHost()
     {
-        $base = config('app.url', null);
+        $appUrl = config('app.url', null);
+
+        if ($appUrl) {
+            return implode('/', array_slice(explode('/', $appUrl), 0, 3));
+        }
+
+        return parent::getSchemeAndHttpHost();
+    }
+
+    /**
+     * Override the default request methods to get the base URL
+     * to directly use the custom APP_URL, if set.
+     * The base URL never ends with a / but should start with one if not empty.
+     *
+     * @return string
+     */
+    public function getBaseUrl()
+    {
+        $appUrl = config('app.url', null);
+
+        if ($appUrl) {
+            $parsedBaseUrl = rtrim(implode('/', array_slice(explode('/', $appUrl), 3)), '/');
 
-        if ($base) {
-            $base = trim($base, '/');
-        } else {
-            $base = $this->getScheme().'://'.$this->getHttpHost();
+            return empty($parsedBaseUrl) ? '' : ('/' . $parsedBaseUrl);
         }
 
-        return $base;
+        return parent::getBaseUrl();
     }
 }