Skip to content

Commit

Permalink
- applies code review suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <[email protected]>
  • Loading branch information
baywet committed Aug 1, 2023
1 parent 733b78a commit 127b6ac
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/MultipartBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ public void Serialize(ISerializationWriter writer)
if(first)
first = false;
else
writer.WriteStringValue(string.Empty, string.Empty);
AddNewLine(writer);

writer.WriteStringValue(string.Empty, $"--{Boundary}");
writer.WriteStringValue("Content-Type", $"{part.Value.Item1}");
writer.WriteStringValue("Content-Disposition", $"form-data; name=\"{part.Key}\"");
writer.WriteStringValue(string.Empty, string.Empty);
AddNewLine(writer);
if(part.Value.Item2 is IParsable parsable)
{
using var partWriter = RequestAdapter.SerializationWriterFactory.GetSerializationWriter(part.Value.Item1);
Expand All @@ -130,6 +130,10 @@ public void Serialize(ISerializationWriter writer)
{
writer.WriteStringValue(string.Empty, currentString);
}
else if(part.Value.Item2 is MemoryStream originalMemoryStream)
{
writer.WriteByteArrayValue(string.Empty, originalMemoryStream.ToArray());
}
else if(part.Value.Item2 is Stream currentStream)
{
if(currentStream.CanSeek)
Expand All @@ -152,7 +156,11 @@ public void Serialize(ISerializationWriter writer)
writer.WriteByteArrayValue(part.Key, currentBinary);
}
}
writer.WriteStringValue(string.Empty, string.Empty);
AddNewLine(writer);
writer.WriteStringValue(string.Empty, $"--{Boundary}--");
}
private void AddNewLine(ISerializationWriter writer)
{
writer.WriteStringValue(string.Empty, string.Empty);
}
}

0 comments on commit 127b6ac

Please sign in to comment.