Class: TingYun::Http::TyphoeusHTTPRequest

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

Constant Summary collapse

TYPHOEUS =
"Typhoeus".freeze
LHOST =
'host'.freeze
UHOST =
'Host'.freeze
GET =
'GET'.freeze

Constants inherited from AbstractRequest

AbstractRequest::ERROR_MESSAGE

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ TyphoeusHTTPRequest

Returns a new instance of TyphoeusHTTPRequest.



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

def initialize(request)
  @request = request
  @uri = case request.url
    when ::URI then request.url
    else TingYun::Agent::HTTPClients::URIUtil.parse_and_normalize_url(request.url)
    end
end

Instance Method Details

#[](key) ⇒ Object



72
73
74
75
# File 'lib/ting_yun/http/typhoeus_wrappers.rb', line 72

def [](key)
  return nil unless @request.options && @request.options[:headers]
  @request.options[:headers][key]
end

#[]=(key, value) ⇒ Object



77
78
79
80
# File 'lib/ting_yun/http/typhoeus_wrappers.rb', line 77

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

#fromObject



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

def from
  "typhoeus%2Fhttp"
end

#hostObject



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

def host
  host_from_header || @uri.host
end

#host_from_headerObject



58
59
60
# File 'lib/ting_yun/http/typhoeus_wrappers.rb', line 58

def host_from_header
  self[LHOST] || self[UHOST]
end

#methodObject



68
69
70
# File 'lib/ting_yun/http/typhoeus_wrappers.rb', line 68

def method
  (@request.options[:method] || GET).to_s.upcase
end

#typeObject



48
49
50
# File 'lib/ting_yun/http/typhoeus_wrappers.rb', line 48

def type
  TYPHOEUS
end

#uriObject



82
83
84
# File 'lib/ting_yun/http/typhoeus_wrappers.rb', line 82

def uri
  @uri
end