COUCHDB-627 forward-ported on top of MochiWeb 2.4.2