Sha256: d01725c49dafa569f8679cb54d7abf3f3c579d4d88465bcc2e403a70f901c13a

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

class HttpClientOptions
  attr_reader :uri, :method, :host, :port
  attr_reader :headers, :file, :body, :query, :path
  attr_reader :keepalive, :pass_cookies, :decoding

  attr_accessor :followed, :redirects

  def initialize(uri, options, method)
    @keepalive = options[:keepalive] || false  # default to single request per connection
    @redirects = options[:redirects] ||= 0     # default number of redirects to follow
    @followed  = options[:followed]  ||= 0     # keep track of number of followed requests

    @method   = method.to_s.upcase
    @headers  = options[:head]  || {}
    @query    = options[:query]
    @path     = options[:path]

    @file     = options[:file]
    @body     = options[:body]

    @pass_cookies = options.fetch(:pass_cookies, true)  # pass cookies between redirects
    @decoding     = options.fetch(:decoding, true)      # auto-decode compressed response

    set_uri(uri)
  end

  def follow_redirect?; @followed < @redirects; end
  def ssl?; @uri.scheme == "https" || @uri.port == 443; end
  def no_body?; @method == "HEAD"; end

  def set_uri(uri)
    uri = uri.kind_of?(Addressable::URI) ? uri : Addressable::URI::parse(uri.to_s)
    uri.path = '/' if uri.path.empty?
    uri.path = @path if @path

    @uri = uri

    # Make sure the ports are set as Addressable::URI doesn't
    # set the port if it isn't there
    if @uri.scheme == "https"
      @uri.port ||= 443
    else
      @uri.port ||= 80
    end

    @host = @uri.host
    @port = @uri.port

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
em-http-request-1.0.3 lib/em-http/http_client_options.rb