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
49 def initialize(*)
50   @encodings = []
51 
52   super
53 
54   return unless @headers.key?("content-encoding")
55 
56   @_decoders = @headers.get("content-encoding").map do |encoding|
57     decoder = Compression.registry(encoding).decoder
58     # do not uncompress if there is no decoder available. In fact, we can't reliably
59     # continue decompressing beyond that, so ignore.
60     break unless decoder
61 
62     @encodings << encoding
63     decoder
64   end
65 
66   # remove encodings that we are able to decode
67   @headers["content-encoding"] = @headers.get("content-encoding") - @encodings
68 
69   @_compressed_length = if @headers.key?("content-length")
70     @headers["content-length"].to_i
71   else
72     Float::INFINITY
73   end
74 end

Public Instance methods

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