Sha256: 3df152092eeaa4569b46b2caedd435c8be0fc5ce6b4d87678a01df5bce7a31b2

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# -*- encoding : utf-8 -*-
module Pacto
  module Generator
    class Filters
      CONNECTION_CONTROL_HEADERS = %w(
        Via
        Server
        Connection
        Transfer-Encoding
        Content-Length
      )

      FRESHNESS_HEADERS =
      %w(
        Date
        Last-Modified
        ETag
      )

      HEADERS_TO_FILTER = CONNECTION_CONTROL_HEADERS + FRESHNESS_HEADERS

      def filter_request_headers(request, response)
        # FIXME: Do we need to handle all these cases in real situations, or just because of stubbing?
        vary_headers = response.headers['vary'] || response.headers['Vary'] || []
        vary_headers = [vary_headers] if vary_headers.is_a? String
        vary_headers = vary_headers.map do |h|
          h.split(',').map(&:strip)
        end.flatten

        request.headers.select do |header|
          vary_headers.map(&:downcase).include? header.downcase
        end
      end

      def filter_response_headers(_request, response)
        Pacto::Extensions.normalize_header_keys(response.headers).reject do |header|
          (HEADERS_TO_FILTER.include? header) || (header.start_with?('X-'))
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pacto-0.4.0.rc1 lib/pacto/generator/filters.rb