Sha256: d6e8a3cdecb44eb042dbd656f3a514cb63cac993c7768f3ea90ab4f6673ce032

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

module Reel
  module HTTPVersionsMixin

    HTTP_VERSION_1_0     = '1.0'.freeze
    HTTP_VERSION_1_1     = '1.1'.freeze
    DEFAULT_HTTP_VERSION = HTTP_VERSION_1_1
  end

  module ConnectionMixin

    # Obtain the IP address of the remote connection
    def remote_ip
      socket.peeraddr(false)[3]
    end
    alias remote_addr remote_ip

    # Obtain the hostname of the remote connection
    def remote_host
      # NOTE: Celluloid::IO does not yet support non-blocking reverse DNS
      socket.peeraddr(true)[2]
    end
  end

  module RequestMixin

    def method
      @request_info.http_method
    end

    def headers
      @request_info.headers
    end

    def [] header
      headers[header]
    end

    def version
      @request_info.http_version || HTTPVersionsMixin::DEFAULT_HTTP_VERSION
    end

    def url
      @request_info.url
    end

    def uri
      @uri ||= URI(url)
    end

    def path
      uri.path
    end

    def query_string
      uri.query
    end

    def fragment
      uri.fragment
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
reel-0.4.0 lib/reel/mixins.rb
reel-0.4.0.pre7 lib/reel/mixins.rb
reel-0.4.0.pre6 lib/reel/mixins.rb
reel-0.4.0.pre5 lib/reel/mixins.rb
reel-0.4.0.pre4 lib/reel/mixins.rb
reel-0.4.0.pre3 lib/reel/mixins.rb
reel-0.4.0.pre2 lib/reel/mixins.rb