-
Notifications
You must be signed in to change notification settings - Fork 161
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
Write the HTTP response only when all output has been formatted #858
base: release-8.x
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,19 +67,20 @@ internal static async Task WriteToStreamAsync( | |
|
||
ODataPath path = request.ODataFeature().Path; | ||
IEdmNavigationSource targetNavigationSource = path.GetNavigationSource(); | ||
HttpResponse response = request.HttpContext.Response; | ||
var responseBody = new MemoryStream(); | ||
var responseHeaders = request.HttpContext.Response.Headers; | ||
|
||
// serialize a response | ||
string preferHeader = RequestPreferenceHelpers.GetRequestPreferHeader(requestHeaders); | ||
string annotationFilter = null; | ||
if (!string.IsNullOrEmpty(preferHeader)) | ||
{ | ||
ODataMessageWrapper messageWrapper = ODataMessageWrapperHelper.Create(response.Body, response.Headers); | ||
ODataMessageWrapper messageWrapper = ODataMessageWrapperHelper.Create(responseBody, responseHeaders); | ||
messageWrapper.SetHeader(RequestPreferenceHelpers.PreferHeaderName, preferHeader); | ||
annotationFilter = messageWrapper.PreferHeader().AnnotationFilter; | ||
} | ||
|
||
IODataResponseMessageAsync responseMessage = ODataMessageWrapperHelper.Create(new StreamWrapper(response.Body), response.Headers, request.GetRouteServices()); | ||
IODataResponseMessageAsync responseMessage = ODataMessageWrapperHelper.Create(new StreamWrapper(responseBody), responseHeaders, request.GetRouteServices()); | ||
if (annotationFilter != null) | ||
{ | ||
responseMessage.PreferenceAppliedHeader().AnnotationFilter = annotationFilter; | ||
|
@@ -150,6 +151,7 @@ internal static async Task WriteToStreamAsync( | |
} | ||
|
||
await serializer.WriteObjectAsync(value, type, messageWriter, writeContext).ConfigureAwait(false); | ||
await request.HttpContext.Response.Body.WriteAsync(responseBody.ToArray()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we really need to create array of unknown size here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha, I was missing rewinding the buffer response body stream back to position zero |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assume to use memory stream pooling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean Microsoft.IO.RecyclableMemoryStream ?