Permalink
Browse files

Fix plex link issue

  • Loading branch information...
hidden4003 committed Jul 16, 2018
1 parent 1bcb919 commit 8e15ab4905f542e490ca043aeba06364d6fdf9f5
Showing with 16 additions and 10 deletions.
  1. +16 −10 Shoko.Server/Plex/PlexHelper.cs
@@ -45,14 +45,7 @@ public class PlexHelper
static PlexHelper()
{
HttpClient.DefaultRequestHeaders.Add("X-Plex-Client-Identifier", ClientIdentifier);
HttpClient.DefaultRequestHeaders.Add("X-Plex-Platform-Version", ServerState.Instance.ApplicationVersion);
HttpClient.DefaultRequestHeaders.Add("X-Plex-Platform", "Shoko Server");
HttpClient.DefaultRequestHeaders.Add("X-Plex-Device-Name", "Shoko Server Sync");
HttpClient.DefaultRequestHeaders.Add("X-Plex-Device", "Shoko");
HttpClient.DefaultRequestHeaders.Add("User-Agent",
$"{Assembly.GetEntryAssembly().GetName().Name} v${Assembly.GetEntryAssembly().GetName().Version}");
HttpClient.Timeout = TimeSpan.FromSeconds(3);
SetupHttpClient(HttpClient, TimeSpan.FromSeconds(3));
}
private PlexHelper(JMMUser user)
@@ -157,6 +150,18 @@ public bool IsAuthenticated
$"&context%5Bdevice%5D%5BplatformVersion%5D={WebUtility.UrlEncode(Environment.OSVersion.VersionString)}" +
$"&context%5Bdevice%5D%5Bversion%5D={WebUtility.UrlEncode(Assembly.GetEntryAssembly().GetName().Version.ToString())}";
private static void SetupHttpClient(HttpClient client, TimeSpan timeout)
{
client.DefaultRequestHeaders.Add("X-Plex-Client-Identifier", ClientIdentifier);
client.DefaultRequestHeaders.Add("X-Plex-Platform-Version", ServerState.Instance.ApplicationVersion);
client.DefaultRequestHeaders.Add("X-Plex-Platform", "Shoko Server");
client.DefaultRequestHeaders.Add("X-Plex-Device-Name", "Shoko Server Sync");
client.DefaultRequestHeaders.Add("X-Plex-Device", "Shoko");
client.DefaultRequestHeaders.Add("User-Agent",
$"{Assembly.GetEntryAssembly().GetName().Name} v${Assembly.GetEntryAssembly().GetName().Version}");
client.Timeout = TimeSpan.FromSeconds(3);
}
private PlexKey GetPlexKey()
{
if (_key != null)
@@ -222,8 +227,9 @@ private string GetPlexToken()
configureRequest?.Invoke(req);
HttpClient.Timeout = TimeSpan.FromSeconds(60);
var resp = await HttpClient.SendAsync(req).ConfigureAwait(false);
var client = new HttpClient();
SetupHttpClient(client, TimeSpan.FromSeconds(60));
var resp = await client.SendAsync(req).ConfigureAwait(false);
Logger.Trace($"Got response: {resp.StatusCode}");
return (resp.StatusCode, await resp.Content.ReadAsStringAsync().ConfigureAwait(false));
}

0 comments on commit 8e15ab4

Please sign in to comment.