mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-04 03:27:21 -05:00 
			
		
		
		
	
						commit
						0ef30db4e8
					
				@ -140,7 +140,17 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
 | 
			
		||||
 | 
			
		||||
        private WebRequest GetRequest(HttpRequestOptions options, string method)
 | 
			
		||||
        {
 | 
			
		||||
            var request = CreateWebRequest(options.Url);
 | 
			
		||||
            var url = options.Url;
 | 
			
		||||
 | 
			
		||||
            var uriAddress = new Uri(url);
 | 
			
		||||
            var userInfo = uriAddress.UserInfo;
 | 
			
		||||
            if (!string.IsNullOrWhiteSpace(userInfo))
 | 
			
		||||
            {
 | 
			
		||||
                _logger.Info("Found userInfo in url: {0} ... url: {1}", userInfo, url);
 | 
			
		||||
                url = url.Replace(userInfo + "@", string.Empty);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var request = CreateWebRequest(url);
 | 
			
		||||
            var httpWebRequest = request as HttpWebRequest;
 | 
			
		||||
 | 
			
		||||
            if (httpWebRequest != null)
 | 
			
		||||
@ -183,9 +193,27 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!string.IsNullOrWhiteSpace(userInfo))
 | 
			
		||||
            {
 | 
			
		||||
                var parts = userInfo.Split(':');
 | 
			
		||||
                if (parts.Length == 2)
 | 
			
		||||
                {
 | 
			
		||||
                    request.Credentials = GetCredential(url, parts[0], parts[1]);
 | 
			
		||||
                    request.PreAuthenticate = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return request;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private CredentialCache GetCredential(string url, string username, string password)
 | 
			
		||||
        {
 | 
			
		||||
            //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
 | 
			
		||||
            CredentialCache credentialCache = new CredentialCache();
 | 
			
		||||
            credentialCache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
 | 
			
		||||
            return credentialCache;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void AddRequestHeaders(HttpWebRequest request, HttpRequestOptions options)
 | 
			
		||||
        {
 | 
			
		||||
            foreach (var header in options.RequestHeaders.ToList())
 | 
			
		||||
 | 
			
		||||
@ -72,7 +72,10 @@ namespace MediaBrowser.Providers.MediaInfo
 | 
			
		||||
                    // Try to translate to three character code
 | 
			
		||||
                    // Be flexible and check against both the full and three character versions
 | 
			
		||||
                    var culture = _localization.GetCultures()
 | 
			
		||||
                        .FirstOrDefault(i => string.Equals(i.DisplayName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Name, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.ThreeLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.TwoLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase));
 | 
			
		||||
                        .FirstOrDefault(i => string.Equals(i.DisplayName, language, StringComparison.OrdinalIgnoreCase) || 
 | 
			
		||||
                        string.Equals(i.Name, language, StringComparison.OrdinalIgnoreCase) || 
 | 
			
		||||
                        string.Equals(i.ThreeLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase) || 
 | 
			
		||||
                        string.Equals(i.TwoLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase));
 | 
			
		||||
 | 
			
		||||
                    if (culture != null)
 | 
			
		||||
                    {
 | 
			
		||||
@ -99,10 +102,12 @@ namespace MediaBrowser.Providers.MediaInfo
 | 
			
		||||
        private string NormalizeFilenameForSubtitleComparison(string filename)
 | 
			
		||||
        {
 | 
			
		||||
            // Try to account for sloppy file naming
 | 
			
		||||
            filename = filename.Replace("-", string.Empty);
 | 
			
		||||
            filename = filename.Replace("_", string.Empty);
 | 
			
		||||
            filename = filename.Replace(" ", string.Empty);
 | 
			
		||||
 | 
			
		||||
            // can't normalize this due to languages such as pt-br
 | 
			
		||||
            //filename = filename.Replace("-", string.Empty);
 | 
			
		||||
 | 
			
		||||
            //filename = filename.Replace(".", string.Empty);
 | 
			
		||||
 | 
			
		||||
            return filename;
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,7 @@ using System.Collections.Specialized;
 | 
			
		||||
using System.Globalization;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Web;
 | 
			
		||||
using ServiceStack;
 | 
			
		||||
using ServiceStack.Web;
 | 
			
		||||
@ -32,19 +33,20 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
 | 
			
		||||
            return header.Substring(ap + 1, end - ap - 1);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void LoadMultiPart()
 | 
			
		||||
        async Task LoadMultiPart()
 | 
			
		||||
        {
 | 
			
		||||
            string boundary = GetParameter(ContentType, "; boundary=");
 | 
			
		||||
            if (boundary == null)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            var input = GetSubStream(InputStream);
 | 
			
		||||
 | 
			
		||||
            using (var requestStream = GetSubStream(InputStream))
 | 
			
		||||
            {
 | 
			
		||||
                //DB: 30/01/11 - Hack to get around non-seekable stream and received HTTP request
 | 
			
		||||
                //Not ending with \r\n?
 | 
			
		||||
                var ms = new MemoryStream(32 * 1024);
 | 
			
		||||
            input.CopyTo(ms);
 | 
			
		||||
            input = ms;
 | 
			
		||||
                await requestStream.CopyToAsync(ms).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
                var input = ms;
 | 
			
		||||
                ms.WriteByte((byte)'\r');
 | 
			
		||||
                ms.WriteByte((byte)'\n');
 | 
			
		||||
 | 
			
		||||
@ -78,7 +80,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
 | 
			
		||||
                        files.AddFile(e.Name, sub);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            EndSubStream(input);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public NameValueCollection Form
 | 
			
		||||
@ -91,10 +93,15 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
 | 
			
		||||
                    files = new HttpFileCollection();
 | 
			
		||||
 | 
			
		||||
                    if (IsContentType("multipart/form-data", true))
 | 
			
		||||
                        LoadMultiPart();
 | 
			
		||||
                    else if (
 | 
			
		||||
                        IsContentType("application/x-www-form-urlencoded", true))
 | 
			
		||||
                        LoadWwwForm();
 | 
			
		||||
                    {
 | 
			
		||||
                        var task = LoadMultiPart();
 | 
			
		||||
                        Task.WaitAll(task);
 | 
			
		||||
                    }
 | 
			
		||||
                    else if (IsContentType("application/x-www-form-urlencoded", true))
 | 
			
		||||
                    {
 | 
			
		||||
                        var task = LoadWwwForm();
 | 
			
		||||
                        Task.WaitAll(task);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    form.Protect();
 | 
			
		||||
                }
 | 
			
		||||
@ -220,15 +227,16 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
 | 
			
		||||
            return String.Compare(ContentType, ct, true, Helpers.InvariantCulture) == 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        void LoadWwwForm()
 | 
			
		||||
        async Task LoadWwwForm()
 | 
			
		||||
        {
 | 
			
		||||
            using (Stream input = GetSubStream(InputStream))
 | 
			
		||||
            {
 | 
			
		||||
                using (StreamReader s = new StreamReader(input, ContentEncoding))
 | 
			
		||||
                using (var ms = new MemoryStream())
 | 
			
		||||
                {
 | 
			
		||||
                    await input.CopyToAsync(ms).ConfigureAwait(false);
 | 
			
		||||
                    ms.Position = 0;
 | 
			
		||||
 | 
			
		||||
                    using (StreamReader s = new StreamReader(ms, ContentEncoding))
 | 
			
		||||
                    {
 | 
			
		||||
                        StringBuilder key = new StringBuilder();
 | 
			
		||||
                        StringBuilder value = new StringBuilder();
 | 
			
		||||
@ -262,8 +270,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
 | 
			
		||||
                        }
 | 
			
		||||
                        if (c == -1)
 | 
			
		||||
                            AddRawKeyValue(key, value);
 | 
			
		||||
 | 
			
		||||
                    EndSubStream(input);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -465,10 +465,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
 | 
			
		||||
            return stream;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        static void EndSubStream(Stream stream)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static string GetHandlerPathIfAny(string listenerUrl)
 | 
			
		||||
        {
 | 
			
		||||
            if (listenerUrl == null) return null;
 | 
			
		||||
 | 
			
		||||
@ -73,8 +73,8 @@
 | 
			
		||||
      <HintPath>..\packages\SimpleInjector.3.2.0\lib\net45\SimpleInjector.dll</HintPath>
 | 
			
		||||
      <Private>True</Private>
 | 
			
		||||
    </Reference>
 | 
			
		||||
    <Reference Include="SocketHttpListener, Version=1.0.6039.31236, Culture=neutral, processorArchitecture=MSIL">
 | 
			
		||||
      <HintPath>..\packages\SocketHttpListener.1.0.0.33\lib\net45\SocketHttpListener.dll</HintPath>
 | 
			
		||||
    <Reference Include="SocketHttpListener, Version=1.0.6046.26351, Culture=neutral, processorArchitecture=MSIL">
 | 
			
		||||
      <HintPath>..\packages\SocketHttpListener.1.0.0.35\lib\net45\SocketHttpListener.dll</HintPath>
 | 
			
		||||
      <Private>True</Private>
 | 
			
		||||
    </Reference>
 | 
			
		||||
    <Reference Include="System" />
 | 
			
		||||
 | 
			
		||||
@ -9,5 +9,5 @@
 | 
			
		||||
  <package id="morelinq" version="1.4.0" targetFramework="net45" />
 | 
			
		||||
  <package id="Patterns.Logging" version="1.0.0.2" targetFramework="net45" />
 | 
			
		||||
  <package id="SimpleInjector" version="3.2.0" targetFramework="net45" />
 | 
			
		||||
  <package id="SocketHttpListener" version="1.0.0.33" targetFramework="net45" />
 | 
			
		||||
  <package id="SocketHttpListener" version="1.0.0.35" targetFramework="net45" />
 | 
			
		||||
</packages>
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user