| 202 | if (boundaryValue.isEmpty()) |
| 203 | return Result::Error(HttpResultCategory, HttpError::MultipartWriterBoundaryEmpty); |
| 204 | if (boundaryValue.sizeInBytes() >= sizeof(boundaryStorage)) |
| 205 | return Result::Error(HttpResultCategory, HttpError::MultipartBoundaryTooLong); |
| 206 | if (not scHttpMultipartBoundaryIsSafe(boundaryValue)) |
| 207 | return Result::Error(HttpResultCategory, HttpError::MultipartWriterBoundaryUnsafe); |
| 208 | ::memcpy(boundaryStorage, boundaryValue.bytesWithoutTerminator(), boundaryValue.sizeInBytes()); |
| 209 | boundary = StringSpan::fromNullTerminated(boundaryStorage, StringEncoding::Ascii); |
| 210 | return Result(true); |
| 211 | } |
| 212 | |
| 213 | Result HttpMultipartWriter::addField(StringSpan fieldName, StringSpan value) |
| 214 | { |
| 215 | if (boundary.isEmpty()) |
| 216 | return Result::Error(HttpResultCategory, HttpError::MultipartWriterBoundaryMissing); |
| 217 | if (fieldName.isEmpty()) |
| 218 | return Result::Error(HttpResultCategory, HttpError::MultipartWriterFieldNameEmpty); |
| 219 | if (not scHttpMultipartQuotedParameterIsSafe(fieldName)) |