]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
test/modules/proxy: Add test for uwsgi headers trunk trunk
authorGiannis Christodoulou <ichristod@apache.org>
Tue, 21 Jul 2026 10:13:35 +0000 (10:13 +0000)
committerGiannis Christodoulou <ichristod@apache.org>
Tue, 21 Jul 2026 10:13:35 +0000 (10:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1936420 13f79535-47bb-0310-9956-ffa450edef68

test/modules/proxy/env.py
test/modules/proxy/test_05_uwsgi.py [new file with mode: 0644]

index 92e85ba9fc456e6fa0d2dec5bde1571ee8a3b82b..fc443370754915ee1ace150e34ea96a8668f9329 100644 (file)
@@ -20,6 +20,7 @@ class TCPFaker:
         self._host = host
         self._port = port
         self._done = False
+        self._request = None
 
     def start(self):
         def process():
@@ -51,6 +52,8 @@ Hello""".encode()
                 c, client_address = self._socket.accept()
                 try:
                     data = c.recv(4096)
+                    # capture request to backend
+                    self._request = data
                     c.sendall(self._make_response(data))
                 finally:
                     c.close()
@@ -66,7 +69,7 @@ class ProxyTestSetup(HttpdTestSetup):
         super().__init__(env=env)
         self.add_source_dir(os.path.dirname(inspect.getfile(ProxyTestSetup)))
         self.add_modules(["proxy", "proxy_http", "proxy_ajp", "proxy_balancer",
-                          "lbmethod_byrequests", "remoteip"])
+                          "proxy_uwsgi", "lbmethod_byrequests", "remoteip"])
 
 
 class ProxyTestEnv(HttpdTestEnv):
diff --git a/test/modules/proxy/test_05_uwsgi.py b/test/modules/proxy/test_05_uwsgi.py
new file mode 100644 (file)
index 0000000..b0733ab
--- /dev/null
@@ -0,0 +1,53 @@
+import pytest
+
+from pyhttpd.conf import HttpdConf
+from .env import TCPFaker
+
+
+class _UWSGIFaker(TCPFaker):
+
+    @staticmethod
+    def hello(data):
+        body = b"Hello"
+        return (
+            b"HTTP/1.1 200 OK\r\n"
+            b"Content-Type: text/plain\r\n"
+            b"Content-Length: 5\r\n"
+            b"\r\n"
+            + body
+        )
+
+
+class TestProxyUwsgi:
+
+    @pytest.fixture(autouse=True, scope='class')
+    def _class_scope(self, env):
+        if not env.has_shared_module("proxy_uwsgi"):
+            pytest.skip("mod_proxy_uwsgi not available")
+        faker = _UWSGIFaker("127.0.0.1", env.http_port2)
+        faker.start()
+        conf = HttpdConf(env)
+        conf.start_vhost(domains=[f"test1.{env.http_tld}"], port=env.http_port)
+        conf.add([
+            f"ProxyPass / uwsgi://127.0.0.1:{env.http_port2}/",
+        ])
+        conf.end_vhost()
+        conf.install()
+        assert env.apache_restart() == 0
+        yield faker
+        faker.stop()
+
+    # verify uwsgi request header
+    def test_proxy_005_01(self, env, _class_scope):
+        _class_scope._make_response = _UWSGIFaker.hello
+        r = env.curl_get(env.mkurl("http", "test1", "/"))
+        assert r.response["status"] == 200
+        assert r.response["body"] == b"Hello"
+
+        data = _class_scope._request
+
+        assert data[0] == 0x00  # standard WSGI request
+        datasize = data[1] + (data[2] * 256)  # read from 16bit little-endian
+        assert data[3] == 0x00  # standard WSGI request
+        assert len(data) == 4 + datasize
+