| 399 | |
| 400 | |
| 401 | void HTMLForm::writeMultipart(std::ostream& ostr) |
| 402 | { |
| 403 | HTMLFormCountingOutputStream* pCountingOutputStream(dynamic_cast<HTMLFormCountingOutputStream*>(&ostr)); |
| 404 | |
| 405 | MultipartWriter writer(ostr, _boundary); |
| 406 | for (NameValueCollection::ConstIterator it = begin(); it != end(); ++it) |
| 407 | { |
| 408 | MessageHeader header; |
| 409 | std::string disp("form-data; name=\""); |
| 410 | disp.append(it->first); |
| 411 | disp.append("\""); |
| 412 | header.set("Content-Disposition", disp); |
| 413 | writer.nextPart(header); |
| 414 | ostr << it->second; |
| 415 | } |
| 416 | for (PartVec::iterator ita = _parts.begin(); ita != _parts.end(); ++ita) |
| 417 | { |
| 418 | MessageHeader header(ita->pSource->headers()); |
| 419 | std::string disp("form-data; name=\""); |
| 420 | disp.append(ita->name); |
| 421 | disp.append("\""); |
| 422 | std::string filename = ita->pSource->filename(); |
| 423 | if (!filename.empty()) |
| 424 | { |
| 425 | disp.append("; filename=\""); |
| 426 | disp.append(filename); |
| 427 | disp.append("\""); |
| 428 | } |
| 429 | header.set("Content-Disposition", disp); |
| 430 | header.set("Content-Type", ita->pSource->mediaType()); |
| 431 | writer.nextPart(header); |
| 432 | if (pCountingOutputStream) |
| 433 | { |
| 434 | // count only, don't move stream position |
| 435 | std::streamsize partlen = ita->pSource->getContentLength(); |
| 436 | if (partlen != PartSource::UNKNOWN_CONTENT_LENGTH) |
| 437 | pCountingOutputStream->addChars(static_cast<int>(partlen)); |
| 438 | else |
| 439 | pCountingOutputStream->setValid(false); |
| 440 | } |
| 441 | else |
| 442 | { |
| 443 | StreamCopier::copyStream(ita->pSource->stream(), ostr); |
| 444 | } |
| 445 | } |
| 446 | writer.close(); |
| 447 | _boundary = writer.boundary(); |
| 448 | } |
| 449 | |
| 450 | |
| 451 | void HTMLForm::setFieldLimit(int limit) |
nothing calls this directly
no test coverage detected