diff --git a/lib/ext/Syncroton/Server.php b/lib/ext/Syncroton/Server.php --- a/lib/ext/Syncroton/Server.php +++ b/lib/ext/Syncroton/Server.php @@ -147,6 +147,13 @@ if (!$response) { $response = $command->getResponse(); } + + if ($response === null) { + // FIXME: Don't send any content-type, but will it not be added by the http server? + ini_set('default_mimetype', ''); + // FIXME: Is this really needed? It is for PHP cli-server, but not really for a real http server + header('Content-Length: 0'); + } } catch (Syncroton_Exception_ProvisioningNeeded $sepn) { if ($this->_logger instanceof Zend_Log) $this->_logger->info(__METHOD__ . '::' . __LINE__ . " provisioning needed"); diff --git a/tests/Sync/Sync/EmailTest.php b/tests/Sync/Sync/EmailTest.php --- a/tests/Sync/Sync/EmailTest.php +++ b/tests/Sync/Sync/EmailTest.php @@ -112,29 +112,7 @@ $this->assertSame('test sync', $xpath->query("{$root}/ns:ApplicationData/Email:Subject")->item(0)->nodeValue); // List the rest of the mail - $request = << - - - - - {$syncKey} - {$folderId} - 1 - 1 - - 0 - 1 - - 2 - 51200 - 0 - - - - - - EOF; + $request = preg_replace('|\d|', "{$syncKey}", $request); $response = $this->request($request, 'Sync'); @@ -154,6 +132,24 @@ $this->assertStringMatchesFormat("{$folderId}::%d", $xpath->query("{$root}/ns:ServerId")->item(0)->nodeValue); $this->assertSame('sync test with attachment', $xpath->query("{$root}/ns:ApplicationData/Email:Subject")->item(0)->nodeValue); + // Test the empty Sync response + $request = preg_replace('|\d|', "{$syncKey}", $request); + + $response = $this->request($request, 'Sync'); + + print_r($response->getHeaders()); + + // According to https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-ascmd/b4b366a5-7dfb-45a9-a256-af8fa7c53400 + // the empty response should look like this + // + // HTTP/1.1 200 OK + // Date: Fri, 10 Apr 2009 20:32:39 GMT + // Content-Length: 0 + + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('', (string) $response->getBody()); + $this->assertSame(['0'], $response->getHeader('Content-Length')); + return $syncKey; } diff --git a/tests/SyncTestCase.php b/tests/SyncTestCase.php --- a/tests/SyncTestCase.php +++ b/tests/SyncTestCase.php @@ -360,16 +360,15 @@ return $xpath; } - /** * adapter for phpunit < 9 */ - protected function assertMatchesRegularExpression($arg1, $arg2) + public static function assertMatchesRegularExpression(string $arg1, string $arg2, string $message = ''): void { if (method_exists("PHPUnit\Framework\TestCase", "assertMatchesRegularExpression")) { - parent::assertMatchesRegularExpression($arg1, $arg2); + parent::assertMatchesRegularExpression($arg1, $arg2, $message); } else { - parent::assertRegExp($arg1, $arg2); + parent::assertRegExp($arg1, $arg2, $message); } } }