Sha256: 2831eb9d445ccd95d31619891823b39cd1c7d3d40cac9481da96b4c8a14bc5e1

Contents?: true

Size: 715 Bytes

Versions: 8

Compression:

Stored size: 715 Bytes

Contents

# frozen_string_literal: true

module Rack
  module Accept
    module Header
      ALLOWED_CHARACTERS = %r{^([a-z*]+)\/([a-z0-9*\&\^\-_#\$!.+]+)(?:;([a-z0-9=;]+))?$}.freeze
      class << self
        # Corrected version of https://github.com/mjackson/rack-accept/blob/master/lib/rack/accept/header.rb#L40-L44
        def parse_media_type(media_type)
          # see http://tools.ietf.org/html/rfc6838#section-4.2 for allowed characters in media type names
          m = media_type&.match(ALLOWED_CHARACTERS)
          m ? [m[1], m[2], m[3] || ''] : []
        end
      end
    end

    class MediaType
      def parse_media_type(media_type)
        Header.parse_media_type(media_type)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
grape-1.5.3 lib/grape/middleware/versioner/parse_media_type_patch.rb
grape-1.5.2 lib/grape/middleware/versioner/parse_media_type_patch.rb
grape-1.5.1 lib/grape/middleware/versioner/parse_media_type_patch.rb
grape-1.5.0 lib/grape/middleware/versioner/parse_media_type_patch.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.4.0/lib/grape/middleware/versioner/parse_media_type_patch.rb
grape-1.4.0 lib/grape/middleware/versioner/parse_media_type_patch.rb
grape-1.3.3 lib/grape/middleware/versioner/parse_media_type_patch.rb
grape-1.3.2 lib/grape/middleware/versioner/parse_media_type_patch.rb