HTTP::Multipart::Parser

class HTTP::Multipart::Parser

Overview

Parses multipart MIME messages.

Example

multipart = "--aA40\r\nContent-Type: text/plain\r\n\r\nbody\r\n--aA40--"
parser = HTTP::Multipart::Parser.new(IO::Memory.new(multipart), "aA40")

while parser.has_next?
  parser.next do |headers, io|
    headers["Content-Type"] # => "text/plain"
    io.gets_to_end          # => "body"
  end
end

Please note that the IO object yielded by #next is only valid until the block returns.

Defined in:

http/multipart/parser.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.new(io : IO, boundary : String)Source

Creates a new Multipart::Parser which parses io with multipart boundary boundary.

Instance Method Detail

def has_next?Source

True if #next can be called legally.

def next(&block)Source

Parses the next body part and yields headers as HTTP::Headers and the body text as an IO.

This method yields once instead of returning the values, because the IO object yielded to the block is only valid while the block is executing. The IO object will be closed as soon as the block returns. To store the content of the body part for longer than the block, the IO must be read into memory.

multipart = "--aA40\r\nContent-Type: text/plain\r\n\r\nbody\r\n--aA40--"
parser = HTTP::Multipart::Parser.new(IO::Memory.new(multipart), "aA40")
parser.next do |headers, io|
  headers["Content-Type"] # => "text/plain"
  io.gets_to_end          # => "body"
end

© 2012–2017 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.22.0/HTTP/Multipart/Parser.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部