@@ -52,16 +52,75 @@ GET /t
5252
5353
5454
55- === TEST 2: do not pass upstream trailers to downstream
55+ === TEST 2: pass upstream trailers to downstream
56+ Since the processing logic for the trailer is located in the upstream module, it must be tested via proxy_pass.
57+ --- http_config
58+ server {
59+ listen 1985;
60+ location /t {
61+ add_trailer "foo" "bar";
62+ echo "hello";
63+ }
64+ }
5665--- config
5766location /up {
58- add_trailer "foo" "bar";
59- echo "hello";
67+ proxy_pass http://127.0.0.1:1985/t;
68+ }
69+ location /t {
70+ access_by_lua_block {
71+ local upstream = require("resty.apisix.upstream")
72+ assert(upstream.set_pass_trailers(true), 'failed to set pass trailers')
73+ }
74+
75+ content_by_lua_block {
76+ local sock = ngx.socket.tcp()
77+
78+ local ok, err = sock:connect("127.0.0.1", ngx.var.server_port)
79+ if not ok then
80+ ngx.say("failed to connect: ", err)
81+ return
82+ end
83+
84+ local _, err = sock:send("GET /up HTTP/1.1\r\nHost: 127.0.0.1:1984\r\nUser-Agent: curl/8.5.0\r\nAccept: */*\r\nConnection: close\r\n\r\n")
85+ if err then
86+ ngx.say("failed to send: ", err)
87+ return
88+ end
89+
90+ local data, err, partial = sock:receive("*a")
91+ if err then
92+ ngx.say("failed to receive: ", err)
93+ return
94+ end
95+
96+ assert(string.find(data, "HTTP/1.1 200 OK", 1, true), "status not 200")
97+ assert(not string.find(data, "Trailer: foo", 1, true), "exist trailer header")
98+ assert(string.find(data, "foo: bar", 1, true), "missing trailer")
99+ }
100+ }
101+ --- request
102+ GET /t
103+
104+
105+
106+ === TEST 3: do not pass upstream trailers to downstream
107+ Since the processing logic for the trailer is located in the upstream module, it must be tested via proxy_pass.
108+ --- http_config
109+ server {
110+ listen 1985;
111+ location /t {
112+ add_trailer "foo" "bar";
113+ echo "hello";
114+ }
115+ }
116+ --- config
117+ location /up {
118+ proxy_pass http://127.0.0.1:1985/t;
60119}
61120location /t {
62121 access_by_lua_block {
63122 local upstream = require("resty.apisix.upstream")
64- assert(upstream.set_pass_trailers(false))
123+ assert(upstream.set_pass_trailers(false), 'failed to set pass trailers' )
65124 }
66125
67126 content_by_lua_block {
0 commit comments