| 448 | } |
| 449 | |
| 450 | void URL::createHeadersAndPostData (String& headers, MemoryBlock& postDataToWrite) const |
| 451 | { |
| 452 | MemoryOutputStream data (postDataToWrite, false); |
| 453 | |
| 454 | if (filesToUpload.size() > 0) |
| 455 | { |
| 456 | // (this doesn't currently support mixing custom post-data with uploads..) |
| 457 | jassert (postData.getSize() == 0); |
| 458 | |
| 459 | auto boundary = String::toHexString (Random::getSystemRandom().nextInt64()); |
| 460 | |
| 461 | headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n"; |
| 462 | |
| 463 | data << "--" << boundary; |
| 464 | |
| 465 | for (int i = 0; i < parameterNames.size(); ++i) |
| 466 | { |
| 467 | data << "\r\nContent-Disposition: form-data; name=\"" << parameterNames[i] |
| 468 | << "\"\r\n\r\n" << parameterValues[i] |
| 469 | << "\r\n--" << boundary; |
| 470 | } |
| 471 | |
| 472 | for (auto* f : filesToUpload) |
| 473 | { |
| 474 | data << "\r\nContent-Disposition: form-data; name=\"" << f->parameterName |
| 475 | << "\"; filename=\"" << f->filename << "\"\r\n"; |
| 476 | |
| 477 | if (f->mimeType.isNotEmpty()) |
| 478 | data << "Content-Type: " << f->mimeType << "\r\n"; |
| 479 | |
| 480 | data << "Content-Transfer-Encoding: binary\r\n\r\n"; |
| 481 | |
| 482 | if (f->data != nullptr) |
| 483 | data << *f->data; |
| 484 | else |
| 485 | data << f->file; |
| 486 | |
| 487 | data << "\r\n--" << boundary; |
| 488 | } |
| 489 | |
| 490 | data << "--\r\n"; |
| 491 | } |
| 492 | else |
| 493 | { |
| 494 | data << URLHelpers::getMangledParameters (*this) |
| 495 | << postData; |
| 496 | |
| 497 | // if the user-supplied headers didn't contain a content-type, add one now.. |
| 498 | if (! headers.containsIgnoreCase ("Content-Type")) |
| 499 | headers << "Content-Type: application/x-www-form-urlencoded\r\n"; |
| 500 | |
| 501 | headers << "Content-length: " << (int) data.getDataSize() << "\r\n"; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | //============================================================================== |
| 506 | bool URL::isProbablyAWebsiteURL (const String& possibleURL) |
nothing calls this directly
no test coverage detected