Sha256: a7ed2f55ff68a05c6787dfdb0b7fd4d7536d5705a9b8abbdea4ed24b53c6a193

Contents?: true

Size: 788 Bytes

Versions: 13

Compression:

Stored size: 788 Bytes

Contents

require 'rack/mime'
require 'rack/respond_to'

module Goliath
  module Rack
    # Does some basic cleanup / handling of the HTTP_ACCEPT header.
    # This will remove gzip, deflate, compressed and identity. If
    # there are no values left the header will be set to \*/\*.
    #
    # @example
    #   use Goliath::Rack::DefaultMimeType
    #
    class DefaultMimeType
      def initialize(app)
        @app = app
      end

      def call(env)
        accept = env['HTTP_ACCEPT'] || ''
        accept = accept.split(/\s*,\s*/)
        accept.delete_if { |a| a =~ /gzip|deflate|compressed|identity/ }
        accept = accept.join(", ")

        env['HTTP_ACCEPT'] = accept
        env['HTTP_ACCEPT'] = '*/*' if env['HTTP_ACCEPT'] == ''
        @app.call(env)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
goliath-1.0.7 lib/goliath/rack/default_mime_type.rb
goliath-1.0.6 lib/goliath/rack/default_mime_type.rb
goliath-1.0.5 lib/goliath/rack/default_mime_type.rb
goliath-1.0.4 lib/goliath/rack/default_mime_type.rb
goliath-1.0.3 lib/goliath/rack/default_mime_type.rb
goliath-1.0.2 lib/goliath/rack/default_mime_type.rb
goliath-1.0.1 lib/goliath/rack/default_mime_type.rb
goliath-1.0.0 lib/goliath/rack/default_mime_type.rb
goliath-1.0.0.beta.1 lib/goliath/rack/default_mime_type.rb
goliath-0.9.4 lib/goliath/rack/default_mime_type.rb
goliath-0.9.2 lib/goliath/rack/default_mime_type.rb
goliath-0.9.1 lib/goliath/rack/default_mime_type.rb
goliath-0.9.0 lib/goliath/rack/default_mime_type.rb