Conversation
Updated the construction of the 'User-Agent' header in both Login and Clientlogin classes to use a fallback to config['USER_AGENT'] if user_agent is not provided, ensuring a valid user agent string is always set.
There was a problem hiding this comment.
Pull Request Overview
This PR updates the User-Agent header handling in the Login and Clientlogin classes to add fallback logic that uses the global config's USER_AGENT value when no explicit user agent is provided. However, the implementation introduces code duplication.
- The fallback logic
user_agent or (str(config['USER_AGENT']) if config['USER_AGENT'] is not None else None)is applied twice in each class - The duplication occurs both where the variable is first assigned and again when passed to
get_user_agent()
|
|
||
| headers = { | ||
| 'User-Agent': get_user_agent(user_agent) | ||
| 'User-Agent': get_user_agent(user_agent or (str(config['USER_AGENT']) if config['USER_AGENT'] is not None else None)) |
There was a problem hiding this comment.
The fallback logic user_agent or (str(config['USER_AGENT']) if config['USER_AGENT'] is not None else None) is redundant here. The variable user_agent was already resolved with the same fallback logic on line 215, so this line can be simplified to just get_user_agent(user_agent).
| 'User-Agent': get_user_agent(user_agent or (str(config['USER_AGENT']) if config['USER_AGENT'] is not None else None)) | |
| 'User-Agent': get_user_agent(user_agent) |
|
|
||
| headers = { | ||
| 'User-Agent': get_user_agent(user_agent) | ||
| 'User-Agent': get_user_agent(user_agent or (str(config['USER_AGENT']) if config['USER_AGENT'] is not None else None)) |
There was a problem hiding this comment.
The fallback logic user_agent or (str(config['USER_AGENT']) if config['USER_AGENT'] is not None else None) is redundant here. The variable user_agent was already resolved with the same fallback logic on line 274, so this line can be simplified to just get_user_agent(user_agent).
| 'User-Agent': get_user_agent(user_agent or (str(config['USER_AGENT']) if config['USER_AGENT'] is not None else None)) | |
| 'User-Agent': get_user_agent(user_agent) |
Updated the construction of the 'User-Agent' header in both Login and Clientlogin classes to use a fallback to config['USER_AGENT'] if user_agent is not provided, ensuring a valid user agent string is always set.