You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
51 lines
1.6 KiB
8 years ago
|
using System;
|
||
|
using System.IO;
|
||
8 years ago
|
using ServiceStack;
|
||
8 years ago
|
|
||
8 years ago
|
namespace Emby.Server.Implementations.Services
|
||
8 years ago
|
{
|
||
8 years ago
|
public class RequestHelper
|
||
8 years ago
|
{
|
||
8 years ago
|
public static Func<Type, Stream, object> GetRequestReader(string contentType)
|
||
8 years ago
|
{
|
||
8 years ago
|
switch (GetContentTypeWithoutEncoding(contentType))
|
||
8 years ago
|
{
|
||
|
case "application/xml":
|
||
|
case "text/xml":
|
||
|
case "text/xml; charset=utf-8": //"text/xml; charset=utf-8" also matches xml
|
||
8 years ago
|
return ServiceStackHost.Instance.DeserializeXml;
|
||
8 years ago
|
|
||
|
case "application/json":
|
||
|
case "text/json":
|
||
8 years ago
|
return ServiceStackHost.Instance.DeserializeJson;
|
||
8 years ago
|
}
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
|
||
8 years ago
|
public static Action<object, Stream> GetResponseWriter(string contentType)
|
||
8 years ago
|
{
|
||
8 years ago
|
switch (GetContentTypeWithoutEncoding(contentType))
|
||
8 years ago
|
{
|
||
|
case "application/xml":
|
||
|
case "text/xml":
|
||
|
case "text/xml; charset=utf-8": //"text/xml; charset=utf-8" also matches xml
|
||
8 years ago
|
return (o, s) => ServiceStackHost.Instance.SerializeToXml(o, s);
|
||
8 years ago
|
|
||
|
case "application/json":
|
||
|
case "text/json":
|
||
8 years ago
|
return (o, s) => ServiceStackHost.Instance.SerializeToJson(o, s);
|
||
8 years ago
|
}
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
|
||
8 years ago
|
private static string GetContentTypeWithoutEncoding(string contentType)
|
||
8 years ago
|
{
|
||
|
return contentType == null
|
||
|
? null
|
||
|
: contentType.Split(';')[0].ToLower().Trim();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|