Class: Datadog::CI::Transport::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/transport/http.rb

Defined Under Namespace

Classes: AdapterSettings, ResponseDecorator

Constant Summary collapse

DEFAULT_TIMEOUT =
30
MAX_RETRIES =
3
INITIAL_BACKOFF =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, timeout: DEFAULT_TIMEOUT, port: nil, ssl: true, compress: false) ⇒ HTTP

Returns a new instance of HTTP.



27
28
29
30
31
32
33
# File 'lib/datadog/ci/transport/http.rb', line 27

def initialize(host:, timeout: DEFAULT_TIMEOUT, port: nil, ssl: true, compress: false)
  @host = host
  @port = port
  @timeout = timeout
  @ssl = ssl.nil? ? true : ssl
  @compress = compress.nil? ? false : compress
end

Instance Attribute Details

#compressObject (readonly)

Returns the value of attribute compress.



16
17
18
# File 'lib/datadog/ci/transport/http.rb', line 16

def compress
  @compress
end

#hostObject (readonly)

Returns the value of attribute host.



16
17
18
# File 'lib/datadog/ci/transport/http.rb', line 16

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



16
17
18
# File 'lib/datadog/ci/transport/http.rb', line 16

def port
  @port
end

#sslObject (readonly)

Returns the value of attribute ssl.



16
17
18
# File 'lib/datadog/ci/transport/http.rb', line 16

def ssl
  @ssl
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



16
17
18
# File 'lib/datadog/ci/transport/http.rb', line 16

def timeout
  @timeout
end

Instance Method Details

#request(path:, payload:, headers:, verb: "post", retries: MAX_RETRIES, backoff: INITIAL_BACKOFF) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/datadog/ci/transport/http.rb', line 35

def request(path:, payload:, headers:, verb: "post", retries: MAX_RETRIES, backoff: INITIAL_BACKOFF)
  if compress
    headers[Ext::Transport::HEADER_CONTENT_ENCODING] = Ext::Transport::CONTENT_ENCODING_GZIP
    payload = Gzip.compress(payload)
  end

  Datadog.logger.debug do
    "Sending #{verb} request: host=#{host}; port=#{port}; ssl_enabled=#{ssl}; " \
      "compression_enabled=#{compress}; path=#{path}; payload_size=#{payload.size}"
  end

  response = ResponseDecorator.new(
    perform_http_call(path: path, payload: payload, headers: headers, verb: verb, retries: retries, backoff: backoff)
  )

  Datadog.logger.debug do
    "Received server response: #{response.inspect}"
  end

  response
end