HTTP::Multipart::Builder
class HTTP::Multipart::Builder
Overview
Builds a multipart MIME message.
Example
io = IO::Memory.new multipart = HTTP::Multipart::Builder.new(io) multipart.body_part HTTP::Headers{"Content-Type" => "text/plain"}, "hello!" multipart.finish io.to_s # => "----------------------------DTf61dRTHYzprx7rwVQhTWr7\r\nContent-Type: text/plain\r\n\r\nhello!\r\n----------------------------DTf61dRTHYzprx7rwVQhTWr7--"
Defined in:
http/multipart/builder.crClass Method Summary
- .new(io : IO, boundary = Multipart.generate_boundary)
Creates a new
Multipart::Builder
which writes the generated multipart message to io, using the multipart boundary boundary-
Instance Method Summary
- #body_part(headers : HTTP::Headers, string : String)
Appends a body part to the multipart message with the given headers and string.
- #body_part(headers : HTTP::Headers, data : Bytes)
Appends a body part to the multipart message with the given headers and data.
- #body_part(headers : HTTP::Headers, body_io : IO)
Appends a body part to the multipart message with the given headers and data from body_io.
- #body_part(headers : HTTP::Headers, &block)
Yields an IO that can be used to write to a body part which is appended to the multipart message with the given headers.
- #body_part(headers : HTTP::Headers)
Appends a body part to the multipart message with the given headers and no body data.
- #boundary : String
- #content_type(subtype = "mixed")
Returns a content type header with multipart subtype subtype, and boundary parameter added.
- #epilogue(string : String)
Appends string to the epilogue segment of the multipart message.
- #epilogue(data : Bytes)
Appends data to the epilogue segment of the multipart message.
- #epilogue(epilogue_io : IO)
Appends preamble_io to the epilogue segment of the multipart message.
- #epilogue(&block)
Yields an IO that can be used to append to the epilogue of the multipart message.
- #finish
Finalizes the multipart message, this method must be called to properly end the multipart message.
- #preamble(string : String)
Appends string to the preamble segment of the multipart message.
- #preamble(data : Bytes)
Appends data to the preamble segment of the multipart message.
- #preamble(preamble_io : IO)
Appends preamble_io to the preamble segment of the multipart message.
- #preamble(&block)
Yields an IO that can be used to append to the preamble of the multipart message.
Instance methods inherited from class Reference
==(other : self)==(other) ==, dup dup, hash hash, inspect(io : IO) : Nil inspect, object_id : UInt64 object_id, pretty_print(pp) : Nil pretty_print, same?(other : Reference)
same?(other : Nil) same?, to_s(io : IO) : Nil to_s
Class methods inherited from class Reference
new new Instance methods inherited from class Object
!=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)===(other : YAML::Any)
===(other) ===, =~(other) =~, class class, dup dup, hash hash, inspect(io : IO)
inspect inspect, itself itself, not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, tap(&block) tap, to_json(io : IO)
to_json to_json, to_pretty_json(indent : String = " ")
to_pretty_json(io : IO, indent : String = " ") to_pretty_json, to_s
to_s(io : IO) to_s, to_yaml(io : IO)
to_yaml to_yaml, try(&block) try
Class methods inherited from class Object
from_json(string_or_io, root : String) : selffrom_json(string_or_io) : self from_json, from_yaml(string_or_io) : self from_yaml
Class Method Detail
def self.new(io : IO, boundary = Multipart.generate_boundary)Source
Creates a new Multipart::Builder
which writes the generated multipart message to io, using the multipart boundary boundary-
Instance Method Detail
def body_part(headers : HTTP::Headers, string : String)Source
def body_part(headers : HTTP::Headers, data : Bytes)Source
def body_part(headers : HTTP::Headers, body_io : IO)Source
def body_part(headers : HTTP::Headers, &block)Source
def body_part(headers : HTTP::Headers)Source
def content_type(subtype = "mixed")Source
Returns a content type header with multipart subtype subtype, and boundary parameter added.
builder = HTTP::Multipart::Builder.new(io, "a4VF") builder.content_type("mixed") # => "multipart/mixed; boundary=\"a4VF\""
def epilogue(string : String)Source
Appends string to the epilogue segment of the multipart message. Throws if #finish
is called before this method, or no body parts have been appended.
Can be called multiple times to append to the epilogue multiple times.
def epilogue(data : Bytes)Source
Appends data to the epilogue segment of the multipart message. Throws if #finish
is called before this method, or no body parts have been appended.
Can be called multiple times to append to the epilogue multiple times.
def epilogue(epilogue_io : IO)Source
Appends preamble_io to the epilogue segment of the multipart message. Throws if #finish
is called before this method, or no body parts have been appended.
Can be called multiple times to append to the epilogue multiple times.
def epilogue(&block)Source
Yields an IO that can be used to append to the epilogue of the multipart message. Throws if #finish
is called before this method, or no body parts have been appended.
Can be called multiple times to append to the preamble multiple times.
def finishSource
Finalizes the multipart message, this method must be called to properly end the multipart message.
def preamble(string : String)Source
Appends string to the preamble segment of the multipart message. Throws if #body_part
is called before this method.
Can be called multiple times to append to the preamble multiple times.
def preamble(data : Bytes)Source
Appends data to the preamble segment of the multipart message. Throws if #body_part
is called before this method.
Can be called multiple times to append to the preamble multiple times.
def preamble(preamble_io : IO)Source
Appends preamble_io to the preamble segment of the multipart message. Throws if #body_part
is called before this method.
Can be called multiple times to append to the preamble multiple times.
def preamble(&block)Source
Yields an IO that can be used to append to the preamble of the multipart message. Throws if #body_part
is called before this method.
Can be called multiple times to append to the preamble multiple times.
© 2012–2017 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.22.0/HTTP/Multipart/Builder.html