Sha256: 10b2cbef2579b61f2f2d5856711c4b8b03790d430c3587d5ea296c95484dbfd1

Contents?: true

Size: 625 Bytes

Versions: 53

Compression:

Stored size: 625 Bytes

Contents

module Rack
  module PactBroker
    class AcceptsHtmlFilter

      def initialize app
        @app = app
      end

      def call env
        if accepts_html_and_not_json_or_csv env
          @app.call(env)
        else
          [404, {},[]]
        end
      end

      def accepts_html_and_not_json_or_csv env
        accept = env['HTTP_ACCEPT'] || ''
        accepts_html(accept) && !accepts_json_or_csv(accept)
      end

      def accepts_html(accept)
        accept.include?("html")
      end

      def accepts_json_or_csv accept
        accept.include?("json") || accept.include?("csv")
      end
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
pact_broker-2.29.0 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.27.6 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.27.5 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.27.4 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.27.3 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.27.2 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.27.0 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.26.1 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.26.0 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.25.0 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.24.0 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.23.4 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.23.3 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.23.2 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.23.1 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.23.0 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.22.0 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.21.0 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.20.0 lib/rack/pact_broker/accepts_html_filter.rb
pact_broker-2.19.2 lib/rack/pact_broker/accepts_html_filter.rb