minor fixes, mostly style and documentation

This commit is contained in:
Guenter Obiltschnig
2017-02-15 09:52:58 +01:00
parent 68a0ff1515
commit 5692187d2d
27 changed files with 85 additions and 77 deletions

View File

@@ -235,6 +235,10 @@ void HTMLForm::prepareSubmit(HTTPRequest& request)
{
request.setChunkedTransferEncoding(true);
}
if (!request.getChunkedTransferEncoding())
{
request.setContentLength(calculateContentLength());
}
}
else
{
@@ -250,7 +254,7 @@ void HTMLForm::prepareSubmit(HTTPRequest& request)
std::streamsize HTMLForm::calculateContentLength()
{
if (_boundary.empty())
if (_encoding == ENCODING_MULTIPART && _boundary.empty())
throw HTMLFormException("Form must be prepared");
HTMLFormCountingOutputStream c;
@@ -399,7 +403,7 @@ void HTMLForm::writeUrl(std::ostream& ostr)
void HTMLForm::writeMultipart(std::ostream& ostr)
{
HTMLFormCountingOutputStream *costr(dynamic_cast<HTMLFormCountingOutputStream*>(&ostr));
HTMLFormCountingOutputStream* pCountingOutputStream(dynamic_cast<HTMLFormCountingOutputStream*>(&ostr));
MultipartWriter writer(ostr, _boundary);
for (NameValueCollection::ConstIterator it = begin(); it != end(); ++it)
@@ -428,17 +432,19 @@ void HTMLForm::writeMultipart(std::ostream& ostr)
header.set("Content-Disposition", disp);
header.set("Content-Type", ita->pSource->mediaType());
writer.nextPart(header);
if (costr)
if (pCountingOutputStream)
{
// count only, don't move stream position
std::streamsize partlen = ita->pSource->getContentLength();
if (partlen != PartSource::UNKNOWN_CONTENT_LENGTH)
costr->addChars(static_cast<int>(partlen));
pCountingOutputStream->addChars(static_cast<int>(partlen));
else
costr->setValid(false);
pCountingOutputStream->setValid(false);
}
else
{
StreamCopier::copyStream(ita->pSource->stream(), ostr);
}
}
writer.close();
_boundary = writer.boundary();