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

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

Defined Under Namespace

Classes: InternalErrorResponse, Response

Constant Summary collapse

DEFAULT_TIMEOUT =
30

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.



21
22
23
24
25
26
27
# File 'lib/datadog/ci/transport/http.rb', line 21

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.



12
13
14
# File 'lib/datadog/ci/transport/http.rb', line 12

def compress
  @compress
end

#hostObject (readonly)

Returns the value of attribute host.



12
13
14
# File 'lib/datadog/ci/transport/http.rb', line 12

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



12
13
14
# File 'lib/datadog/ci/transport/http.rb', line 12

def port
  @port
end

#sslObject (readonly)

Returns the value of attribute ssl.



12
13
14
# File 'lib/datadog/ci/transport/http.rb', line 12

def ssl
  @ssl
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



12
13
14
# File 'lib/datadog/ci/transport/http.rb', line 12

def timeout
  @timeout
end

Instance Method Details

#request(path:, payload:, headers:, method: "post") ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/datadog/ci/transport/http.rb', line 29

def request(path:, payload:, headers:, method: "post")
  raise "Unknown method #{method}" unless respond_to?(method, true)

  if compress
    headers[Ext::Transport::HEADER_CONTENT_ENCODING] = Ext::Transport::CONTENT_ENCODING_GZIP
    payload = Gzip.compress(payload)
  end

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

  send(method, path: path, payload: payload, headers: headers)
end