Method: JSONRPC2::HTTPUtils.which

Defined in:
lib/jsonrpc2/accept.rb

.which(http_client_accepts, options) ⇒ Object

Selects the clients preferred media/mime type based on Accept header

Parameters:

  • http_client_accepts (String)

    HTTP Accepts header

  • options (Array<String>)

    Media types available



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/jsonrpc2/accept.rb', line 54

def which http_client_accepts, options
  return nil unless http_client_accepts

  parse_accept(http_client_accepts, true).each do |preference, types|
    types.each do |type|
      options.each do |option|
        return option if type.match(option)
      end
    end
  end

  nil
end