Sha256: 10b331f678584d9b3391d9e0b24580a39a464a5b0e9ed108f4af9a5a983ffca6

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

module Pacto
  class 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'] || []
        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

2 entries across 2 versions & 1 rubygems

Version Path
pacto-0.3.1 lib/pacto/generator/filters.rb
pacto-0.3.0 lib/pacto/generator/filters.rb