class Rack::VendorAcceptHeader
Constants
- VERSION
Public Class Methods
new(app, options = {})
click to toggle source
# File lib/rack/vendor_accept_header.rb, line 6 def initialize(app, options = {}) @app = app @options = options end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/vendor_accept_header.rb, line 11 def call(env) parts = parse_accept_header(env) env['vnd_version'] = parts[:version] env['vnd_context'] = parts[:context] env['vnd_type'] = parts[:type] env['vnd_sub_type'] = parts[:sub_type] @app.call(env) end
Private Instance Methods
parse_accept_header(env)
click to toggle source
# File lib/rack/vendor_accept_header.rb, line 22 def parse_accept_header(env) if env['HTTP_ACCEPT'] =~ /application\/vnd\.(\w+)\.v(\d+(?:\.\d+)*)\+(\w+)/ return { type: 'application', context: $1, version: $2, sub_type: $3 } else return { type: nil, context: nil, version: nil, sub_type: nil } end end