mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-16 02:18:54 -07:00
fixed dlna headers
This commit is contained in:
parent
f0f897e97e
commit
f2261a669e
@ -105,48 +105,12 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||
return client;
|
||||
}
|
||||
|
||||
private WebRequest GetMonoRequest(HttpRequestOptions options, string method, bool enableHttpCompression)
|
||||
{
|
||||
var request = (HttpWebRequest)WebRequest.Create(options.Url);
|
||||
|
||||
if (!string.IsNullOrEmpty(options.AcceptHeader))
|
||||
{
|
||||
request.Accept = options.AcceptHeader;
|
||||
}
|
||||
|
||||
request.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None;
|
||||
|
||||
request.CachePolicy = options.CachePolicy == Net.HttpRequestCachePolicy.None ?
|
||||
new RequestCachePolicy(RequestCacheLevel.BypassCache) :
|
||||
new RequestCachePolicy(RequestCacheLevel.Revalidate);
|
||||
|
||||
request.ConnectionGroupName = GetHostFromUrl(options.Url);
|
||||
request.KeepAlive = true;
|
||||
request.Method = method;
|
||||
request.Pipelined = true;
|
||||
request.Timeout = 20000;
|
||||
|
||||
if (!string.IsNullOrEmpty(options.UserAgent))
|
||||
{
|
||||
request.UserAgent = options.UserAgent;
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
private PropertyInfo _httpBehaviorPropertyInfo;
|
||||
private WebRequest GetRequest(HttpRequestOptions options, string method, bool enableHttpCompression)
|
||||
{
|
||||
#if __MonoCS__
|
||||
return GetMonoRequest(options, method, enableHttpCompression);
|
||||
#endif
|
||||
var request = (HttpWebRequest)WebRequest.Create(options.Url);
|
||||
|
||||
var request = HttpWebRequest.CreateHttp(options.Url);
|
||||
|
||||
if (!string.IsNullOrEmpty(options.AcceptHeader))
|
||||
{
|
||||
request.Accept = options.AcceptHeader;
|
||||
}
|
||||
AddRequestHeaders(request, options);
|
||||
|
||||
request.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None;
|
||||
|
||||
@ -160,11 +124,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||
request.Pipelined = true;
|
||||
request.Timeout = 20000;
|
||||
|
||||
if (!string.IsNullOrEmpty(options.UserAgent))
|
||||
{
|
||||
request.UserAgent = options.UserAgent;
|
||||
}
|
||||
|
||||
#if !__MonoCS__
|
||||
// This is a hack to prevent KeepAlive from getting disabled internally by the HttpWebRequest
|
||||
// May need to remove this for mono
|
||||
var sp = request.ServicePoint;
|
||||
@ -173,10 +133,30 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||
_httpBehaviorPropertyInfo = sp.GetType().GetProperty("HttpBehaviour", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
}
|
||||
_httpBehaviorPropertyInfo.SetValue(sp, (byte)0, null);
|
||||
#endif
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
private void AddRequestHeaders(HttpWebRequest request, HttpRequestOptions options)
|
||||
{
|
||||
foreach (var header in options.RequestHeaders.ToList())
|
||||
{
|
||||
if (string.Equals(header.Key, "Accept", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
request.Accept = header.Value;
|
||||
}
|
||||
else if (string.Equals(header.Key, "User-Agent", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
request.UserAgent = header.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
request.Headers.Set(header.Key, header.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the response internal.
|
||||
/// </summary>
|
||||
|
@ -357,6 +357,9 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
return;
|
||||
|
||||
((Timer)sender).Stop();
|
||||
|
||||
try
|
||||
{
|
||||
var hasTrack = await GetPositionInfo().ConfigureAwait(false);
|
||||
|
||||
// TODO: Why make these requests if hasTrack==false?
|
||||
@ -370,6 +373,11 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
await GetVolume().ConfigureAwait(false);
|
||||
_count = 0;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error updating device info", ex);
|
||||
}
|
||||
|
||||
_count++;
|
||||
if (_disposed)
|
||||
@ -390,18 +398,8 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
throw new InvalidOperationException("Unable to find service");
|
||||
}
|
||||
|
||||
XDocument result;
|
||||
|
||||
try
|
||||
{
|
||||
result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType))
|
||||
var result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error getting volume info", ex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == null || result.Document == null)
|
||||
return;
|
||||
@ -431,18 +429,8 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
if (service == null)
|
||||
return;
|
||||
|
||||
XDocument result;
|
||||
|
||||
try
|
||||
{
|
||||
result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType))
|
||||
var result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error getting transport info", ex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == null || result.Document == null)
|
||||
return;
|
||||
@ -471,18 +459,8 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
throw new InvalidOperationException("Unable to find service");
|
||||
}
|
||||
|
||||
XDocument result;
|
||||
|
||||
try
|
||||
{
|
||||
result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType))
|
||||
var result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error getting media info", ex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == null || result.Document == null)
|
||||
return;
|
||||
@ -522,18 +500,8 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
throw new InvalidOperationException("Unable to find service");
|
||||
}
|
||||
|
||||
XDocument result;
|
||||
|
||||
try
|
||||
{
|
||||
result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType))
|
||||
var result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, RendererCommands.BuildPost(command, service.ServiceType))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error getting position info", ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result == null || result.Document == null)
|
||||
return true;
|
||||
|
@ -23,15 +23,15 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISessionManager _sessionManager;
|
||||
private readonly IHttpClient _httpClient;
|
||||
private User _defualtUser;
|
||||
private readonly CancellationTokenSource _tokenSource;
|
||||
private ConcurrentDictionary<string, DateTime> _locations;
|
||||
|
||||
private readonly IItemRepository _itemRepository;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly INetworkManager _networkManager;
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
public PlayToManager(ILogger logger, ISessionManager sessionManager, IHttpClient httpClient, IItemRepository itemRepository, ILibraryManager libraryManager, INetworkManager networkManager)
|
||||
public PlayToManager(ILogger logger, ISessionManager sessionManager, IHttpClient httpClient, IItemRepository itemRepository, ILibraryManager libraryManager, INetworkManager networkManager, IUserManager userManager)
|
||||
{
|
||||
_locations = new ConcurrentDictionary<string, DateTime>();
|
||||
_tokenSource = new CancellationTokenSource();
|
||||
@ -42,11 +42,11 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
_itemRepository = itemRepository;
|
||||
_libraryManager = libraryManager;
|
||||
_networkManager = networkManager;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
public async void Start(User defaultUser)
|
||||
public async void Start()
|
||||
{
|
||||
_defualtUser = defaultUser;
|
||||
_logger.Log(LogSeverity.Info, "PlayTo-Manager starting");
|
||||
|
||||
_locations = new ConcurrentDictionary<string, DateTime>();
|
||||
@ -216,7 +216,7 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
{
|
||||
var transcodeProfiles = TranscodeSettings.GetProfileSettings(device.Properties);
|
||||
|
||||
var sessionInfo = await _sessionManager.LogSessionActivity(device.Properties.ClientType, device.Properties.Name, device.Properties.UUID, device.Properties.DisplayName, uri.OriginalString, _defualtUser)
|
||||
var sessionInfo = await _sessionManager.LogSessionActivity(device.Properties.ClientType, device.Properties.Name, device.Properties.UUID, device.Properties.DisplayName, uri.OriginalString, null)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var controller = sessionInfo.SessionController as PlayToController;
|
||||
@ -232,6 +232,23 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
}
|
||||
}
|
||||
|
||||
const string DefaultUser = "Play To";
|
||||
private async Task<User> GetPlayToUser()
|
||||
{
|
||||
var user = _userManager.Users.FirstOrDefault(u => string.Equals(DefaultUser, u.Name, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
user = await _userManager.CreateUser(DefaultUser);
|
||||
|
||||
user.Configuration.IsHidden = true;
|
||||
user.Configuration.IsAdministrator = false;
|
||||
user.SaveConfiguration();
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the Uri is valid for further inspection or not.
|
||||
/// (the limit for reinspection is 5 minutes)
|
||||
|
@ -1,55 +1,26 @@
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Controller.Plugins;
|
||||
using MediaBrowser.Controller.Session;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Dlna.PlayTo
|
||||
{
|
||||
public class PlayToServerEntryPoint : IServerEntryPoint
|
||||
{
|
||||
const string DefaultUser = "Play To";
|
||||
|
||||
private bool _disposed;
|
||||
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly PlayToManager _manager;
|
||||
|
||||
public PlayToServerEntryPoint(ILogManager logManager, ISessionManager sessionManager, IUserManager userManager, IHttpClient httpClient, INetworkManager networkManager, IItemRepository itemRepository, ILibraryManager libraryManager)
|
||||
{
|
||||
_userManager = userManager;
|
||||
|
||||
_manager = new PlayToManager(logManager.GetLogger("PlayTo"), sessionManager, httpClient, itemRepository, libraryManager, networkManager);
|
||||
_manager = new PlayToManager(logManager.GetLogger("PlayTo"), sessionManager, httpClient, itemRepository, libraryManager, networkManager, userManager);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the defaultuser if needed.
|
||||
/// </summary>
|
||||
private async Task<User> CreateUserIfNeeded()
|
||||
public void Run()
|
||||
{
|
||||
var user = _userManager.Users.FirstOrDefault(u => u.Name == DefaultUser);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
user = await _userManager.CreateUser(DefaultUser);
|
||||
|
||||
user.Configuration.IsHidden = true;
|
||||
user.Configuration.IsAdministrator = false;
|
||||
user.SaveConfiguration();
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public async void Run()
|
||||
{
|
||||
//var defaultUser = await CreateUserIfNeeded().ConfigureAwait(false);
|
||||
|
||||
//_manager.Start(defaultUser);
|
||||
//_manager.Start();
|
||||
}
|
||||
|
||||
#region Dispose
|
||||
|
@ -44,10 +44,10 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
{
|
||||
var options = new HttpRequestOptions
|
||||
{
|
||||
Url = url.ToString()
|
||||
Url = url.ToString(),
|
||||
UserAgent = USERAGENT
|
||||
};
|
||||
|
||||
options.RequestHeaders["UserAgent"] = USERAGENT;
|
||||
options.RequestHeaders["HOST"] = ip + ":" + port;
|
||||
options.RequestHeaders["CALLBACK"] = "<" + localIp + ":" + eventport + ">";
|
||||
options.RequestHeaders["NT"] = "upnp:event";
|
||||
@ -63,10 +63,10 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
{
|
||||
var options = new HttpRequestOptions
|
||||
{
|
||||
Url = url.ToString()
|
||||
Url = url.ToString(),
|
||||
UserAgent = USERAGENT
|
||||
};
|
||||
|
||||
options.RequestHeaders["UserAgent"] = USERAGENT;
|
||||
options.RequestHeaders["HOST"] = ip + ":" + port;
|
||||
options.RequestHeaders["CALLBACK"] = "<" + localIp + ":" + eventport + ">";
|
||||
options.RequestHeaders["NT"] = "upnp:event";
|
||||
@ -82,10 +82,10 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
{
|
||||
var options = new HttpRequestOptions
|
||||
{
|
||||
Url = url.ToString()
|
||||
Url = url.ToString(),
|
||||
UserAgent = USERAGENT
|
||||
};
|
||||
|
||||
options.RequestHeaders["UserAgent"] = USERAGENT;
|
||||
options.RequestHeaders["FriendlyName.DLNA.ORG"] = FriendlyName;
|
||||
//request.CookieContainer = Container;
|
||||
|
||||
@ -105,12 +105,12 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
|
||||
var options = new HttpRequestOptions
|
||||
{
|
||||
Url = url.ToString()
|
||||
Url = url.ToString(),
|
||||
UserAgent = USERAGENT
|
||||
};
|
||||
|
||||
options.RequestHeaders["SOAPAction"] = soapAction;
|
||||
options.RequestHeaders["Pragma"] = "no-cache";
|
||||
options.RequestHeaders["UserAgent"] = USERAGENT;
|
||||
options.RequestHeaders["FriendlyName.DLNA.ORG"] = FriendlyName;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(header))
|
||||
|
Loading…
Reference in New Issue
Block a user