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

Ssl ip address error fix #46

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def reqs(f):

# -*- Tests Requires -*-

tests_require = reqs('test.txt') + reqs('test_django.txt')
tests_require = ""#reqs('test.txt') + reqs('test_django.txt')

# -*- Long Description -*-

Expand Down
7 changes: 7 additions & 0 deletions thorn/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Settings(object):
default_signal_honors_transaction = False
default_hmac_signer = 'thorn.utils.hmac:compat_sign'
default_allow_redirects = False
default_raise_http_error = False

def __init__(self, app=None):
self.app = app_or_default(app or self.app)
Expand Down Expand Up @@ -107,6 +108,12 @@ def THORN_ALLOW_REDIRECTS(self):
return self._get(
'THORN_ALLOW_REDIRECTS', self.default_allow_redirects)

@cached_property
def THORN_RAISE_HTTP_ERROR(self):
# type: () -> bool
return self._get(
'THORN_RAISE_HTTP_ERROR', self.default_raise_http_error)

def _get(self, key, default=None):
# type: (str, Any) -> Any
return self._get_lazy(key, lambda: default)
Expand Down
1 change: 0 additions & 1 deletion thorn/dispatch/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

__all__ = ['Dispatcher', 'WorkerDispatcher']


class _CeleryDispatcher(base.Dispatcher):

def as_request_group(self, requests):
Expand Down
48 changes: 35 additions & 13 deletions thorn/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from celery import uuid
from celery.utils import cached_property
from requests.exceptions import ConnectionError, Timeout
from requests.exceptions import ConnectionError, HTTPError, Timeout
from requests.packages.urllib3.util.url import Url, parse_url
from vine import maybe_promise, promise
from vine.abstract import Thenable, ThenableProxy
Expand Down Expand Up @@ -127,6 +127,9 @@ def __init__(self, event, data, sender, subscriber,
))
if user_agent:
self.user_agent = user_agent
self.raise_http_error = self.app.settings.THORN_RAISE_HTTP_ERROR
if self.raise_http_error:
self.connection_errors = (ConnectionError, HTTPError)

def validate_recipient(self, url):
# type: (str) -> None
Expand All @@ -142,6 +145,8 @@ def dispatch(self, session=None, propagate=False):
self.validate_recipient(self.subscriber.url)
with self._finalize_unless_request_error(propagate):
self.response = self.post(session=session)
if self.raise_http_error:
self.response.raise_for_status()
return self

@contextmanager
Expand Down Expand Up @@ -198,18 +203,35 @@ def post(self, session=None):
host, url = self.to_safeurl(self.subscriber.url)

with self.session_or_acquire(session) as session:
return session.post(
url=url,
data=self.data,
allow_redirects=self.allow_redirects,
timeout=self.timeout,
headers=self.annotate_headers({
'Hook-HMAC': self.sign_request(self.subscriber, self.data),
'Hook-Subscription': str(self.subscriber.uuid),
'Host': host,
}),
verify=False,
)
try:
return session.post(
url=url,
data=self.data,
allow_redirects=self.allow_redirects,
timeout=self.timeout,
headers=self.annotate_headers({
'Hook-HMAC': self.sign_request(self.subscriber, self.data),
'Hook-Subscription': str(self.subscriber.uuid),
'Host': host,
}),
verify=False,
)
except requests.exceptions.SSLError as e:
addr = socket.gethostbyname(host)
url = url.replace(addr, host)

return session.post(
url=url,
data=self.data,
allow_redirects=self.allow_redirects,
timeout=self.timeout,
headers=self.annotate_headers({
'Hook-HMAC': self.sign_request(self.subscriber, self.data),
'Hook-Subscription': str(self.subscriber.uuid),
'Host': host,
}),
verify=False,
)

def handle_timeout_error(self, exc, propagate=False):
# type: (Exception, bool) -> Any
Expand Down