Skip to content

Commit d497af8

Browse files
committed
correct headers
1 parent 9a2cbbc commit d497af8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

appium/webdriver/appium_connection.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,22 @@ class AppiumConnection(RemoteConnection):
3939
- https://github.com/appium/appium-base-driver/pull/400
4040
"""
4141

42-
RemoteConnection.user_agent = f'{PREFIX_HEADER}{library_version()} ({RemoteConnection.user_agent})'
42+
user_agent = f'{PREFIX_HEADER}{library_version()} ({RemoteConnection.user_agent})'
4343

4444
@classmethod
4545
def get_remote_connection_headers(cls, parsed_url: 'ParseResult', keep_alive: bool = True) -> Dict[str, Any]:
4646
"""Override get_remote_connection_headers in RemoteConnection to control the extra headers.
4747
This method will be used in sending a request method in this class.
4848
"""
49-
headers = RemoteConnection.get_remote_connection_headers(parsed_url, keep_alive=keep_alive)
49+
5050
if parsed_url.path.endswith('/session'):
5151
# https://github.com/appium/appium-base-driver/pull/400
52-
RemoteConnection.extra_headers = {_HEADER_IDEMOTENCY_KEY: str(uuid.uuid4())}
53-
elif _HEADER_IDEMOTENCY_KEY in RemoteConnection.extra_headers:
54-
del RemoteConnection.extra_headers[_HEADER_IDEMOTENCY_KEY]
55-
56-
return headers
52+
if cls.extra_headers is None:
53+
cls.extra_headers = {_HEADER_IDEMOTENCY_KEY: str(uuid.uuid4())}
54+
else:
55+
cls.extra_headers[_HEADER_IDEMOTENCY_KEY] = str(uuid.uuid4())
56+
elif cls.extra_headers is not None and _HEADER_IDEMOTENCY_KEY in cls.extra_headers:
57+
del cls.extra_headers[_HEADER_IDEMOTENCY_KEY]
58+
59+
base_headers = super().get_remote_connection_headers(parsed_url, keep_alive=keep_alive)
60+
return base_headers if cls.extra_headers is None else {**base_headers, **cls.extra_headers}

0 commit comments

Comments
 (0)