write a simple wrapper of symfony http client;force the client to use ipv4

This commit is contained in:
huangjx
2022-02-27 12:08:33 +08:00
parent 963334dee5
commit f9169240de
2 changed files with 61 additions and 9 deletions

View File

@@ -9,13 +9,13 @@ use OCA\NCDownloader\Search\Sites\bitSearch;
use OCA\NCDownloader\Search\Sites\sliderkz;
use OCA\NCDownloader\Search\Sites\TPB;
use OCA\NCDownloader\Tools\Aria2;
use OCA\NCDownloader\Tools\Client;
use OCA\NCDownloader\Tools\Helper;
use OCA\NCDownloader\Tools\Settings;
use OCA\NCDownloader\Tools\Youtube;
use OCP\AppFramework\App;
use OCP\IContainer;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\HttpClient\HttpClient;
class Application extends App
{
@@ -82,17 +82,15 @@ class Application extends App
$container->query('Youtube')
);
});
$container->registerService('httpClient', function () {
$options = [
'ipv4' => true,
];
return Client::create($options);
});
$container->registerService('crawler', function () {
return new Crawler();
});
$container->registerService('httpClient', function () {
$agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36';
return HttpClient::create([
'headers' => [
'User-Agent' => $agent,
],
]);
});
$container->registerService(TPB::class, function (IContainer $container) {
$crawler = $container->query('crawler');
$client = $container->query('httpClient');