我正在尝试通过 hello world 示例和自托管示例来学习 ServiceStack。我正在请求 JSON 内容。
我在响应标头中注意到以下内容:
ASP.Net 项目中托管的基本服务:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Wed, 10 Apr 2013 12:49:46 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ServiceStack/3.943 Win32NT/.NET
Cache-Control: private
Content-Type: application/json; charset=utf-8
Content-Length: 16 <-------------------------------------
Connection: Close
相同的基本服务,自托管(命令行):
HTTP/1.1 200 OK
Transfer-Encoding: chunked <-------------------------------
Content-Type: application/json; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
X-Powered-By: ServiceStack/3.943 Win32NT/.NET
Date: Wed, 10 Apr 2013 12:48:50 GMT
看来自托管品种不会缓冲它的响应?这是性能或兼容性问题吗?
使用自托管方式时如何开启缓冲?
非常感谢。
使用自托管方式时如何开启缓冲?
您可以创建一个如下所示的 ResponseFilter 。我想说这有点激进,它会阻止其他 ResponseFilter 运行。你可以把它变成一个过滤属性 https://github.com/ServiceStack/ServiceStack/wiki/Filter-attributes并且仅当响应具有明显的性能优势时才使用它。否则,我会让 AppHost 处理响应。
ResponseFilters.Add((httpReq, httpRes, dto) =>
{
using (var ms = new MemoryStream())
{
EndpointHost.ContentTypeFilter.SerializeToStream(
new SerializationContext(httpReq.ResponseContentType), dto, ms);
var bytes = ms.ToArray();
var listenerResponse = (HttpListenerResponse)httpRes.OriginalResponse;
listenerResponse.SendChunked = false;
listenerResponse.ContentLength64 = bytes.Length;
listenerResponse.OutputStream.Write(bytes, 0, bytes.Length);
httpRes.EndServiceStackRequest();
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)