# Path: oslo_middleware/http_proxy_to_wsgi.py
# OPTS = [
#     cfg.BoolOpt('enable_proxy_headers_parsing',
#                 default=False,
#                 help="Whether the application is behind a proxy or not. "
#                      "This determines if the middleware should parse the "
#                      "headers or not.")
# ]
# class HTTPProxyToWSGI(base.ConfigurableMiddleware):
#     def __init__(self, application, *args, **kwargs):
#     def _parse_rfc7239_header(header):
#     def process_request(self, req):


from wsgiref import util
from oslotest import base as test_base
from oslo_middleware import http_proxy_to_wsgi
import webob
        def fake_app(req):
            return req.environ['REMOTE_ADDR']

        self.middleware = http_proxy_to_wsgi.HTTPProxyToWSGI(fake_app)
        forwarded_for_addr = '1.2.3.4'
        forwarded_addr = '8.8.8.8'

        # If both X-Forwarded-For and Fowarded headers are present, it should
        # use the Forwarded header and ignore the X-Forwarded-For header.
        self.request.headers['Forwarded'] = (
            "for=%s;proto=https;host=example.com:8043" % (forwarded_addr))
        self.request.headers['X-Forwarded-For'] = forwarded_for_addr
        response = self.request.get_response(self.middleware)
        self.assertEqual(forwarded_addr.encode(), response.body)

        # Now if only X-Forwarded-For header is present, it should be used.
        del self.request.headers['Forwarded']
        response = self.request.get_response(self.middleware)
        self.assertEqual(forwarded_for_addr.encode(), response.body)


class TestHTTPProxyToWSGIDisabled(test_base.BaseTestCase):

    def setUp(self):
        super(TestHTTPProxyToWSGIDisabled, self).setUp()

        @webob.dec.wsgify()
        def fake_app(req):
            return util.application_uri(req.environ)


# Path: oslo_middleware/http_proxy_to_wsgi.py
# OPTS = [
#     cfg.BoolOpt('enable_proxy_headers_parsing',
#                 default=False,
#                 help="Whether the application is behind a proxy or not. "
#                      "This determines if the middleware should parse the "
#                      "headers or not.")
# ]
# class HTTPProxyToWSGI(base.ConfigurableMiddleware):
#     def __init__(self, application, *args, **kwargs):
#     def _parse_rfc7239_header(header):
#     def process_request(self, req):


# Path: oslo_middleware/tests/test_http_proxy_to_wsgi.py
from wsgiref import util
from oslotest import base as test_base
from oslo_middleware import http_proxy_to_wsgi
import webob

        def fake_app(req):
            return req.environ['REMOTE_ADDR']

        self.middleware = http_proxy_to_wsgi.HTTPProxyToWSGI(fake_app)
        forwarded_for_addr = '1.2.3.4'
        forwarded_addr = '8.8.8.8'

        # If both X-Forwarded-For and Fowarded headers are present, it should
        # use the Forwarded header and ignore the X-Forwarded-For header.
        self.request.headers['Forwarded'] = (
            "for=%s;proto=https;host=example.com:8043" % (forwarded_addr))
        self.request.headers['X-Forwarded-For'] = forwarded_for_addr
        response = self.request.get_response(self.middleware)
        self.assertEqual(forwarded_addr.encode(), response.body)

        # Now if only X-Forwarded-For header is present, it should be used.
        del self.request.headers['Forwarded']
        response = self.request.get_response(self.middleware)
        self.assertEqual(forwarded_for_addr.encode(), response.body)


class TestHTTPProxyToWSGIDisabled(test_base.BaseTestCase):

    def setUp(self):
        super(TestHTTPProxyToWSGIDisabled, self).setUp()

        @webob.dec.wsgify()
        def fake_app(req):
            return util.application_uri(req.environ)


        self.middleware = http_proxy_to_wsgi.HTTPProxyToWSGI(fake_app)