diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-02-24 15:21:37 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-02-24 15:21:37 -0500 |
| commit | a73eeac6869edc199c4d0915d07b6847d0c95524 (patch) | |
| tree | 378241f264bbd6106ea6e958e5bf346d1f76b86e /Emby.Server.Implementations/Services/RequestHelper.cs | |
| parent | c456490de43082f008dd592345e76cf75db1ad0a (diff) | |
| parent | cd6b7f3bdc5bcbc6c68131cc40b71b68ac1b73a6 (diff) | |
Merge branch 'master' of https://github.com/MediaBrowser/Emby
Diffstat (limited to 'Emby.Server.Implementations/Services/RequestHelper.cs')
| -rw-r--r-- | Emby.Server.Implementations/Services/RequestHelper.cs | 51 |
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 000000000..7538d3102 --- /dev/null +++ b/Emby.Server.Implementations/Services/RequestHelper.cs @@ -0,0 +1,51 @@ +using System; +using System.IO; +using Emby.Server.Implementations.HttpServer; + +namespace Emby.Server.Implementations.Services +{ + public class RequestHelper + { + public static Func<Type, Stream, object> GetRequestReader(HttpListenerHost host, 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 host.DeserializeXml; + + case "application/json": + case "text/json": + return host.DeserializeJson; + } + + return null; + } + + public static Action<object, Stream> GetResponseWriter(HttpListenerHost host, 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 host.SerializeToXml; + + case "application/json": + case "text/json": + return host.SerializeToJson; + } + + return null; + } + + private static string GetContentTypeWithoutEncoding(string contentType) + { + return contentType == null + ? null + : contentType.Split(';')[0].ToLower().Trim(); + } + + } +}
\ No newline at end of file |
