aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Services/RequestHelper.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2017-02-12 20:07:48 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2017-02-12 20:07:48 -0500
commit0a03d7ad9fe6554b78963445f012464023113614 (patch)
treedb7c353f9759d6d4259ee3fc017b569cba6f383c /Emby.Server.Implementations/Services/RequestHelper.cs
parenta6e7438987ebd0ef2c44940f76e6efd487803e02 (diff)
localization fixes
Diffstat (limited to 'Emby.Server.Implementations/Services/RequestHelper.cs')
-rw-r--r--Emby.Server.Implementations/Services/RequestHelper.cs51
1 files changed, 51 insertions, 0 deletions
diff --git a/Emby.Server.Implementations/Services/RequestHelper.cs b/Emby.Server.Implementations/Services/RequestHelper.cs
new file mode 100644
index 0000000000..8cfc3d0897
--- /dev/null
+++ b/Emby.Server.Implementations/Services/RequestHelper.cs
@@ -0,0 +1,51 @@
+using System;
+using System.IO;
+using ServiceStack;
+
+namespace Emby.Server.Implementations.Services
+{
+ public class RequestHelper
+ {
+ public static Func<Type, Stream, object> GetRequestReader(string contentType)
+ {
+ switch (GetContentTypeWithoutEncoding(contentType))
+ {
+ case "application/xml":
+ case "text/xml":
+ case "text/xml; charset=utf-8": //"text/xml; charset=utf-8" also matches xml
+ return ServiceStackHost.Instance.DeserializeXml;
+
+ case "application/json":
+ case "text/json":
+ return ServiceStackHost.Instance.DeserializeJson;
+ }
+
+ return null;
+ }
+
+ public static Action<object, Stream> GetResponseWriter(string contentType)
+ {
+ switch (GetContentTypeWithoutEncoding(contentType))
+ {
+ case "application/xml":
+ case "text/xml":
+ case "text/xml; charset=utf-8": //"text/xml; charset=utf-8" also matches xml
+ return (o, s) => ServiceStackHost.Instance.SerializeToXml(o, s);
+
+ case "application/json":
+ case "text/json":
+ return (o, s) => ServiceStackHost.Instance.SerializeToJson(o, s);
+ }
+
+ return null;
+ }
+
+ private static string GetContentTypeWithoutEncoding(string contentType)
+ {
+ return contentType == null
+ ? null
+ : contentType.Split(';')[0].ToLower().Trim();
+ }
+
+ }
+} \ No newline at end of file