mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-03 04:38:39 +01:00
fix for MultipartWriter leading CR-LF bug
This commit is contained in:
parent
d615c47379
commit
8a498c2e19
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MultipartReader.h
|
// MultipartReader.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.3/Net/include/Poco/Net/MultipartReader.h#1 $
|
// $Id: //poco/1.3/Net/include/Poco/Net/MultipartReader.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Net
|
// Library: Net
|
||||||
// Package: Messages
|
// Package: Messages
|
||||||
@ -104,7 +104,7 @@ class Net_API MultipartReader
|
|||||||
/// message into its single parts.
|
/// message into its single parts.
|
||||||
///
|
///
|
||||||
/// The format of multipart messages is described
|
/// The format of multipart messages is described
|
||||||
/// in section 7.2 of RFC 1341.
|
/// in section 5.1 of RFC 2046.
|
||||||
///
|
///
|
||||||
/// To split a multipart message into its parts,
|
/// To split a multipart message into its parts,
|
||||||
/// do the following:
|
/// do the following:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MultipartWriter.h
|
// MultipartWriter.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.3/Net/include/Poco/Net/MultipartWriter.h#1 $
|
// $Id: //poco/1.3/Net/include/Poco/Net/MultipartWriter.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Net
|
// Library: Net
|
||||||
// Package: Messages
|
// Package: Messages
|
||||||
@ -56,7 +56,7 @@ class Net_API MultipartWriter
|
|||||||
/// messages to an output stream.
|
/// messages to an output stream.
|
||||||
///
|
///
|
||||||
/// The format of multipart messages is described
|
/// The format of multipart messages is described
|
||||||
/// in section 7.2 of RFC 1341.
|
/// in section 5.1 of RFC 2046.
|
||||||
///
|
///
|
||||||
/// To create a multipart message, first create
|
/// To create a multipart message, first create
|
||||||
/// a MultipartWriter object.
|
/// a MultipartWriter object.
|
||||||
@ -112,6 +112,7 @@ private:
|
|||||||
|
|
||||||
std::ostream& _ostr;
|
std::ostream& _ostr;
|
||||||
std::string _boundary;
|
std::string _boundary;
|
||||||
|
bool _firstPart;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MultipartWriter.cpp
|
// MultipartWriter.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.3/Net/src/MultipartWriter.cpp#1 $
|
// $Id: //poco/1.3/Net/src/MultipartWriter.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Net
|
// Library: Net
|
||||||
// Package: Messages
|
// Package: Messages
|
||||||
@ -50,14 +50,16 @@ namespace Net {
|
|||||||
|
|
||||||
MultipartWriter::MultipartWriter(std::ostream& ostr):
|
MultipartWriter::MultipartWriter(std::ostream& ostr):
|
||||||
_ostr(ostr),
|
_ostr(ostr),
|
||||||
_boundary(createBoundary())
|
_boundary(createBoundary()),
|
||||||
|
_firstPart(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MultipartWriter::MultipartWriter(std::ostream& ostr, const std::string& boundary):
|
MultipartWriter::MultipartWriter(std::ostream& ostr, const std::string& boundary):
|
||||||
_ostr(ostr),
|
_ostr(ostr),
|
||||||
_boundary(boundary)
|
_boundary(boundary),
|
||||||
|
_firstPart(true)
|
||||||
{
|
{
|
||||||
if (_boundary.empty())
|
if (_boundary.empty())
|
||||||
_boundary = createBoundary();
|
_boundary = createBoundary();
|
||||||
@ -71,7 +73,11 @@ MultipartWriter::~MultipartWriter()
|
|||||||
|
|
||||||
void MultipartWriter::nextPart(const MessageHeader& header)
|
void MultipartWriter::nextPart(const MessageHeader& header)
|
||||||
{
|
{
|
||||||
_ostr << "\r\n--" << _boundary << "\r\n";
|
if (_firstPart)
|
||||||
|
_firstPart = false;
|
||||||
|
else
|
||||||
|
_ostr << "\r\n";
|
||||||
|
_ostr << "--" << _boundary << "\r\n";
|
||||||
header.write(_ostr);
|
header.write(_ostr);
|
||||||
_ostr << "\r\n";
|
_ostr << "\r\n";
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// HTMLFormTest.cpp
|
// HTMLFormTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.3/Net/testsuite/src/HTMLFormTest.cpp#1 $
|
// $Id: //poco/1.3/Net/testsuite/src/HTMLFormTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
@ -133,7 +133,7 @@ void HTMLFormTest::testWriteMultipart()
|
|||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
form.write(ostr, "MIME_boundary_0123456789");
|
form.write(ostr, "MIME_boundary_0123456789");
|
||||||
std::string s = ostr.str();
|
std::string s = ostr.str();
|
||||||
assert (s == "\r\n"
|
assert (s ==
|
||||||
"--MIME_boundary_0123456789\r\n"
|
"--MIME_boundary_0123456789\r\n"
|
||||||
"Content-Disposition: form-data; name=\"field1\"\r\n"
|
"Content-Disposition: form-data; name=\"field1\"\r\n"
|
||||||
"\r\n"
|
"\r\n"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MailMessageTest.cpp
|
// MailMessageTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.3/Net/testsuite/src/MailMessageTest.cpp#1 $
|
// $Id: //poco/1.3/Net/testsuite/src/MailMessageTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
@ -284,7 +284,6 @@ void MailMessageTest::testWriteMultiPart()
|
|||||||
"Subject: Test Message\r\n"
|
"Subject: Test Message\r\n"
|
||||||
"To: John Doe <john.doe@no.where>\r\n"
|
"To: John Doe <john.doe@no.where>\r\n"
|
||||||
"\r\n"
|
"\r\n"
|
||||||
"\r\n"
|
|
||||||
"--$\r\n"
|
"--$\r\n"
|
||||||
"Content-Disposition: inline\r\n"
|
"Content-Disposition: inline\r\n"
|
||||||
"Content-Transfer-Encoding: 8bit\r\n"
|
"Content-Transfer-Encoding: 8bit\r\n"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MultipartWriterTest.cpp
|
// MultipartWriterTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.3/Net/testsuite/src/MultipartWriterTest.cpp#1 $
|
// $Id: //poco/1.3/Net/testsuite/src/MultipartWriterTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
@ -63,7 +63,7 @@ void MultipartWriterTest::testWriteOnePart()
|
|||||||
ostr << "this is part 1";
|
ostr << "this is part 1";
|
||||||
w.close();
|
w.close();
|
||||||
std::string s = ostr.str();
|
std::string s = ostr.str();
|
||||||
assert (s == "\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
|
assert (s == "--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ void MultipartWriterTest::testWriteTwoParts()
|
|||||||
ostr << "this is part 2";
|
ostr << "this is part 2";
|
||||||
w.close();
|
w.close();
|
||||||
std::string s = ostr.str();
|
std::string s = ostr.str();
|
||||||
assert (s == "\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567\r\n\r\nthis is part 2\r\n--MIME_boundary_01234567--\r\n");
|
assert (s == "--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567\r\n\r\nthis is part 2\r\n--MIME_boundary_01234567--\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user