| 216 | } |
| 217 | |
| 218 | Result HttpMultipartWriter::addFile(StringSpan fieldName, StringSpan fileName, Span<const char> body, |
| 219 | StringSpan contentType) |
| 220 | { |
| 221 | SC_TRY_MSG(boundary.sizeInBytes() > 0, "HttpMultipartWriter::addFile boundary not set"); |
| 222 | SC_TRY_MSG(not fieldName.isEmpty(), "HttpMultipartWriter::addFile empty field name"); |
| 223 | SC_TRY_MSG(scHttpMultipartQuotedParameterIsSafe(fieldName), "HttpMultipartWriter::addFile unsafe field name"); |
| 224 | SC_TRY_MSG(fileName.isEmpty() or scHttpMultipartQuotedParameterIsSafe(fileName), |
| 225 | "HttpMultipartWriter::addFile unsafe file name"); |
| 226 | SC_TRY_MSG(contentType.isEmpty() or scHttpHeaderValueIsSafe(contentType), |
| 227 | "HttpMultipartWriter::addFile unsafe content type"); |
| 228 | SC_TRY_MSG(numParts < MaxParts, "HttpMultipartWriter::addFile too many parts"); |
| 229 | Part& part = parts[numParts++]; |
| 230 | part.partName = fieldName; |
| 231 | part.fileName = fileName; |
| 232 | part.contentType = contentType; |
| 233 | part.body = body; |
| 234 | return Result(true); |
| 235 | } |
| 236 | |
| 237 | size_t HttpMultipartWriter::getContentLength() const |
| 238 | { |