*/
public function handleAnonymousOptions(RequestInterface $request, ResponseInterface $response) {
$isOffice = preg_match('/Microsoft Office/i', $request->getHeader('User-Agent'));
- $isAnonymousOption = ($request->getMethod() === 'OPTIONS' && ($request->getHeader('Authorization') === null || trim($request->getHeader('Authorization')) === 'Bearer') && $this->isRequestInRoot($request->getPath()));
- $isOfficeHead = $request->getMethod() === 'HEAD' && $isOffice && $request->getHeader('Authorization') === 'Bearer';
+ $emptyAuth = $request->getHeader('Authorization') === null
+ || $request->getHeader('Authorization') === ''
+ || trim($request->getHeader('Authorization')) === 'Bearer';
+ $isAnonymousOption = $request->getMethod() === 'OPTIONS' && $emptyAuth;
+ $isOfficeHead = $request->getMethod() === 'HEAD' && $isOffice && $emptyAuth;
if ($isAnonymousOption || $isOfficeHead) {
/** @var CorePlugin $corePlugin */
$corePlugin = $this->server->getPlugin('core');
use Test\TestCase;
class AnonymousOptionsTest extends TestCase {
- private function sendRequest($method, $path) {
+ private function sendRequest($method, $path, $userAgent = '') {
$server = new Server();
$server->addPlugin(new AnonymousOptionsPlugin());
$server->addPlugin(new Plugin(new BasicCallBack(function() {
$server->httpRequest->setMethod($method);
$server->httpRequest->setUrl($path);
+ $server->httpRequest->setHeader('User-Agent', $userAgent);
$server->sapi = new SapiMock();
$server->exec();
public function testAnonymousOptionsNonRootSubDir() {
$response = $this->sendRequest('OPTIONS', 'foo/bar');
- $this->assertEquals(401, $response->getStatus());
+ $this->assertEquals(200, $response->getStatus());
+ }
+
+ public function testAnonymousHead() {
+ $response = $this->sendRequest('HEAD', '', 'Microsoft Office does strange things');
+
+ $this->assertEquals(200, $response->getStatus());
+ }
+
+ public function testAnonymousHeadNoOffice() {
+ $response = $this->sendRequest('HEAD', '');
+
+ $this->assertEquals(401, $response->getStatus(), 'curl');
}
}