aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Services/ServiceHandler.cs
diff options
context:
space:
mode:
authorJoshua M. Boniface <joshua@boniface.me>2020-07-24 12:21:25 -0400
committerGitHub <noreply@github.com>2020-07-24 12:21:25 -0400
commite3db0ac400e7a1a42e7a844a13ab052d26125612 (patch)
treec72dcbc78fab6194731f17cd86ee028a6458d514 /Emby.Server.Implementations/Services/ServiceHandler.cs
parentf5a3cc654fc8646e633489919b4a8b9e7d3c48fe (diff)
parent928bc6c7875c4523ee158aabc0e2ffc46c691383 (diff)
Merge pull request #3657 from Bond-009/readonlyspan
Review usage of string.Substring (part 1)
Diffstat (limited to 'Emby.Server.Implementations/Services/ServiceHandler.cs')
-rw-r--r--Emby.Server.Implementations/Services/ServiceHandler.cs18
1 files changed, 11 insertions, 7 deletions
diff --git a/Emby.Server.Implementations/Services/ServiceHandler.cs b/Emby.Server.Implementations/Services/ServiceHandler.cs
index 3d4e1ca77..c87e418c2 100644
--- a/Emby.Server.Implementations/Services/ServiceHandler.cs
+++ b/Emby.Server.Implementations/Services/ServiceHandler.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
+using System.Net.Mime;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
@@ -45,7 +46,7 @@ namespace Emby.Server.Implementations.Services
var pos = pathInfo.LastIndexOf('.');
if (pos != -1)
{
- var format = pathInfo.Substring(pos + 1);
+ var format = pathInfo.AsSpan().Slice(pos + 1);
contentType = GetFormatContentType(format);
if (contentType != null)
{
@@ -56,15 +57,18 @@ namespace Emby.Server.Implementations.Services
return pathInfo;
}
- private static string GetFormatContentType(string format)
+ private static string GetFormatContentType(ReadOnlySpan<char> format)
{
- // built-in formats
- switch (format)
+ if (format.Equals("json", StringComparison.Ordinal))
{
- case "json": return "application/json";
- case "xml": return "application/xml";
- default: return null;
+ return MediaTypeNames.Application.Json;
}
+ else if (format.Equals("xml", StringComparison.Ordinal))
+ {
+ return MediaTypeNames.Application.Xml;
+ }
+
+ return null;
}
public async Task ProcessRequestAsync(HttpListenerHost httpHost, IRequest httpReq, HttpResponse httpRes, ILogger logger, CancellationToken cancellationToken)