BookStack/app/Http/Request.php
Dan Brown ebc69a8f2c
Fixed double path slash URL issue in some cases
- Occurred on system request path usage (Primarily on guest login
  redirection) when a custom path was not in use.
- Added test to cover.

For #3404
2022-05-04 20:08:22 +01:00

45 lines
1.1 KiB
PHP

<?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 directly use the custom APP_URL, if set.
*
* @return string
*/
public function getSchemeAndHttpHost()
{
$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)), '/');
return empty($parsedBaseUrl) ? '' : ('/' . $parsedBaseUrl);
}
return parent::getBaseUrl();
}
}