Skip to content
Snippets Groups Projects
Commit 1539c8cb authored by Stephen Mustgrave's avatar Stephen Mustgrave
Browse files

Issue #3365703 by malcomio, julien tekrane, smustgrave, a.dmitriiev, nterbogt:...

Issue #3365703 by malcomio, julien tekrane, smustgrave, a.dmitriiev, nterbogt: Images not proxied when file_public_path does not match web root
parent 3b1cae72
No related branches found
No related tags found
1 merge request!59Draft: Reroll
Pipeline #356500 passed with warnings
......@@ -15,6 +15,7 @@ use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Download manager.
......@@ -32,6 +33,7 @@ final class DownloadManager implements DownloadManagerInterface {
protected LoggerInterface $logger,
protected ConfigFactoryInterface $configFactory,
protected LockBackendInterface $lock,
protected RequestStack $requestStack,
) {
}
......@@ -138,7 +140,9 @@ final class DownloadManager implements DownloadManagerInterface {
* {@inheritdoc}
*/
public function filePublicPath(): string {
return PublicStream::basePath();
$filesDir = PublicStream::baseUrl();
$host = $this->requestStack->getCurrentRequest()->getSchemeAndHttpHost();
return str_replace($host . '/', '', $filesDir);
}
/**
......
......@@ -8,6 +8,7 @@ services:
arguments:
$logger: '@logger.channel.stage_file_proxy'
$lock: '@lock'
$requestStack: '@request_stack'
Drupal\stage_file_proxy\DownloadManagerInterface: '@stage_file_proxy.download_manager'
Drupal\stage_file_proxy\EventSubscriber\ImageDownloadControllerSubscriber: ~
......
......@@ -7,6 +7,7 @@ use Drupal\KernelTests\KernelTestBase;
use Drupal\stage_file_proxy\DownloadManager;
use GuzzleHttp\Client;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Test stage file proxy module.
......@@ -59,6 +60,13 @@ class DownloadManagerTest extends KernelTestBase {
*/
protected DownloadManager $downloadManager;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected RequestStack $requestStack;
/**
* Before a test method is run, setUp() is invoked.
*
......@@ -72,7 +80,8 @@ class DownloadManagerTest extends KernelTestBase {
$this->client = new Client();
$this->logger = \Drupal::logger('test_logger');
$this->configFactory = $this->container->get('config.factory');
$this->downloadManager = new DownloadManager($this->client, $this->fileSystem, $this->logger, $this->configFactory, \Drupal::lock());
$this->requestStack = new RequestStack();
$this->downloadManager = new DownloadManager($this->client, $this->fileSystem, $this->logger, $this->configFactory, \Drupal::lock(), $this->requestStack);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment