Module: Riak::Util::Multipart

Extended by:
Multipart
Included in:
Multipart, StreamParser
Defined in:
lib/riak/util/multipart.rb,
lib/riak/util/multipart/stream_parser.rb

Overview

Utility methods for handling multipart/mixed responses

Defined Under Namespace

Classes: StreamParser

Instance Method Summary (collapse)

Instance Method Details

- (String) extract_boundary(header_string)

Extracts the boundary string from a Content-Type header that is a multipart type

Parameters:

  • header_string (String)

    the Content-Type header

Returns:

  • (String)

    the boundary string separating each part



21
22
23
# File 'lib/riak/util/multipart.rb', line 21

def extract_boundary(header_string)
  $1 if header_string =~ /boundary=([A-Za-z0-9\'()+_,-.\/:=?]+)/
end

- (Object) parse(data, boundary)

Parses a multipart/mixed body into its constituent parts, including nested multipart/mixed sections

Parameters:

  • data (String)

    the multipart body data

  • boundary (String)

    the boundary string given in the Content-Type header



11
12
13
14
15
16
# File 'lib/riak/util/multipart.rb', line 11

def parse(data, boundary)
  contents = data.match(end_boundary_regex(boundary)).pre_match rescue ""
  contents.split(inner_boundary_regex(boundary)).reject(&:blank?).map do |part|
    parse_multipart_section(part)
  end.compact
end