api/util/json{,_test}: fix HEAD request writing body, improve test coverage