Class: Skylight::Util::HTTP Private

Inherits:
Object show all
Includes:
Logging
Defined in:
lib/skylight/util/http.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: ErrorResponse, ReadResponseError, Response, StartError

Constant Summary collapse

CONTENT_ENCODING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"content-encoding".freeze
CONTENT_LENGTH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"content-length".freeze
CONTENT_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"content-type".freeze
ACCEPT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"Accept".freeze
X_VERSION_HDR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"x-skylight-agent-version".freeze
APPLICATION_JSON =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"application/json".freeze
AUTHORIZATION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"authorization".freeze
DEFLATE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"deflate".freeze
GZIP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"gzip".freeze
READ_EXCEPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[Timeout::Error, EOFError, Net::ReadTimeout].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#config_for_logging, #debug, #error, #fmt, #info, #log, #log_context, #raise_on_error?, #t, #trace, #trace?, #warn

Constructor Details

#initialize(config, service = :auth, opts = {}) ⇒ HTTP

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HTTP.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/skylight/util/http.rb', line 41

def initialize(config, service = :auth, opts = {})
  @config = config

  unless (url = config["#{service}_url"])
    raise ArgumentError, "no URL specified for #{service}"
  end

  url = URI.parse(url)

  @ssl = url.scheme == "https"
  @host = url.host
  @port = url.port

  if (proxy_url = config[:proxy_url])
    proxy_url = URI.parse(proxy_url)
    @proxy_addr = proxy_url.host
    @proxy_port = proxy_url.port
    @proxy_user, @proxy_pass = (proxy_url.userinfo || "").split(/:/)
  end

  @open_timeout = get_timeout(:connect, config, service, opts)
  @read_timeout = get_timeout(:read, config, service, opts)

  @deflate = config["#{service}_http_deflate"]
  @authentication = config[:authentication]
end

Instance Attribute Details

#authenticationObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/skylight/util/http.rb', line 24

def authentication
  @authentication
end

#configObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
# File 'lib/skylight/util/http.rb', line 25

def config
  @config
end

#hostObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
# File 'lib/skylight/util/http.rb', line 25

def host
  @host
end

#portObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
# File 'lib/skylight/util/http.rb', line 25

def port
  @port
end

Instance Method Details

#get(endpoint, hdrs = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



68
69
70
71
# File 'lib/skylight/util/http.rb', line 68

def get(endpoint, hdrs = {})
  request = build_request(Net::HTTP::Get, endpoint, hdrs)
  execute(request)
end

#post(endpoint, body, hdrs = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



73
74
75
76
77
78
79
80
81
# File 'lib/skylight/util/http.rb', line 73

def post(endpoint, body, hdrs = {})
  unless body.respond_to?(:to_str)
    hdrs[CONTENT_TYPE] = APPLICATION_JSON
    body = body.to_json
  end

  request = build_request(Net::HTTP::Post, endpoint, hdrs, body.bytesize)
  execute(request, body)
end