mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-04 03:27:21 -05:00 
			
		
		
		
	Simplify headers use in WSS
This commit is contained in:
		
							parent
							
								
									5f6ab836de
								
							
						
					
					
						commit
						a6e1b23eb0
					
				@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Http.Extensions;
 | 
				
			|||||||
using Microsoft.Extensions.Logging;
 | 
					using Microsoft.Extensions.Logging;
 | 
				
			||||||
using Microsoft.Extensions.Primitives;
 | 
					using Microsoft.Extensions.Primitives;
 | 
				
			||||||
using Microsoft.Net.Http.Headers;
 | 
					using Microsoft.Net.Http.Headers;
 | 
				
			||||||
 | 
					using HeaderNames = MediaBrowser.Common.Net.MoreHeaderNames;
 | 
				
			||||||
using IHttpFile = MediaBrowser.Model.Services.IHttpFile;
 | 
					using IHttpFile = MediaBrowser.Model.Services.IHttpFile;
 | 
				
			||||||
using IHttpRequest = MediaBrowser.Model.Services.IHttpRequest;
 | 
					using IHttpRequest = MediaBrowser.Model.Services.IHttpRequest;
 | 
				
			||||||
using IResponse = MediaBrowser.Model.Services.IResponse;
 | 
					using IResponse = MediaBrowser.Model.Services.IResponse;
 | 
				
			||||||
@ -38,16 +39,9 @@ namespace Emby.Server.Implementations.SocketSharp
 | 
				
			|||||||
        public string RawUrl => request.GetEncodedPathAndQuery();
 | 
					        public string RawUrl => request.GetEncodedPathAndQuery();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public string AbsoluteUri => request.GetDisplayUrl().TrimEnd('/');
 | 
					        public string AbsoluteUri => request.GetDisplayUrl().TrimEnd('/');
 | 
				
			||||||
 | 
					        // Header[name] returns "" when undefined
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public string XForwardedFor
 | 
					        private string GetHeader(string name) => request.Headers[name].ToString();
 | 
				
			||||||
            => 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 remoteIp;
 | 
					        private string remoteIp;
 | 
				
			||||||
        public string RemoteIp
 | 
					        public string RemoteIp
 | 
				
			||||||
@ -59,13 +53,13 @@ namespace Emby.Server.Implementations.SocketSharp
 | 
				
			|||||||
                    return remoteIp;
 | 
					                    return remoteIp;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                var temp = CheckBadChars(XForwardedFor.AsSpan());
 | 
					                var temp = CheckBadChars(GetHeader(HeaderNames.XForwardedFor).AsSpan());
 | 
				
			||||||
                if (temp.Length != 0)
 | 
					                if (temp.Length != 0)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    return remoteIp = temp.ToString();
 | 
					                    return remoteIp = temp.ToString();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                temp = CheckBadChars(XRealIp.AsSpan());
 | 
					                temp = CheckBadChars(GetHeader(HeaderNames.XRealIP).AsSpan());
 | 
				
			||||||
                if (temp.Length != 0)
 | 
					                if (temp.Length != 0)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    return remoteIp = NormalizeIp(temp).ToString();
 | 
					                    return remoteIp = NormalizeIp(temp).ToString();
 | 
				
			||||||
 | 
				
			|||||||
@ -7,26 +7,6 @@ namespace MediaBrowser.Model.Services
 | 
				
			|||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        string HttpMethod { get; }
 | 
					        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>
 | 
					        /// <summary>
 | 
				
			||||||
        /// The value of the Accept HTTP Request Header
 | 
					        /// The value of the Accept HTTP Request Header
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user