From: Giannis Christodoulou Date: Tue, 21 Jul 2026 10:13:35 +0000 (+0000) Subject: test/modules/proxy: Add test for uwsgi headers X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;ds=sidebyside;p=thirdparty%2Fapache%2Fhttpd.git test/modules/proxy: Add test for uwsgi headers git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1936420 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/test/modules/proxy/env.py b/test/modules/proxy/env.py index 92e85ba9fc..fc44337075 100644 --- a/test/modules/proxy/env.py +++ b/test/modules/proxy/env.py @@ -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 index 0000000000..b0733aba7d --- /dev/null +++ b/test/modules/proxy/test_05_uwsgi.py @@ -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 +