|
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | 15 | import uuid |
16 | | -from typing import TYPE_CHECKING, Any, Dict, Optional, Union |
| 16 | +from typing import TYPE_CHECKING, Any, Dict, Optional |
17 | 17 |
|
18 | | -import urllib3 |
19 | 18 | from selenium.webdriver.remote.remote_connection import RemoteConnection |
20 | 19 |
|
21 | 20 | from appium.common.helper import library_version |
|
30 | 29 | class AppiumConnection(RemoteConnection): |
31 | 30 | _proxy_url: Optional[str] |
32 | 31 |
|
33 | | - def __init__( |
34 | | - self, |
35 | | - remote_server_addr: str, |
36 | | - keep_alive: bool = False, |
37 | | - ignore_proxy: Optional[bool] = False, |
38 | | - init_args_for_pool_manager: Union[Dict[str, Any], None] = None, |
39 | | - ): |
40 | | - # Need to call before super().__init__ in order to pass arguments for the pool manager in the super. |
41 | | - self._init_args_for_pool_manager = init_args_for_pool_manager or {} |
42 | | - |
43 | | - super().__init__(remote_server_addr, keep_alive=keep_alive, ignore_proxy=ignore_proxy) |
44 | | - |
45 | | - def _get_connection_manager(self) -> Union[urllib3.PoolManager, urllib3.ProxyManager]: |
46 | | - # https://github.com/SeleniumHQ/selenium/blob/0e0194b0e52a34e7df4b841f1ed74506beea5c3e/py/selenium/webdriver/remote/remote_connection.py#L134 |
47 | | - pool_manager_init_args = {'timeout': self.get_timeout()} |
48 | | - |
49 | | - if self._ca_certs: |
50 | | - pool_manager_init_args['cert_reqs'] = 'CERT_REQUIRED' |
51 | | - pool_manager_init_args['ca_certs'] = self._ca_certs |
52 | | - else: |
53 | | - # This line is necessary to disable certificate verification |
54 | | - pool_manager_init_args['cert_reqs'] = 'CERT_NONE' |
55 | | - |
56 | | - pool_manager_init_args.update(self._init_args_for_pool_manager) |
57 | | - |
58 | | - if self._proxy_url: |
59 | | - if self._proxy_url.lower().startswith('sock'): |
60 | | - from urllib3.contrib.socks import SOCKSProxyManager |
61 | | - |
62 | | - return SOCKSProxyManager(self._proxy_url, **pool_manager_init_args) |
63 | | - if self._identify_http_proxy_auth(): |
64 | | - self._proxy_url, self._basic_proxy_auth = self._separate_http_proxy_auth() |
65 | | - pool_manager_init_args['proxy_headers'] = urllib3.make_headers(proxy_basic_auth=self._basic_proxy_auth) |
66 | | - return urllib3.ProxyManager(self._proxy_url, **pool_manager_init_args) |
67 | | - |
68 | | - return urllib3.PoolManager(**pool_manager_init_args) |
| 32 | + RemoteConnection.user_agent = f'{PREFIX_HEADER}{library_version()} ({RemoteConnection.user_agent})' |
69 | 33 |
|
70 | 34 | @classmethod |
71 | 35 | def get_remote_connection_headers(cls, parsed_url: 'ParseResult', keep_alive: bool = True) -> Dict[str, Any]: |
72 | 36 | """Override get_remote_connection_headers in RemoteConnection""" |
73 | 37 | headers = RemoteConnection.get_remote_connection_headers(parsed_url, keep_alive=keep_alive) |
74 | | - # e.g. appium/0.49 (selenium/3.141.0 (python linux)) |
75 | | - headers['User-Agent'] = f'{PREFIX_HEADER}{library_version()} ({headers["User-Agent"]})' |
76 | 38 | if parsed_url.path.endswith('/session'): |
77 | 39 | # https://github.com/appium/appium-base-driver/pull/400 |
78 | | - headers['X-Idempotency-Key'] = str(uuid.uuid4()) |
| 40 | + RemoteConnection.extra_headers = {'X-Idempotency-Key': str(uuid.uuid4())} |
| 41 | + else: |
| 42 | + RemoteConnection.extra_headers = {} |
79 | 43 |
|
80 | 44 | return headers |
0 commit comments