Fix "headers are already sent" introduced with #6519

Backport of #7347
Merge pull request #7349 from owncloud/backport-7347

Backport of #7347 to stable6