Added a flush() call in the resource handler to make sure unwritten content is flushed (not a bugfix but a precaution for an experiment I've done).