Merge "api: Remove 'Debug' middleware"

This commit is contained in:
Zuul 2019-10-01 17:13:35 +00:00 committed by Gerrit Code Review
commit 4d18b29c95
2 changed files with 0 additions and 61 deletions

View File

@ -12,12 +12,10 @@
"""WSGI primitives used throughout the nova WSGI apps."""
import os
import sys
from oslo_log import log as logging
from paste import deploy
import routes.middleware
import six
import webob
import nova.conf
@ -167,42 +165,6 @@ class Middleware(Application):
return self.process_response(response)
class Debug(Middleware):
"""Helper class for debugging a WSGI application.
Can be inserted into any WSGI application chain to get information
about the request and response.
"""
@webob.dec.wsgify(RequestClass=Request)
def __call__(self, req):
print(('*' * 40) + ' REQUEST ENVIRON')
for key, value in req.environ.items():
print(key, '=', value)
print()
resp = req.get_response(self.application)
print(('*' * 40) + ' RESPONSE HEADERS')
for (key, value) in resp.headers.items():
print(key, '=', value)
print()
resp.app_iter = self.print_generator(resp.app_iter)
return resp
@staticmethod
def print_generator(app_iter):
"""Iterator that prints the contents of a wrapper string."""
print(('*' * 40) + ' BODY')
for part in app_iter:
sys.stdout.write(six.text_type(part))
sys.stdout.flush()
yield part
print()
class Router(object):
"""WSGI middleware that maps incoming requests to WSGI apps."""

View File

@ -19,9 +19,7 @@
Test WSGI basics and provide some helper functions for other WSGI tests.
"""
import fixtures
import routes
from six.moves import StringIO
import webob
from nova.api import wsgi
@ -30,27 +28,6 @@ from nova import test
class Test(test.NoDBTestCase):
def test_debug(self):
"""This tests optional middleware we have which dumps
the requests to stdout.
"""
self.output = StringIO()
self.useFixture(fixtures.MonkeyPatch('sys.stdout', self.output))
class Application(wsgi.Application):
"""Dummy application to test debug."""
def __call__(self, environ, start_response):
start_response("200", [("X-Test", "checking")])
return [b'Test result']
application = wsgi.Debug(Application())
result = webob.Request.blank('/').get_response(application)
self.assertEqual(result.body, b"Test result")
self.assertIn(
'**************************************** REQUEST ENVIRON',
self.output.getvalue())
def test_router(self):
class Application(wsgi.Application):