Skip to content

Commit

Permalink
REFACTOR: Use more generic approach for ignoring specific user agents
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclegg committed May 2, 2020
1 parent 8e4f457 commit e2a23ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
15 changes: 15 additions & 0 deletions docs/en/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,18 @@
```
composer require axllent/silverstripe-trailing-slash
```


## Caveats

When using the silverstripe/silverstripe-staticpublishqueue module the REQUEST_URI is updated so what's used for the request will be different from what is defined in $_SERVER['REQUEST_URI']. As the REQUEST_URI can no longer be used to determine if a trailing slash is required then it makes more sense to ignore the user agent for staticpublishqueue.

The User agent can be ignored by this module by setting;

```yaml
Axllent\TrailingSlash\Middleware\TrailingSlashRedirector:
ignore_agents:
- 'silverstripe/staticpublishqueue'
```
ref; https://github.com/silverstripe/silverstripe-staticpublishqueue/blob/master/src/Publisher.php#L82-L101
12 changes: 11 additions & 1 deletion src/Middleware/TrailingSlashRedirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class TrailingSlashRedirector implements HTTPMiddleware
'dev/',
];

/**
* User-Agents to ignore
*
* @var array
*/
private static $ignore_agents = [];

/**
* Process request
*
Expand Down Expand Up @@ -68,7 +75,10 @@ public function process(HTTPRequest $request, callable $delegate)
$params = $request->getVars();

if (!Director::is_ajax()
&& $request->getHeader('User-Agent') != 'silverstripe/staticpublishqueue'
&& !in_array(
$request->getHeader('User-Agent'),
Config::inst()->get(TrailingSlashRedirector::class, 'ignore_agents')
)
&& !isset($urlPathInfo['extension'])
&& empty($params)
&& !preg_match(
Expand Down

0 comments on commit e2a23ca

Please sign in to comment.