Skip to content

Commit 28b85c8

Browse files
committed
fix(HTTP): error boundary in HTTP-Header, Content-Type
see `https://www.rfc-editor.org/rfc/rfc2046#section-5.1` Poco carries extra ''", which can cause nginx to return 'Malformed multipart message', upload fail.
1 parent 09c33d0 commit 28b85c8

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

Net/src/HTMLForm.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,8 @@ void HTMLForm::prepareSubmit(HTTPRequest& request, int options)
219219
{
220220
_boundary = MultipartWriter::createBoundary();
221221
std::string ct(_encoding);
222-
ct.append("; boundary=\"");
222+
ct.append("; boundary=");
223223
ct.append(_boundary);
224-
ct.append("\"");
225224
request.setContentType(ct);
226225
}
227226
if (request.getVersion() == HTTPMessage::HTTP_1_0)

Net/testsuite/src/HTMLFormTest.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ void HTMLFormTest::testReadMultipart()
254254
"--MIME_boundary_0123456789--\r\n"
255255
);
256256
HTTPRequest req("POST", "/form.cgi");
257-
req.setContentType(HTMLForm::ENCODING_MULTIPART + "; boundary=\"MIME_boundary_0123456789\"");
257+
req.setContentType(HTMLForm::ENCODING_MULTIPART + "; boundary=MIME_boundary_0123456789");
258258
StringPartHandler sah;
259259
HTMLForm form(req, istr, sah);
260260
assertTrue (form.size() == 4);
@@ -309,9 +309,8 @@ void HTMLFormTest::testSubmit3()
309309
HTTPRequest req("POST", "/form.cgi", HTTPMessage::HTTP_1_1);
310310
form.prepareSubmit(req);
311311
std::string expCT(HTMLForm::ENCODING_MULTIPART);
312-
expCT.append("; boundary=\"");
312+
expCT.append("; boundary=");
313313
expCT.append(form.boundary());
314-
expCT.append("\"");
315314
assertTrue (req.getContentType() == expCT);
316315
assertTrue (req.getChunkedTransferEncoding());
317316
}
@@ -343,9 +342,8 @@ void HTMLFormTest::testSubmit5()
343342
HTTPRequest req("POST", "/form.cgi", HTTPMessage::HTTP_1_1);
344343
form.prepareSubmit(req, HTMLForm::OPT_USE_CONTENT_LENGTH);
345344
std::string expCT(HTMLForm::ENCODING_MULTIPART);
346-
expCT.append("; boundary=\"");
345+
expCT.append("; boundary=");
347346
expCT.append(form.boundary());
348-
expCT.append("\"");
349347
assertTrue (req.getContentType() == expCT);
350348
assertTrue (req.getContentLength() == 403);
351349
}
@@ -395,7 +393,7 @@ void HTMLFormTest::testFieldLimitMultipart()
395393
"--MIME_boundary_0123456789--\r\n"
396394
);
397395
HTTPRequest req("POST", "/form.cgi");
398-
req.setContentType(HTMLForm::ENCODING_MULTIPART + "; boundary=\"MIME_boundary_0123456789\"");
396+
req.setContentType(HTMLForm::ENCODING_MULTIPART + "; boundary=MIME_boundary_0123456789");
399397
StringPartHandler sah;
400398
HTMLForm form;
401399
form.setFieldLimit(3);

Net/testsuite/src/MediaTypeTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void MediaTypeTest::testParse()
4747
assertTrue (mt3.getParameter("param1") == "value1");
4848
assertTrue (mt3.getParameter("PARAM2") == "value 2");
4949

50-
MediaType mt4("multipart/mixed; boundary=\"MIME_boundary_01234567\"");
50+
MediaType mt4("multipart/mixed; boundary=MIME_boundary_01234567");
5151
assertTrue (mt4.getType() == "multipart");
5252
assertTrue (mt4.getSubType() == "mixed");
5353
assertTrue (mt4.parameters().size() == 1);

Net/testsuite/src/MessageHeaderTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ void MessageHeaderTest::testSplitParameters()
309309
assertTrue (p.size() == 1);
310310
assertTrue (p["boundary"] == "MIME_boundary_01234567");
311311

312-
s = "multipart/related; boundary=\"MIME_boundary_76543210\"";
312+
s = "multipart/related; boundary=MIME_boundary_76543210";
313313
MessageHeader::splitParameters(s, v, p);
314314
assertTrue (v == "multipart/related");
315315
assertTrue (p.size() == 1);

0 commit comments

Comments
 (0)