Class: Innards::MultipartHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/innards/multipart_handler.rb

Overview

Handles Digest Authentication

Instance Method Summary collapse

Constructor Details

#initialize(content_type) ⇒ MultipartHandler

Returns a new instance of MultipartHandler.



8
9
10
11
12
# File 'lib/innards/multipart_handler.rb', line 8

def initialize(content_type)
  @boundary = MultipartParser::Reader.extract_boundary_value(content_type)
rescue MultipartParser::NotMultipartError
  @boundary = ""
end

Instance Method Details

#is_multipart_response?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/innards/multipart_handler.rb', line 26

def is_multipart_response?
  !@boundary.empty?
end

#parse(body) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/innards/multipart_handler.rb', line 14

def parse body
  parts = []
  multipart_reader = MultipartParser::Reader.new @boundary
  multipart_reader.on_part do |part|
    part.on_data do |data|
      parts << part.headers.merge({:data => data})
    end
  end
  multipart_reader.write body.strip
  parts
end