Class: Celluloid::Http::BodyDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid-http/body_decoder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers, raw_body) ⇒ BodyDecoder

Returns a new instance of BodyDecoder.



14
15
16
# File 'lib/celluloid-http/body_decoder.rb', line 14

def initialize(headers, raw_body)
  @headers, @body = headers, raw_body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



13
14
15
# File 'lib/celluloid-http/body_decoder.rb', line 13

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



13
14
15
# File 'lib/celluloid-http/body_decoder.rb', line 13

def headers
  @headers
end

Class Method Details

.decode(headers, raw_body) ⇒ Object



7
8
9
# File 'lib/celluloid-http/body_decoder.rb', line 7

def decode(headers, raw_body)
  new(headers, raw_body).decode.body
end

Instance Method Details

#decodeObject



18
19
20
21
# File 'lib/celluloid-http/body_decoder.rb', line 18

def decode
  @body = gunzip(@body) if zip?
  self
end

#gunzip(body) ⇒ Object



23
24
25
# File 'lib/celluloid-http/body_decoder.rb', line 23

def gunzip(body)
  Zlib::GzipReader.new(StringIO.new(body)).read
end

#zip?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/celluloid-http/body_decoder.rb', line 27

def zip?
  @headers['Content-Encoding'] == 'gzip'
end