Sha256: dfd285cebd0bff9a4209e53efb38d1c229a9c54aa5ae5da0bd3b66869ee4ed54

Contents?: true

Size: 688 Bytes

Versions: 1

Compression:

Stored size: 688 Bytes

Contents

module Raisin
  class Middleware
    ACCEPT_REGEXP = /application\/vnd\.(?<vendor>[a-z]+)-(?<version>v[0-9]+)\+(?<format>[a-z]+)?/

    def initialize(app)
      @app = app
      @vendor = Configuration.version.vendor
    end

    def call(env)
      @env = env
      if verify_accept_header
        @app.call(@env)
      else
        [406, {}, []]
      end
    end

    private

    def verify_accept_header
      if (matches = ACCEPT_REGEXP.match(@env['HTTP_ACCEPT'])) && @vendor == matches[:vendor]
        @env['raisin.version']  = matches[:version]
        @env['raisin.format']   = "application/#{matches[:format]}"
        true
      else
        false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
raisin-0.0.4 lib/raisin/middleware.rb