Skip to content

Conversation

@vad
Copy link
Collaborator

@vad vad commented May 29, 2017

aiohttp doesn't use httplib but asyncio Tcp connection instead. aiohttp is basically an async version of httplib.

This applies the patch to aiohttp without asking, because the user shouldn't be aware of httplib vs aiohttp, which IMHO is an internal detail of our approach.

@vad
Copy link
Collaborator Author

vad commented May 30, 2017

@saily @do3cc looking for feedback

Copy link
Collaborator

@do3cc do3cc left a comment

Choose a reason for hiding this comment

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

After these minor changes, I'd merge this.

# no aiohttp installed
return

from yarl import URL
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is yarl?
If it is from aiohttp, please put it in the try block

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's a requirement of aiohttp

try:
from aiohttp.client import ClientSession
except ImportError:
# no aiohttp installed
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add log message at level info here. If one day aiohttp changes import locations, this code will silently fail without giving a hint as to why it fails. better yet, if you want, don't catch for import errors at all but use pkg_resources to check if the aiohttp package is installed.
Then a changed import in aiohttp will trigger an exception which is even better than a log message.


from yarl import URL

def patch(self, method, url, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am fine with naming the patched method patch, but if you do it, please rename whitelisted above too. It should be consistent.

return self.old_request(method, url, **kwargs)

if not getattr(ClientSession, 'blockage', False):
logger.debug('Monkey patching httplib')
Copy link
Collaborator

Choose a reason for hiding this comment

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

You aren't monkeypatching httplib here. This debug message might be confusing.

def patch(self, method, url, **kwargs):
yurl = URL(url)

if yurl.host not in whitelist:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a log statement when an url passes the whitelist, as above.

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.

3 participants