Skip to content

Commit 9349f40

Browse files
committed
fix
1 parent bcc3cea commit 9349f40

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
lines changed

src/ngx_http_apisix_module.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,7 @@ ngx_http_apisix_set_upstream_pass_trailers(ngx_http_request_t *r, int on)
10691069
ngx_int_t
10701070
ngx_http_apisix_is_upstream_pass_trailers(ngx_http_request_t *r)
10711071
{
1072-
return 0;
1073-
/* ngx_http_apisix_ctx_t *ctx;
1072+
ngx_http_apisix_ctx_t *ctx;
10741073

10751074
ctx = ngx_http_apisix_get_module_ctx(r);
10761075

@@ -1079,5 +1078,5 @@ ngx_http_apisix_is_upstream_pass_trailers(ngx_http_request_t *r)
10791078
return ctx->upstream_pass_trailers;
10801079
}
10811080

1082-
return 1; */
1081+
return 1;
10831082
}

t/upstream_pass_trailers.t

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
5766
location /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
}
61120
location /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

Comments
 (0)