mirror of
https://github.com/wallabag/wallabag.git
synced 2025-06-27 16:36:00 +00:00
Define a custom user-agent for wallabag
This commit is contained in:
parent
e90bbaf540
commit
1aa67747bb
4 changed files with 15 additions and 6 deletions
|
@ -31,6 +31,7 @@ services:
|
|||
$supportUrl: '@=service(''craue_config'').get(''wallabag_support_url'')'
|
||||
$fonts: '%wallabag.fonts%'
|
||||
$defaultIgnoreOriginInstanceRules: '%wallabag.default_ignore_origin_instance_rules%'
|
||||
$defaultUserAgent: "%wallabag.user_agent%"
|
||||
|
||||
Wallabag\:
|
||||
resource: '../../src/*'
|
||||
|
@ -206,6 +207,8 @@ services:
|
|||
$config:
|
||||
error_message: '%wallabag.fetching_error_message%'
|
||||
error_message_title: '%wallabag.fetching_error_message_title%'
|
||||
http_client:
|
||||
ua_browser: "%wallabag.user_agent%"
|
||||
$client: '@psr18.wallabag.client'
|
||||
calls:
|
||||
- [ setLogger, [ "@logger" ] ]
|
||||
|
|
|
@ -183,3 +183,4 @@ parameters:
|
|||
- 'text/html'
|
||||
- 'application/vnd.ms-excel'
|
||||
wallabag.resource_dir: "%kernel.project_dir%/web/uploads/import"
|
||||
wallabag.user_agent: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.92 Safari/535.2"
|
||||
|
|
|
@ -14,6 +14,7 @@ class LoginFormAuthenticator
|
|||
public function __construct(
|
||||
private readonly HttpBrowser $browser,
|
||||
AuthenticatorProvider $authenticatorProvider,
|
||||
private readonly string $defaultUserAgent,
|
||||
) {
|
||||
$this->expressionLanguage = new ExpressionLanguage(null, [$authenticatorProvider]);
|
||||
}
|
||||
|
@ -84,6 +85,10 @@ class LoginFormAuthenticator
|
|||
$headers["HTTP_$headerName"] = $headerValue;
|
||||
}
|
||||
|
||||
if (empty($headers['HTTP_user-agent'])) {
|
||||
$headers['HTTP_user-agent'] = $this->defaultUserAgent;
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class LoginFormAuthenticatorTest extends TestCase
|
|||
$requestHtmlFunctionClient = new MockHttpClient([$requestHtmlFunctionResponse]);
|
||||
$authenticatorProvider = new AuthenticatorProvider($requestHtmlFunctionClient);
|
||||
|
||||
$auth = new LoginFormAuthenticator($browser, $authenticatorProvider);
|
||||
$auth = new LoginFormAuthenticator($browser, $authenticatorProvider, 'Wallabag (Symfony HttpClient/5)');
|
||||
|
||||
$res = $auth->login($siteConfig);
|
||||
|
||||
|
@ -68,7 +68,7 @@ class LoginFormAuthenticatorTest extends TestCase
|
|||
$requestHtmlFunctionClient = new MockHttpClient([$requestHtmlFunctionResponse]);
|
||||
$authenticatorProvider = new AuthenticatorProvider($requestHtmlFunctionClient);
|
||||
|
||||
$auth = new LoginFormAuthenticator($browser, $authenticatorProvider);
|
||||
$auth = new LoginFormAuthenticator($browser, $authenticatorProvider, 'Wallabag (Symfony HttpClient/5)');
|
||||
|
||||
$res = $auth->login($siteConfig);
|
||||
|
||||
|
@ -126,7 +126,7 @@ class LoginFormAuthenticatorTest extends TestCase
|
|||
;
|
||||
$authenticatorProvider = new AuthenticatorProvider($requestHtmlFunctionClient);
|
||||
|
||||
$auth = new LoginFormAuthenticator($browser, $authenticatorProvider);
|
||||
$auth = new LoginFormAuthenticator($browser, $authenticatorProvider, 'Wallabag (Symfony HttpClient/5)');
|
||||
|
||||
$res = $auth->login($siteConfig);
|
||||
|
||||
|
@ -151,7 +151,7 @@ class LoginFormAuthenticatorTest extends TestCase
|
|||
$requestHtmlFunctionClient = new MockHttpClient([$requestHtmlFunctionResponse]);
|
||||
$authenticatorProvider = new AuthenticatorProvider($requestHtmlFunctionClient);
|
||||
|
||||
$auth = new LoginFormAuthenticator($browser, $authenticatorProvider);
|
||||
$auth = new LoginFormAuthenticator($browser, $authenticatorProvider, 'Wallabag (Symfony HttpClient/5)');
|
||||
|
||||
$loginRequired = $auth->isLoginRequired($siteConfig, file_get_contents(__DIR__ . '/../fixtures/nextinpact-login.html'));
|
||||
|
||||
|
@ -177,7 +177,7 @@ class LoginFormAuthenticatorTest extends TestCase
|
|||
$requestHtmlFunctionClient = new MockHttpClient([$requestHtmlFunctionResponse]);
|
||||
$authenticatorProvider = new AuthenticatorProvider($requestHtmlFunctionClient);
|
||||
|
||||
$auth = new LoginFormAuthenticator($browser, $authenticatorProvider);
|
||||
$auth = new LoginFormAuthenticator($browser, $authenticatorProvider, 'Wallabag (Symfony HttpClient/5)');
|
||||
|
||||
$loginRequired = $auth->isLoginRequired($siteConfig, file_get_contents(__DIR__ . '/../fixtures/nextinpact-article.html'));
|
||||
|
||||
|
@ -235,7 +235,7 @@ class LoginFormAuthenticatorTest extends TestCase
|
|||
;
|
||||
$authenticatorProvider = new AuthenticatorProvider($requestHtmlFunctionClient);
|
||||
|
||||
$auth = new LoginFormAuthenticator($browser, $authenticatorProvider);
|
||||
$auth = new LoginFormAuthenticator($browser, $authenticatorProvider, 'Wallabag (Symfony HttpClient/5)');
|
||||
|
||||
$res = $auth->login($siteConfig);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue