Class: ClickhouseRuby::Connection::DecompressedResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/clickhouse_ruby/connection.rb

Overview

Wrapper for automatically decompressing gzip responses

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ DecompressedResponse

Returns a new instance of DecompressedResponse.

Parameters:

  • response (Net::HTTPResponse)

    the original HTTP response



410
411
412
413
# File 'lib/clickhouse_ruby/connection.rb', line 410

def initialize(response)
  @response = response
  @decompressed_body = nil
end

Instance Method Details

#[](header) ⇒ String?

Returns a header value

Parameters:

  • header (String)

    header name

Returns:

  • (String, nil)

    header value



426
427
428
# File 'lib/clickhouse_ruby/connection.rb', line 426

def [](header)
  @response[header]
end

#bodyString

Returns the decompressed response body

Returns:

  • (String)

    decompressed body



433
434
435
436
437
438
439
440
441
# File 'lib/clickhouse_ruby/connection.rb', line 433

def body
  @decompressed_body ||= begin
    return @response.body if @response.body.nil? || @response.body.empty?

    Zlib.gunzip(@response.body)
  rescue Zlib::Error
    @response.body
  end
end

#codeString

Returns the HTTP status code

Returns:

  • (String)

    status code



418
419
420
# File 'lib/clickhouse_ruby/connection.rb', line 418

def code
  @response.code
end