1
0
mirror of https://github.com/apache/httpd.git synced 2026-10-23 22:49:01 +03:00

Merge r1936420 from trunk:

test/modules/proxy: Add test for uwsgi headers


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1938759 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Rainer Jung
2026-10-02 12:26:56 +00:00
parent 2d8cfecec5
commit b895da4ed0
2 changed files with 57 additions and 1 deletions

View 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):

View File

@@ -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