当我使用它们时,我应该在 Owin 的上下文中处理这些流吗?
Should I dispose the streams in Owin's context when I use them?
我正在使用 WebApp.Start();
为一个非常简单的自托管端点编写 Owin 中间件
要写入响应流,我有以下形式的代码:
var writer = new StreamWriter(context.Response.Body, Encoding.UTF8);
serialiser.Serialize(writer, output);
writer.Flush();
我应该处理作者还是context.Response.Body
?通常我到处都有 using
语句,但我没有实例化响应流,我模糊地记得有一个约定,处理是实例化 IDisposable 的组件的责任。
不,服务器拥有这些流并将在请求结束时清理它们。
http://owin.org/html/spec/owin-1.0.html
3.4
"The application SHOULD NOT close or dispose the given stream unless it has completely consumed the request body. The stream owner (e.g. the server or middleware) MUST do any necessary cleanup once the application delegate's Task completes."
3.5
"The application SHOULD NOT close or dispose the given stream as middleware may append additional data. The stream owner (e.g. the server or middleware) MUST perform any necessary cleanup once the application delegate's Task completes."
我正在使用 WebApp.Start();
为一个非常简单的自托管端点编写 Owin 中间件要写入响应流,我有以下形式的代码:
var writer = new StreamWriter(context.Response.Body, Encoding.UTF8);
serialiser.Serialize(writer, output);
writer.Flush();
我应该处理作者还是context.Response.Body
?通常我到处都有 using
语句,但我没有实例化响应流,我模糊地记得有一个约定,处理是实例化 IDisposable 的组件的责任。
不,服务器拥有这些流并将在请求结束时清理它们。
http://owin.org/html/spec/owin-1.0.html
3.4 "The application SHOULD NOT close or dispose the given stream unless it has completely consumed the request body. The stream owner (e.g. the server or middleware) MUST do any necessary cleanup once the application delegate's Task completes."
3.5 "The application SHOULD NOT close or dispose the given stream as middleware may append additional data. The stream owner (e.g. the server or middleware) MUST perform any necessary cleanup once the application delegate's Task completes."