Add method to reconstruct the request URI from a WSGI environment.
amcgregor opened this issue · comments
Initial commit, above, adds the factory method URI.from_wsgi
which may be passed a WSGI environment dictionary or dictionary-alike, or any object which has an environ
attribute that is a WSGI environment dictionary, such as a WebOb Request
instance. Tests forthcoming (having a mild issue with it emitting the default port number for the given protocol) but in-progress.
pytest
current test failure
def test_wsgi_unpacking():
webob = pytest.importorskip('webob')
url = 'https://example.com/foo/bar?baz=27'
request = webob.Request.blank(url)
uri = URI.from_wsgi(request)
> assert str(uri) == url
E AssertionError: assert 'https://exam...oo/bar?baz=27' == 'https://exam...oo/bar?baz=27'
E - https://example.com/foo/bar?baz=27
E + https://example.com:443/foo/bar?baz=27
E ? ++++
request = <Request at 0x108fd1100 GET https://example.com/foo/bar?baz=27>
uri = URI('https://example.com:443/foo/bar?baz=27')
url = 'https://example.com/foo/bar?baz=27'
webob = <module 'webob' from '/Users/amcgregor/Projects/marrow/.venv/lib/python3.8/site-packages/webob/__init__.py'>
Sub-optimally corrected by inclusion of the two likely culprits in a WSGI environment (http
and https
) in a port mapping dictionary uri.uri:SERVICES
; this should be loaded from /etc/services
or such a file should be bundled with the library, ref: #15. (System-provided eliminates maintenance overhead for this file.)