Sha256: d743a331e5f9aee2b418db7c3e6209f1b2a15fe1df6dc743b9f4d13df855f691

Contents?: true

Size: 1017 Bytes

Versions: 36

Compression:

Stored size: 1017 Bytes

Contents

# frozen_string_literal: true

module Salestation
  class Web < Module
    module InputValidators
      class ContentTypeHeader
        include Deterministic::Prelude

        def self.[](*allowed_headers)
          new(allowed_headers)
        end

        def initialize(allowed_headers)
          @allowed_headers = allowed_headers
        end

        def call(header_value)
          # Some headers can have additional information such as `multipart/form-data`
          parsed_header_value = header_value ? header_value.split(';').first : nil

          header_valid = @allowed_headers.empty? || @allowed_headers.include?(parsed_header_value)

          if header_valid
            Success(nil)
          else
            Failure(App::Errors::UnsupportedMediaType.new(
              message: "Unsupported Content-Type Header '#{header_value}'",
              debug_message: "Available Content-Type Headers are #{@allowed_headers.join(', ')}"
            ))
          end
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
salestation-5.3.3 lib/salestation/web/input_validators/content_type_header.rb
salestation-5.3.2 lib/salestation/web/input_validators/content_type_header.rb
salestation-5.3.1 lib/salestation/web/input_validators/content_type_header.rb
salestation-5.3.0 lib/salestation/web/input_validators/content_type_header.rb
salestation-5.2.0 lib/salestation/web/input_validators/content_type_header.rb
salestation-5.1.0 lib/salestation/web/input_validators/content_type_header.rb
salestation-5.0.2 lib/salestation/web/input_validators/content_type_header.rb
salestation-5.0.1 lib/salestation/web/input_validators/content_type_header.rb
salestation-5.0.0 lib/salestation/web/input_validators/content_type_header.rb
salestation-4.6.1 lib/salestation/web/input_validators/content_type_header.rb
salestation-4.6.0 lib/salestation/web/input_validators/content_type_header.rb
salestation-4.5.0 lib/salestation/web/input_validators/content_type_header.rb
salestation-4.4.2 lib/salestation/web/input_validators/content_type_header.rb
salestation-4.4.1 lib/salestation/web/input_validators/content_type_header.rb
salestation-4.4.0 lib/salestation/web/input_validators/content_type_header.rb
salestation-4.3.1 lib/salestation/web/input_validators/content_type_header.rb
salestation-4.3.0 lib/salestation/web/input_validators/content_type_header.rb
salestation-4.2.0 lib/salestation/web/input_validators/content_type_header.rb
salestation-4.1.0 lib/salestation/web/input_validators/content_type_header.rb
salestation-4.0.3 lib/salestation/web/input_validators/content_type_header.rb