protected function sendItems(Response $response, iterable $items, ?Pagination $pagination = null, ?int $total = null): Response
    {
        $items = is_array($items) ? $items : ($items instanceof \Traversable ? iterator_to_array($items, false) : []);
        $total = $total ?? count($items);
        $start = $pagination === null ? 0 : $pagination->getOffset();
        $max = $pagination === null ? 0 : $pagination->getMax();
        // make sure $end is no higher than $total and isn't negative
        $end = max(min((PHP_INT_MAX - $max < $start ? PHP_INT_MAX : $start + $max), $total) - 1, 0);
        return $this->sendJson(
            $response->withHeader('Content-Range', "items $start-$end/$total"),
            $items
        );
    }