Skip to content

Send a custom user agent#2

Open
sumit-ql wants to merge 1 commit intomasterfrom
custom-user-agent
Open

Send a custom user agent#2
sumit-ql wants to merge 1 commit intomasterfrom
custom-user-agent

Conversation

@sumit-ql
Copy link
Owner

@sumit-ql sumit-ql commented Jul 19, 2019

Feature request [17]

  1. Added user-agent in DownloadBase class constructor. Updated unit tests accordingly.
  2. Once this approach looks ok, will add the same in 'ChunkedDownload' class as well.

@sumit-ql sumit-ql changed the title Adding user-agent in DownloadBase class constructor. Send a custom user agent Jul 19, 2019
@sumit-ql
Copy link
Owner Author

@mf2199 @sangramql Please review.


def __init__(self, media_url, stream=None,
start=None, end=None, headers=None):
start=None, end=None, user_agent=None, headers=None):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular reason to put user_agent before headers?

Copy link
Owner Author

@sumit-ql sumit-ql Jul 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing as such, i thought of having str argument(user_agent) before a dict(headers) looks good.

"""
method, url, payload, headers = self._prepare_request()
if self.user_agent is not None:
headers[u'User-Agent'] = self.user_agent
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure which way is better, to have the if check here or simply allow headers[u'User-Agent'] have a None value.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not set user_agent as None if api caller doesnt provide user-agent. In that case, user_agent would be 'python-requests/2.18.' which is set by the underlying requests lib.

self, stream=None, end=65536, headers=None, chunks=(),
response_headers=None):
self, stream=None, end=65536, user_agent=None, headers=None,
chunks=(), response_headers=None):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same idea as in the first comment.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as comment in first.

download = download_mod.Download(
EXAMPLE_URL, stream=stream, end=end, headers=headers)
EXAMPLE_URL, stream=stream, end=end, user_agent=user_agent,
headers=headers)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing...

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@sumit-ql
Copy link
Owner Author

@mf2199 @sangramql Can i go for a public PR?

@sumit-ql sumit-ql force-pushed the custom-user-agent branch from 5b9132e to 1e6c468 Compare August 5, 2019 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants