mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-17 15:46:22 +00:00
update responses
This commit is contained in:
@@ -13,37 +13,31 @@ namespace ServiceStack.Host
|
||||
public void SerializeToStream(IRequest req, object response, Stream responseStream)
|
||||
{
|
||||
var contentType = req.ResponseContentType;
|
||||
var serializer = GetResponseSerializer(contentType);
|
||||
if (serializer == null)
|
||||
throw new NotSupportedException("ContentType not supported: " + contentType);
|
||||
var serializer = GetStreamSerializer(contentType);
|
||||
|
||||
var httpRes = new HttpResponseStreamWrapper(responseStream, req)
|
||||
{
|
||||
Dto = req.Response.Dto
|
||||
};
|
||||
serializer(req, response, httpRes);
|
||||
serializer(response, responseStream);
|
||||
}
|
||||
|
||||
public Action<IRequest, object, IResponse> GetResponseSerializer(string contentType)
|
||||
public Action<object, IResponse> GetResponseSerializer(string contentType)
|
||||
{
|
||||
var serializer = GetStreamSerializer(contentType);
|
||||
if (serializer == null) return null;
|
||||
|
||||
return (httpReq, dto, httpRes) => serializer(httpReq, dto, httpRes.OutputStream);
|
||||
return (dto, httpRes) => serializer(dto, httpRes.OutputStream);
|
||||
}
|
||||
|
||||
public Action<IRequest, object, Stream> GetStreamSerializer(string contentType)
|
||||
public Action<object, Stream> GetStreamSerializer(string contentType)
|
||||
{
|
||||
switch (GetRealContentType(contentType))
|
||||
{
|
||||
case "application/xml":
|
||||
case "text/xml":
|
||||
case "text/xml; charset=utf-8": //"text/xml; charset=utf-8" also matches xml
|
||||
return (r, o, s) => ServiceStackHost.Instance.SerializeToXml(o, s);
|
||||
return (o, s) => ServiceStackHost.Instance.SerializeToXml(o, s);
|
||||
|
||||
case "application/json":
|
||||
case "text/json":
|
||||
return (r, o, s) => ServiceStackHost.Instance.SerializeToJson(o, s);
|
||||
return (o, s) => ServiceStackHost.Instance.SerializeToJson(o, s);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user