1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
require "spec"
require "mime/multipart"
describe MIME::Multipart do
describe ".parse" do
it "parses multipart messages" do
multipart = "--aA40\r\nContent-Type: text/plain\r\n\r\nabcd\r\n--aA40--"
MIME::Multipart.parse(IO::Memory.new(multipart), "aA40") do |headers, io|
headers["Content-Type"].should eq("text/plain")
io.gets_to_end.should eq("abcd")
end
end
end
describe ".parse_boundary" do
it "parses unquoted boundaries" do
content_type = "multipart/mixed; boundary=a_-47HDS"
MIME::Multipart.parse_boundary(content_type).should eq("a_-47HDS")
end
it "parses quoted boundaries" do
content_type = %{multipart/mixed; boundary="aA_-<>()"}
MIME::Multipart.parse_boundary(content_type).should eq(%{aA_-<>()})
end
end
describe ".parse" do
it "parses multipart messages" do
headers = HTTP::Headers{"Content-Type" => "multipart/mixed; boundary=aA40"}
body = "--aA40\r\nContent-Type: text/plain\r\n\r\nbody\r\n--aA40--"
request = HTTP::Request.new("POST", "/", headers, body)
MIME::Multipart.parse(request) do |headers, io|
headers["Content-Type"].should eq("text/plain")
io.gets_to_end.should eq("body")
end
end
it "parses multipart messages from HTTP client responses" do
headers = HTTP::Headers{"Content-Type" => "multipart/byteranges; boundary=aA40"}
body = "--aA40\r\nContent-Type: text/plain\r\n\r\nbody\r\n--aA40--"
response = HTTP::Client::Response.new(
status: :ok,
headers: headers,
body: body,
)
MIME::Multipart.parse(response) do |headers, io|
headers["Content-Type"].should eq("text/plain")
io.gets_to_end.should eq("body")
end
end
end
end
|