Revert "refactor: add douban httpclient"

This reverts commit 7e4246003d.
This commit is contained in:
cxfksword 2023-09-16 21:45:17 +08:00
parent 04c3ef949e
commit a6cdbce02d
2 changed files with 11 additions and 18 deletions

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using MediaBrowser.Common.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MediaBrowser.Common.Net;
using Jellyfin.Plugin.MetaShark.Api;
using Jellyfin.Plugin.MetaShark.Model;
@ -44,9 +45,12 @@ namespace Jellyfin.Plugin.MetaShark.Controllers
}
HttpResponseMessage response;
var httpClient = this._httpClientFactory.CreateClient("douban");
var httpClient = GetHttpClient();
using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url))
{
requestMessage.Headers.Add("User-Agent", DoubanApi.HTTP_USER_AGENT);
requestMessage.Headers.Add("Referer", DoubanApi.HTTP_REFERER);
response = await httpClient.SendAsync(requestMessage);
}
var stream = await response.Content.ReadAsStreamAsync();
@ -76,5 +80,11 @@ namespace Jellyfin.Plugin.MetaShark.Controllers
var isLogin = await _doubanApi.CheckLoginAsync(CancellationToken.None);
return new ApiResult(isLogin ? 1 : 0, isLogin ? "logined" : "not login");
}
private HttpClient GetHttpClient()
{
var client = _httpClientFactory.CreateClient(NamedClient.Default);
return client;
}
}
}

View File

@ -13,7 +13,6 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MediaBrowser.Controller.Persistence;
using System.Net.Http;
using System.Net;
namespace Jellyfin.Plugin.MetaShark
{
@ -39,22 +38,6 @@ namespace Jellyfin.Plugin.MetaShark
{
return new ImdbApi(ctx.GetRequiredService<ILoggerFactory>());
});
// douban httpclient 忽略 ssl 证书校验
serviceCollection.AddHttpClient("douban", client =>
{
client.DefaultRequestHeaders.Add("User-Agent", DoubanApi.HTTP_USER_AGENT);
client.DefaultRequestHeaders.Add("Referer", DoubanApi.HTTP_REFERER);
}).ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true
};
return handler;
});
}
}
}