Repository navigation
fix(multipart): omit nil header string values and support additionalValuesToMerge - #2220
Conversation
|
I've opened this PR in
Unit tests covering header omission, additional values merging, and invalid part validation have been added, and |
…ress review feedback
|
I have updated the PR in commit \29b7efa0\ to address the review recommendations:
Local Gradle test suites and \spotlessCheck\ pass cleanly. Whenever convenient, please take another look. Thank you! |
| if (value.equals("--" + currentTargetBoundary)) { | ||
| valueToWrite = "--" + currentReplacementBoundary; | ||
| } else if (value.equals("--" + currentTargetBoundary + "--")) { | ||
| if (isLastBody) { | ||
| valueToWrite = "--" + currentReplacementBoundary + "--"; |
There was a problem hiding this comment.
Resolved: Introduced an explicit FramingState state machine in MultipartSerializationWriter to track MIME framing phases (EXPECTING_FIRST_BOUNDARY, IN_HEADERS, EXPECTING_PAYLOAD, EXPECTING_DELIMITER_AFTER_PAYLOAD, EXPECTING_BOUNDARY_OR_CLOSING, and FINISHED). Boundary rewriting and intermediate closing delimiter suppression are now strictly scoped to structural framing delimiters (EXPECTING_FIRST_BOUNDARY and EXPECTING_BOUNDARY_OR_CLOSING), ensuring string payloads matching boundary or delimiter patterns are emitted untouched as message content. Added regression test preservesStringPayloadMatchingBoundaryOrClosingDelimiterWhenMerging in MultipartSerializationWriterTests.
|
I've pushed an update in commit
Whenever convenient, please take another look. Thank you! |


Summary of Changes
Omit Nil Header String Values in
writeStringValue:writeStringValue(key, value), ifkey != null && !key.isEmpty()andvalue == null, it previously serializedkey + "\r\n"without a colon or value, creating a malformed MIME header line that violates RFC 2046 and RFC 7230/5322 syntax.if (key != null && !key.isEmpty() && value == null), returning immediately so that headers with null values are cleanly omitted, matching the Kiota serialization convention across SDKs.key == null || key.isEmpty()andvalue == null("\r\n").Support
additionalValuesToMergeinwriteObjectValue:writeObjectValuevalidatedObjects.requireNonNull(additionalValuesToMerge)but completely ignored the array without serializing any additionalMultipartBodyparts.MultipartBody), invoking lifecycle callbacks (onBeforeObjectSerialization,onStartObjectSerialization,onAfterObjectSerialization), and serializing each part (consistent withFormSerializationWriterandJsonSerializationWriter).Unit Tests Added in
MultipartSerializationWriterTests:writesStringValueWithKeyValue: verifies standard header serialization (Content-Type: text/plain).writeStringValueWithNilValueOmitsHeader: verifies headers with null values are omitted.writeStringValueWithEmptyKeyAndNilValueWritesDelimiter: verifies delimiter emission (\r\n).writeStringValueWithEmptyKeyAndValueWritesRawLine: verifies raw line serialization.writesAStructuredObjectWithAdditionalValuesToMerge: verifies merging multipleMultipartBodyparts.throwsOnInvalidAdditionalValuesToMerge: asserts runtime exception for non-MultipartBody instances in additional values.