Sha256: d41ee4bdba7e9b41412e60ca11d2804ff5c8b3c220c1000db2224db284fe78df

Contents?: true

Size: 716 Bytes

Versions: 1

Compression:

Stored size: 716 Bytes

Contents

module Reel
  class RequestInfo
    attr_reader :http_method, :url, :http_version, :headers

    def initialize(http_method, url, http_version, headers)
      @http_method  = http_method
      @url          = url
      @http_version = http_version
      @headers      = headers
    end

    UPGRADE   = 'Upgrade'.freeze
    WEBSOCKET = 'websocket'.freeze

    # Array#include? seems slow compared to Hash lookup
    request_methods = Http::METHODS.map { |m| m.to_s.upcase }
    REQUEST_METHODS = Hash[request_methods.zip(request_methods)].freeze

    def method
      REQUEST_METHODS[http_method]
    end

    def websocket_request?
      headers[UPGRADE] && headers[UPGRADE].downcase == WEBSOCKET
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reel-0.4.0.pre2 lib/reel/request_info.rb