Class: HTTP::Features::AutoDeflate

Inherits:
HTTP::Feature show all
Defined in:
lib/http/features/auto_deflate.rb

Defined Under Namespace

Classes: CompressedBody, DeflatedBody, GzippedBody

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAutoDeflate

Returns a new instance of AutoDeflate.

Raises:



11
12
13
14
15
16
17
# File 'lib/http/features/auto_deflate.rb', line 11

def initialize(*)
  super

  @method = @opts.key?(:method) ? @opts[:method].to_s : "gzip"

  raise Error, "Only gzip and deflate methods are supported" unless %w[gzip deflate].include?(@method)
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/http/features/auto_deflate.rb', line 9

def method
  @method
end

Instance Method Details

#deflated_body(body) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/http/features/auto_deflate.rb', line 19

def deflated_body(body)
  case method
  when "gzip"
    GzippedBody.new(body)
  when "deflate"
    DeflatedBody.new(body)
  else
    raise ArgumentError, "Unsupported deflate method: #{method}"
  end
end