Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed missing initial preamble in the MultiPart response formmatter. #5363

Merged
merged 1 commit into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

---
Content-Type: application/json; charset=utf-8

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

---
Content-Type: application/json; charset=utf-8

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

---
Content-Type: application/json; charset=utf-8

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

---
Content-Type: application/json; charset=utf-8

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ContentType": "multipart/mixed; boundary=\"-\"",
"StatusCode": "OK",
"Content": "---\r\nContent-Type: application/json; charset=utf-8\r\n\r\n{\"data\":{\"hero\":{\"name\":\"R2-D2\"}},\"hasNext\":true}\r\n---\r\nContent-Type: application/json; charset=utf-8\r\n\r\n{\"label\":\"my_id\",\"path\":[\"hero\"],\"data\":{\"id\":\"2001\"},\"hasNext\":false}\r\n-----\r\n"
"Content": "\r\n---\r\nContent-Type: application/json; charset=utf-8\r\n\r\n{\"data\":{\"hero\":{\"name\":\"R2-D2\"}},\"hasNext\":true}\r\n---\r\nContent-Type: application/json; charset=utf-8\r\n\r\n{\"label\":\"my_id\",\"path\":[\"hero\"],\"data\":{\"id\":\"2001\"},\"hasNext\":false}\r\n-----\r\n"
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public sealed partial class MultiPartResponseStreamFormatter : IResponseStreamFo
await outputStream.FlushAsync(ct).ConfigureAwait(false);
}

private async Task WriteResultAsync(
private async ValueTask WriteResultAsync(
IQueryResult result,
Stream outputStream,
CancellationToken ct)
Expand All @@ -116,10 +116,9 @@ public sealed partial class MultiPartResponseStreamFormatter : IResponseStreamFo
// The payload is sent, followed by a CRLF.
var buffer = writer.GetInternalBuffer();
await outputStream.WriteAsync(buffer, 0, writer.Length, ct).ConfigureAwait(false);
await outputStream.WriteAsync(CrLf, 0, CrLf.Length, ct).ConfigureAwait(false);
}

private static async Task WriteResultHeaderAsync(
private static async ValueTask WriteResultHeaderAsync(
Stream outputStream,
CancellationToken ct)
{
Expand All @@ -134,21 +133,23 @@ public sealed partial class MultiPartResponseStreamFormatter : IResponseStreamFo
await outputStream.WriteAsync(CrLf, 0, CrLf.Length, ct).ConfigureAwait(false);
}

private static async Task WriteNextAsync(
private static async ValueTask WriteNextAsync(
Stream outputStream,
CancellationToken ct)
{
// Each part of the multipart response must start with --- and a CRLF
// Before each part of the multi-part response, a boundary (CRLF, ---, CRLF) is sent.
await outputStream.WriteAsync(CrLf, 0, CrLf.Length, ct).ConfigureAwait(false);
await outputStream.WriteAsync(Start, 0, Start.Length, ct).ConfigureAwait(false);
await outputStream.WriteAsync(CrLf, 0, CrLf.Length, ct).ConfigureAwait(false);
}

private static async Task WriteEndAsync(
private static async ValueTask WriteEndAsync(
Stream outputStream,
CancellationToken ct)
{
// After the last part of the multipart response is sent, the terminating
// boundary ----- is sent, followed by a CRLF
// After the final payload, the terminating boundary of CRLF followed by
// ----- followed by CRLF is sent.
await outputStream.WriteAsync(CrLf, 0, CrLf.Length, ct).ConfigureAwait(false);
await outputStream.WriteAsync(End, 0, End.Length, ct).ConfigureAwait(false);
await outputStream.WriteAsync(CrLf, 0, CrLf.Length, ct).ConfigureAwait(false);
}
Expand Down