Add `X-Records` header to paged requests

This adds code to calculate the total number of results that
would have been returned by a paged query, and includes that
value in an HTTP header in the response.

Also, this code is horrible and needs major refactoring.