Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add User-Agent header when resolving via urllib #663

Merged
merged 2 commits into from
Feb 6, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pex/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def resolve(self, link):
class UrllibContext(Context):
"""Default Python standard library Context."""

USER_AGENT = 'pex/%s' % PEX_VERSION
AndrewLvov marked this conversation as resolved.
Show resolved Hide resolved

def open(self, link):
return urllib_request.urlopen(link.url)
AndrewLvov marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -146,7 +148,7 @@ def content(self, link):
return fp.read().decode(encoding, 'replace')

def resolve(self, link):
request = urllib_request.Request(link.url)
request = urllib_request.Request(link.url, headers={'User-Agent': self.USER_AGENT})
request.get_method = lambda: 'HEAD'
with contextlib.closing(urllib_request.urlopen(request)) as response:
return link.wrap(response.url)
Expand Down