Module: HTTPX::Plugins::Compression::ResponseBodyMethods

Defined in:
lib/httpx/plugins/compression.rb

Instance Method Summary collapse

Instance Method Details

#closeObject



60
61
62
63
64
65
66
# File 'lib/httpx/plugins/compression.rb', line 60

def close
  super

  return unless defined?(@_decoders)

  @_decoders.each(&:close)
end

#initializeObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/httpx/plugins/compression.rb', line 37

def initialize(*)
  super

  return unless @headers.key?("content-encoding")

  @_decoders = @headers.get("content-encoding").map do |encoding|
    Compression.registry(encoding).decoder
  end
  @_compressed_length = if @headers.key?("content-length")
    @headers["content-length"].to_i
  else
    Float::INFINITY
  end
end

#write(chunk) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/httpx/plugins/compression.rb', line 52

def write(chunk)
  return super unless defined?(@_compressed_length)

  @_compressed_length -= chunk.bytesize
  chunk = decompress(chunk)
  super(chunk)
end