Class: TingYun::Http::ExconHTTPRequest

Inherits:
AbstractRequest show all
Defined in:
lib/ting_yun/http/excon_wrappers.rb

Constant Summary collapse

EXCON =
"Excon".freeze
LHOST =
'host'.freeze
UHOST =
'Host'.freeze
COLON =
':'.freeze

Constants inherited from AbstractRequest

AbstractRequest::ERROR_MESSAGE

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datum) ⇒ ExconHTTPRequest

Returns a new instance of ExconHTTPRequest.



38
39
40
41
42
43
44
45
# File 'lib/ting_yun/http/excon_wrappers.rb', line 38

def initialize(datum)
  @datum = datum

  @method = @datum[:method].to_s.upcase
  @scheme = @datum[:scheme]
  @port   = @datum[:port]
  @path   = @datum[:path]
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



31
32
33
# File 'lib/ting_yun/http/excon_wrappers.rb', line 31

def method
  @method
end

Instance Method Details

#[](key) ⇒ Object



66
67
68
# File 'lib/ting_yun/http/excon_wrappers.rb', line 66

def [](key)
  @datum[:headers][key]
end

#[]=(key, value) ⇒ Object



70
71
72
73
# File 'lib/ting_yun/http/excon_wrappers.rb', line 70

def []=(key, value)
  @datum[:headers] ||= {}
  @datum[:headers][key] = value
end

#fromObject



51
52
53
# File 'lib/ting_yun/http/excon_wrappers.rb', line 51

def from
  "excon%2Fhttp"
end

#hostObject



62
63
64
# File 'lib/ting_yun/http/excon_wrappers.rb', line 62

def host
  host_from_header || @datum[:host]
end

#host_from_headerObject



55
56
57
58
59
60
# File 'lib/ting_yun/http/excon_wrappers.rb', line 55

def host_from_header
  headers = @datum[:headers]
  if hostname = (headers[LHOST] || headers[UHOST])
    hostname.split(COLON).first
  end
end

#typeObject



47
48
49
# File 'lib/ting_yun/http/excon_wrappers.rb', line 47

def type
  EXCON
end

#uriObject



75
76
77
# File 'lib/ting_yun/http/excon_wrappers.rb', line 75

def uri
  URI.parse("#{@scheme}://#{host}:#{@port}#{@path}")
end