Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • project/stage_file_proxy
  • issue/stage_file_proxy-3161884
  • issue/stage_file_proxy-3199201
  • issue/stage_file_proxy-3200149
  • issue/stage_file_proxy-3283529
  • issue/stage_file_proxy-3283162
  • issue/stage_file_proxy-3282524
  • issue/stage_file_proxy-3282542
  • issue/stage_file_proxy-3250417
  • issue/stage_file_proxy-3244308
  • issue/stage_file_proxy-3075369
  • issue/stage_file_proxy-3275211
  • issue/stage_file_proxy-3289828
  • issue/stage_file_proxy-3314255
  • issue/stage_file_proxy-3314928
  • issue/stage_file_proxy-3325366
  • issue/stage_file_proxy-3136443
  • issue/stage_file_proxy-2514772
  • issue/stage_file_proxy-2926771
  • issue/stage_file_proxy-3321092
  • issue/stage_file_proxy-3321432
  • issue/stage_file_proxy-3321367
  • issue/stage_file_proxy-2961901
  • issue/stage_file_proxy-3323977
  • issue/stage_file_proxy-3323978
  • issue/stage_file_proxy-3325262
  • issue/stage_file_proxy-3216628
  • issue/stage_file_proxy-3293275
  • issue/stage_file_proxy-2611830
  • issue/stage_file_proxy-3326961
  • issue/stage_file_proxy-3332930
  • issue/stage_file_proxy-3334347
  • issue/stage_file_proxy-3336884
  • issue/stage_file_proxy-3346804
  • issue/stage_file_proxy-3365703
  • issue/stage_file_proxy-3366260
  • issue/stage_file_proxy-3367711
  • issue/stage_file_proxy-3402972
  • issue/stage_file_proxy-3405414
  • issue/stage_file_proxy-2928564
  • issue/stage_file_proxy-3349119
  • issue/stage_file_proxy-3371597
  • issue/stage_file_proxy-3371693
  • issue/stage_file_proxy-3371694
  • issue/stage_file_proxy-3372105
  • issue/stage_file_proxy-3372764
  • issue/stage_file_proxy-3375749
  • issue/stage_file_proxy-3378374
  • issue/stage_file_proxy-3380017
  • issue/stage_file_proxy-3380483
  • issue/stage_file_proxy-3175045
  • issue/stage_file_proxy-3390264
  • issue/stage_file_proxy-3396633
  • issue/stage_file_proxy-3385745
  • issue/stage_file_proxy-3396634
  • issue/stage_file_proxy-3409100
  • issue/stage_file_proxy-3417922
  • issue/stage_file_proxy-3422123
  • issue/stage_file_proxy-3421948
  • issue/stage_file_proxy-3438649
  • issue/stage_file_proxy-3439840
  • issue/stage_file_proxy-3434751
  • issue/stage_file_proxy-3426029
  • issue/stage_file_proxy-3450243
  • issue/stage_file_proxy-3171559
  • issue/stage_file_proxy-3457368
  • issue/stage_file_proxy-3457510
  • issue/stage_file_proxy-3232791
  • issue/stage_file_proxy-3461472
  • issue/stage_file_proxy-3463085
  • issue/stage_file_proxy-3465906
  • issue/stage_file_proxy-3173364
  • issue/stage_file_proxy-3130512
  • issue/stage_file_proxy-3499660
  • issue/stage_file_proxy-3504017
  • issue/stage_file_proxy-3508533
  • issue/stage_file_proxy-3513009
  • issue/stage_file_proxy-3515835
78 results
Show changes
Commits on Source (4)
......@@ -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);
}
/**
......
......@@ -4,6 +4,7 @@ namespace Drupal\stage_file_proxy\EventSubscriber;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\PageCache\ResponsePolicy\KillSwitch;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\Core\StreamWrapper\StreamWrapperManager;
use Drupal\Core\Url;
......@@ -36,6 +37,8 @@ class StageFileProxySubscriber implements EventSubscriberInterface {
* The config factory.
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* The request stack.
* @param \Drupal\Core\PageCache\ResponsePolicy\KillSwitch $pageCacheKillSwitch
* The page cache kill switch.
*/
public function __construct(
protected DownloadManagerInterface $manager,
......@@ -43,6 +46,7 @@ class StageFileProxySubscriber implements EventSubscriberInterface {
protected EventDispatcherInterface $eventDispatcher,
protected ConfigFactoryInterface $configFactory,
protected RequestStack $requestStack,
protected KillSwitch $pageCacheKillSwitch,
) {
}
......@@ -162,6 +166,7 @@ class StageFileProxySubscriber implements EventSubscriberInterface {
];
if ($config->get('hotlink')) {
$relative_path = UrlHelper::encodePath($relative_path);
$location = Url::fromUri("$server/$remote_file_dir/$relative_path", [
'query' => $query_parameters,
'absolute' => TRUE,
......@@ -176,6 +181,10 @@ class StageFileProxySubscriber implements EventSubscriberInterface {
'query' => $query_parameters,
'absolute' => TRUE,
])->toString();
// Ensure the redirect isn't cached by page_cache module.
$this->pageCacheKillSwitch->trigger();
// Use default cache control: must-revalidate, no-cache, private.
$event->setResponse(new RedirectResponse($location));
}
......
......@@ -8,12 +8,14 @@ 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: ~
Drupal\stage_file_proxy\EventSubscriber\StageFileProxySubscriber:
arguments:
$logger: '@logger.channel.stage_file_proxy'
$pageCacheKillSwitch: '@page_cache_kill_switch'
logger.channel.stage_file_proxy:
parent: logger.channel_base
......
......@@ -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);
}
/**
......