Class: Datadog::CI::Transport::Adapters::Net::Response

Inherits:
Object
  • Object
show all
Includes:
Datadog::Core::Transport::Response
Defined in:
lib/datadog/ci/transport/adapters/net.rb

Direct Known Subclasses

HTTP::ErrorResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.



71
72
73
# File 'lib/datadog/ci/transport/adapters/net.rb', line 71

def initialize(http_response)
  @http_response = http_response
end

Instance Attribute Details

#duration_msObject

Stats for telemetry



69
70
71
# File 'lib/datadog/ci/transport/adapters/net.rb', line 69

def duration_ms
  @duration_ms
end

#http_responseObject (readonly)

Returns the value of attribute http_response.



67
68
69
# File 'lib/datadog/ci/transport/adapters/net.rb', line 67

def http_response
  @http_response
end

#request_compressedObject

Stats for telemetry



69
70
71
# File 'lib/datadog/ci/transport/adapters/net.rb', line 69

def request_compressed
  @request_compressed
end

#request_sizeObject

Stats for telemetry



69
70
71
# File 'lib/datadog/ci/transport/adapters/net.rb', line 69

def request_size
  @request_size
end

Instance Method Details

#client_error?Boolean

Returns:

  • (Boolean)


111
112
113
114
115
116
# File 'lib/datadog/ci/transport/adapters/net.rb', line 111

def client_error?
  http_code = code
  return false if http_code.nil?

  http_code.between?(400, 499)
end

#codeObject



92
93
94
# File 'lib/datadog/ci/transport/adapters/net.rb', line 92

def code
  http_response.code.to_i
end

#errorObject



139
140
141
# File 'lib/datadog/ci/transport/adapters/net.rb', line 139

def error
  nil
end

#gzipped_body?(body) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
132
133
134
135
136
137
# File 'lib/datadog/ci/transport/adapters/net.rb', line 129

def gzipped_body?(body)
  return false if body.nil? || body.empty?

  # no-dd-sa
  first_bytes = body[0, 2]
  return false if first_bytes.nil? || first_bytes.empty?

  first_bytes.b == Ext::Transport::GZIP_MAGIC_NUMBER
end

#gzipped_content?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/datadog/ci/transport/adapters/net.rb', line 125

def gzipped_content?
  header(Ext::Transport::HEADER_CONTENT_ENCODING) == Ext::Transport::CONTENT_ENCODING_GZIP
end

#header(name) ⇒ Object



88
89
90
# File 'lib/datadog/ci/transport/adapters/net.rb', line 88

def header(name)
  http_response[name]
end

#inspectObject



161
162
163
# File 'lib/datadog/ci/transport/adapters/net.rb', line 161

def inspect
  "#{super}, http_response:#{http_response}"
end

#not_found?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/datadog/ci/transport/adapters/net.rb', line 107

def not_found?
  code == 404
end

#ok?Boolean

Returns:

  • (Boolean)


96
97
98
99
100
101
# File 'lib/datadog/ci/transport/adapters/net.rb', line 96

def ok?
  http_code = code
  return false if http_code.nil?

  http_code.between?(200, 299)
end

#payloadObject



75
76
77
78
79
80
81
82
# File 'lib/datadog/ci/transport/adapters/net.rb', line 75

def payload
  return @decompressed_payload if defined?(@decompressed_payload)
  return http_response.body unless gzipped_content?
  return http_response.body unless gzipped_body?(http_response.body)

  Datadog.logger.debug("Decompressing gzipped response payload")
  @decompressed_payload = Gzip.decompress(http_response.body)
end

#response_sizeObject



84
85
86
# File 'lib/datadog/ci/transport/adapters/net.rb', line 84

def response_size
  http_response.body.bytesize
end

#server_error?Boolean

Returns:

  • (Boolean)


118
119
120
121
122
123
# File 'lib/datadog/ci/transport/adapters/net.rb', line 118

def server_error?
  http_code = code
  return false if http_code.nil?

  http_code.between?(500, 599)
end

#telemetry_error_typeObject



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/datadog/ci/transport/adapters/net.rb', line 143

def telemetry_error_type
  return nil if ok?

  case error
  when nil
    Ext::Telemetry::ErrorType::STATUS_CODE
  when Timeout::Error
    Ext::Telemetry::ErrorType::TIMEOUT
  else
    Ext::Telemetry::ErrorType::NETWORK
  end
end

#trace_countObject

compatibility with Datadog::Tracing transport layer



157
158
159
# File 'lib/datadog/ci/transport/adapters/net.rb', line 157

def trace_count
  0
end

#unsupported?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/datadog/ci/transport/adapters/net.rb', line 103

def unsupported?
  code == 415
end