Module: HTTPX::Plugins::Compression::RequestBodyMethods

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

Instance Method Summary collapse

Instance Method Details

#initialize(options) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/httpx/plugins/compression.rb', line 58

def initialize(*, options)
  super
  return if @body.nil?

  threshold = options.compression_threshold_size
  return if threshold && !unbounded_body? && @body.bytesize < threshold

  @headers.get("content-encoding").each do |encoding|
    next if encoding == "identity"

    @body = Encoder.new(@body, options.encodings.registry(encoding).deflater)
  end
  @headers["content-length"] = @body.bytesize unless unbounded_body?
end