events: make sure we propagate our dummy request with proper application_url.

- handles proper proxy prefix
- handles https and reverse proxies
This commit is contained in:
Marcin Kuzminski 2017-07-26 16:19:06 +02:00
parent 2656338a0d
commit c17e166f5f
2 changed files with 9 additions and 3 deletions

View file

@ -605,9 +605,13 @@ def add_events_routes(config):
pattern='/{repo_name}/files/{commit_id}/{f_path}')
def bootstrap_request():
def bootstrap_request(**kwargs):
import pyramid.testing
request = pyramid.testing.DummyRequest()
request = pyramid.testing.DummyRequest(**kwargs)
request.application_url = kwargs.pop('application_url', 'http://example.com')
request.host = kwargs.pop('host', 'example.com:80')
request.domain = kwargs.pop('domain', 'example.com')
config = pyramid.testing.setUp(request=request)
add_events_routes(config)

View file

@ -207,7 +207,9 @@ class Hooks(object):
def _call_hook(self, hook, extras):
extras = AttributeDict(extras)
extras.request = bootstrap_request()
extras.request = bootstrap_request(
application_url=extras['server_url'])
try:
result = hook(extras)