From e11c08eef8587518010ce2dbbeb8b450886b09bf Mon Sep 17 00:00:00 2001 From: gordon chung Date: Mon, 9 Nov 2015 11:35:34 -0500 Subject: [PATCH] add missing shortcut for HTTPProxyToWSGI middleware we should've added a shortcut to oslo_middleware/__init__ to hide path. additionally we shouldn't have added Middleware to class name as it's redundant Change-Id: Id581180c24006aa142eb8bf086eb7fc42835cff5 Closes-Bug: #1514507 --- oslo_middleware/__init__.py | 2 ++ oslo_middleware/http_proxy_to_wsgi.py | 9 +++++++-- oslo_middleware/tests/test_http_proxy_to_wsgi.py | 11 ++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/oslo_middleware/__init__.py b/oslo_middleware/__init__.py index b2ea8c0..ea1c12d 100644 --- a/oslo_middleware/__init__.py +++ b/oslo_middleware/__init__.py @@ -15,6 +15,7 @@ __all__ = ['CatchErrors', 'CORS', 'Debug', 'Healthcheck', + 'HTTPProxyToWSGI', 'RequestId', 'RequestBodySizeLimiter', 'SSLMiddleware'] @@ -24,6 +25,7 @@ from oslo_middleware.correlation_id import CorrelationId from oslo_middleware.cors import CORS from oslo_middleware.debug import Debug from oslo_middleware.healthcheck import Healthcheck +from oslo_middleware.http_proxy_to_wsgi import HTTPProxyToWSGI from oslo_middleware.request_id import RequestId from oslo_middleware.sizelimit import RequestBodySizeLimiter from oslo_middleware.ssl import SSLMiddleware diff --git a/oslo_middleware/http_proxy_to_wsgi.py b/oslo_middleware/http_proxy_to_wsgi.py index 425f414..a2da6ab 100644 --- a/oslo_middleware/http_proxy_to_wsgi.py +++ b/oslo_middleware/http_proxy_to_wsgi.py @@ -11,11 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. See the License for the specific language governing permissions and # limitations under the License. - +from debtcollector import removals from oslo_middleware import base -class HTTPProxyToWSGIMiddleware(base.ConfigurableMiddleware): +class HTTPProxyToWSGI(base.ConfigurableMiddleware): """HTTP proxy to WSGI termination middleware. This middleware overloads WSGI environment variables with the one provided @@ -68,3 +68,8 @@ class HTTPProxyToWSGIMiddleware(base.ConfigurableMiddleware): v = req.environ.get("HTTP_X_FORWARDED_PREFIX") if v: req.environ['SCRIPT_NAME'] = v + req.environ['SCRIPT_NAME'] + + +@removals.remove +class HTTPProxyToWSGIMiddleware(HTTPProxyToWSGI): + """Placeholder for backward compatibility""" diff --git a/oslo_middleware/tests/test_http_proxy_to_wsgi.py b/oslo_middleware/tests/test_http_proxy_to_wsgi.py index bbd3601..8db1190 100644 --- a/oslo_middleware/tests/test_http_proxy_to_wsgi.py +++ b/oslo_middleware/tests/test_http_proxy_to_wsgi.py @@ -24,13 +24,22 @@ class TestHTTPProxyToWSGI(test_base.BaseTestCase): def setUp(self): super(TestHTTPProxyToWSGI, self).setUp() + @webob.dec.wsgify() + def fake_app(req): + return util.application_uri(req.environ) + + self.middleware = http_proxy_to_wsgi.HTTPProxyToWSGI(fake_app) + self.request = webob.Request.blank('/foo/bar', method='POST') + + def test_backward_compat(self): @webob.dec.wsgify() def fake_app(req): return util.application_uri(req.environ) self.middleware = http_proxy_to_wsgi.HTTPProxyToWSGIMiddleware( fake_app) - self.request = webob.Request.blank('/foo/bar', method='POST') + response = self.request.get_response(self.middleware) + self.assertEqual(b"http://localhost:80/", response.body) def test_no_headers(self): response = self.request.get_response(self.middleware)