The Free Software Media System - Server Backend & API
Simplify headers use in WSS
VooDooSa6e1b23eb04d
diff --git a/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs b/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.csindex 792615a0f6..957371df62 100644--- a/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs+++ b/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs@@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Http.Extensions;using Microsoft.Extensions.Logging;using Microsoft.Extensions.Primitives;using Microsoft.Net.Http.Headers;+using HeaderNames = MediaBrowser.Common.Net.MoreHeaderNames;using IHttpFile = MediaBrowser.Model.Services.IHttpFile;using IHttpRequest = MediaBrowser.Model.Services.IHttpRequest;using IResponse = MediaBrowser.Model.Services.IResponse;@@ -38,16 +39,9 @@ namespace Emby.Server.Implementations.SocketSharppublic string RawUrl => request.GetEncodedPathAndQuery();public string AbsoluteUri => request.GetDisplayUrl().TrimEnd('/');+ // Header[name] returns "" when undefined- public string XForwardedFor- => StringValues.IsNullOrEmpty(request.Headers["X-Forwarded-For"]) ? null : request.Headers["X-Forwarded-For"].ToString();-- public int? XForwardedPort- => StringValues.IsNullOrEmpty(request.Headers["X-Forwarded-Port"]) ? (int?)null : int.Parse(request.Headers["X-Forwarded-Port"], CultureInfo.InvariantCulture);-- public string XForwardedProtocol => StringValues.IsNullOrEmpty(request.Headers["X-Forwarded-Proto"]) ? null : request.Headers["X-Forwarded-Proto"].ToString();-- public string XRealIp => StringValues.IsNullOrEmpty(request.Headers["X-Real-IP"]) ? null : request.Headers["X-Real-IP"].ToString();+ private string GetHeader(string name) => request.Headers[name].ToString();private string remoteIp;public string RemoteIp@@ -59,13 +53,13 @@ namespace Emby.Server.Implementations.SocketSharpreturn remoteIp;}- var temp = CheckBadChars(XForwardedFor.AsSpan());+ var temp = CheckBadChars(GetHeader(HeaderNames.XForwardedFor).AsSpan());if (temp.Length != 0){return remoteIp = temp.ToString();}- temp = CheckBadChars(XRealIp.AsSpan());+ temp = CheckBadChars(GetHeader(HeaderNames.XRealIP).AsSpan());if (temp.Length != 0){return remoteIp = NormalizeIp(temp).ToString();diff --git a/MediaBrowser.Model/Services/IHttpRequest.cs b/MediaBrowser.Model/Services/IHttpRequest.csindex 50c6076f30..daf91488f0 100644--- a/MediaBrowser.Model/Services/IHttpRequest.cs+++ b/MediaBrowser.Model/Services/IHttpRequest.cs@@ -7,26 +7,6 @@ namespace MediaBrowser.Model.Services/// </summary>string HttpMethod { get; }- /// <summary>- /// The IP Address of the X-Forwarded-For header, null if null or empty- /// </summary>- string XForwardedFor { get; }-- /// <summary>- /// The Port number of the X-Forwarded-Port header, null if null or empty- /// </summary>- int? XForwardedPort { get; }-- /// <summary>- /// The http or https scheme of the X-Forwarded-Proto header, null if null or empty- /// </summary>- string XForwardedProtocol { get; }-- /// <summary>- /// The value of the X-Real-IP header, null if null or empty- /// </summary>- string XRealIp { get; }-/// <summary>/// The value of the Accept HTTP Request Header/// </summary>