module HTTPX::Plugins::Compression::ResponseBodyMethods

  1. lib/httpx/plugins/compression.rb

Methods

Public Class

  1. new

Public Instance

  1. close
  2. encodings
  3. write

Attributes

encodings [R]

Public Class methods

new (*, **)
[show source]
   # File lib/httpx/plugins/compression.rb
51 def initialize(*, **)
52   @encodings = []
53 
54   super
55 
56   return unless @headers.key?("content-encoding")
57 
58   @_decoders = @headers.get("content-encoding").map do |encoding|
59     next if encoding == "identity"
60 
61     decoder = Compression.registry(encoding).decoder
62     # do not uncompress if there is no decoder available. In fact, we can't reliably
63     # continue decompressing beyond that, so ignore.
64     break unless decoder
65 
66     @encodings << encoding
67     decoder
68   end.compact
69 
70   # remove encodings that we are able to decode
71   @headers["content-encoding"] = @headers.get("content-encoding") - @encodings
72 
73   @_compressed_length = if @headers.key?("content-length")
74     @headers["content-length"].to_i
75   else
76     Float::INFINITY
77   end
78 end

Public Instance methods

close ()
[show source]
   # File lib/httpx/plugins/compression.rb
88 def close
89   super
90 
91   return unless defined?(@_decoders)
92 
93   @_decoders.each(&:close)
94 end
write (chunk)
[show source]
   # File lib/httpx/plugins/compression.rb
80 def write(chunk)
81   return super unless defined?(@_compressed_length)
82 
83   @_compressed_length -= chunk.bytesize
84   chunk = decompress(chunk)
85   super(chunk)
86 end