module Pagy::Backend

def pagy_headers_hash(pagy)

def pagy_headers_hash(pagy)
  countless = defined?(Pagy::Countless) && pagy.is_a?(Pagy::Countless)
  rels      = { 'first' => 1, 'prev' => pagy.prev, 'next' => pagy.next }; rels['last'] = pagy.last unless countless
  url_str   = pagy_url_for(PAGE_PLACEHOLDER, pagy, :url)
  hash      = { 'Link' => Hash[rels.map{|rel, n|[rel, url_str.sub(PAGE_PLACEHOLDER, n.to_s)] if n}.compact] }
  headers   = pagy.vars[:headers]
  hash[headers[:page]]  = pagy.page.to_s         if headers[:page]
  hash[headers[:items]] = pagy.vars[:items].to_s if headers[:items]
  unless countless
    hash[headers[:pages]] = pagy.pages.to_s if headers[:pages]
    hash[headers[:count]] = pagy.count.to_s if headers[:count]
  end
  hash
end