Add support for automatic domains
If not host or url is passed to the Interceptor a uuid is generated for that context.
This commit is contained in:
@@ -107,6 +107,16 @@ def test_httplib2_interceptor_https_host():
|
||||
assert 'WSGI intercept successful!' in content.decode('utf-8')
|
||||
|
||||
|
||||
def test_httplib2_interceptor_no_host():
|
||||
# no hostname or port, one will be generated automatically
|
||||
# we never actually know what it is
|
||||
http = Http()
|
||||
with Httplib2Interceptor(app=app) as url:
|
||||
response, content = http.request(url)
|
||||
assert response.status == 200
|
||||
assert 'WSGI intercept successful!' in content.decode('utf-8')
|
||||
|
||||
|
||||
def test_httplib2_interceptor_url():
|
||||
hostname = str(uuid4())
|
||||
port = 9999
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"""
|
||||
|
||||
from importlib import import_module
|
||||
from uuid import uuid4
|
||||
|
||||
from six.moves.urllib import parse as urlparse
|
||||
|
||||
@@ -17,11 +18,16 @@ class Interceptor(object):
|
||||
process of addition and removal.
|
||||
|
||||
Each Interceptor subclass is associated with a specific http library.
|
||||
|
||||
Each class may be passed a url or a host and a port. If no args are passed
|
||||
a hostname will be automatically generated and the resulting url will be
|
||||
returned by the context manager.
|
||||
"""
|
||||
|
||||
def __init__(self, app, host=None, port=80, prefix=None, url=None):
|
||||
assert app
|
||||
assert (host and port) or (url)
|
||||
if (not host and not url):
|
||||
host = str(uuid4())
|
||||
|
||||
self.app = app
|
||||
|
||||
|
||||
Reference in New Issue
Block a user