Class: Datadog::CI::Transport::Adapters::Net::Response
- Inherits:
-
Object
- Object
- Datadog::CI::Transport::Adapters::Net::Response
- Includes:
- Datadog::Core::Transport::Response
- Defined in:
- lib/datadog/ci/transport/adapters/net.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#duration_ms ⇒ Object
Stats for telemetry.
-
#http_response ⇒ Object
readonly
Returns the value of attribute http_response.
-
#request_compressed ⇒ Object
Stats for telemetry.
-
#request_size ⇒ Object
Stats for telemetry.
Instance Method Summary collapse
- #client_error? ⇒ Boolean
- #code ⇒ Object
- #error ⇒ Object
- #gzipped_body?(body) ⇒ Boolean
- #gzipped_content? ⇒ Boolean
- #header(name) ⇒ Object
-
#initialize(http_response) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #not_found? ⇒ Boolean
- #ok? ⇒ Boolean
- #payload ⇒ Object
- #response_size ⇒ Object
- #server_error? ⇒ Boolean
- #telemetry_error_type ⇒ Object
-
#trace_count ⇒ Object
compatibility with Datadog::Tracing transport layer.
- #unsupported? ⇒ Boolean
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_ms ⇒ Object
Stats for telemetry
69 70 71 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 69 def duration_ms @duration_ms end |
#http_response ⇒ Object (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_compressed ⇒ Object
Stats for telemetry
69 70 71 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 69 def request_compressed @request_compressed end |
#request_size ⇒ Object
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
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 |
#code ⇒ Object
92 93 94 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 92 def code http_response.code.to_i end |
#error ⇒ Object
139 140 141 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 139 def error nil end |
#gzipped_body?(body) ⇒ 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
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 |
#inspect ⇒ Object
161 162 163 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 161 def inspect "#{super}, http_response:#{http_response}" end |
#not_found? ⇒ Boolean
107 108 109 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 107 def not_found? code == 404 end |
#ok? ⇒ 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 |
#payload ⇒ Object
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_size ⇒ Object
84 85 86 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 84 def response_size http_response.body.bytesize end |
#server_error? ⇒ 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_type ⇒ Object
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_count ⇒ Object
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
103 104 105 |
# File 'lib/datadog/ci/transport/adapters/net.rb', line 103 def unsupported? code == 415 end |