Skip to content

Commit 8bc432d

Browse files
committed
If tnt_pass is down, then status should be passed to the client.
1 parent 0361138 commit 8bc432d

File tree

5 files changed

+51
-7
lines changed

5 files changed

+51
-7
lines changed

src/ngx_http_tnt_eval_module.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ typedef struct {
5656
typedef struct {
5757
ngx_http_tnt_eval_loc_conf_t *base_conf;
5858
ngx_http_variable_value_t **values;
59-
unsigned int done:1;
60-
unsigned int in_progress:1;
59+
ngx_int_t status;
60+
ngx_int_t done:1;
61+
ngx_int_t in_progress:1;
6162

6263
/* A reference to the main request */
6364
ngx_http_request_t *r;
@@ -206,6 +207,14 @@ ngx_http_tnt_eval_handler(ngx_http_request_t *r)
206207

207208
if (ctx->done) {
208209
dd("subrequest done, r = %p, ctx = %p", r, ctx);
210+
211+
/** If tnt_pass is down, then status should be passed to the client.
212+
* 0 meas that upstream works
213+
*/
214+
if (ctx->status != 0) {
215+
return ctx->status;
216+
}
217+
209218
return NGX_DECLINED;
210219
}
211220

@@ -310,6 +319,8 @@ ngx_http_tnt_eval_post_subrequest_handler(ngx_http_request_t *r, void *data,
310319

311320
ctx->done = 1;
312321

322+
ctx->status = rc;
323+
313324
#if 0
314325
/* work-around a bug in the nginx core (ngx_http_named_location)
315326
*/
@@ -827,15 +838,15 @@ ngx_http_tnt_eval_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
827838

828839
clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
829840

830-
name.len = sizeof("/eval_") - 1 + NGX_OFF_T_LEN;
841+
name.len = sizeof("/tnt_eval_") - 1 + NGX_OFF_T_LEN;
831842

832843
name.data = ngx_palloc(cf->pool, name.len);
833844

834845
if (name.data == NULL) {
835846
return NGX_CONF_ERROR;
836847
}
837848

838-
name.len = ngx_sprintf(name.data, "/eval_%O", (off_t)(uintptr_t) clcf)
849+
name.len = ngx_sprintf(name.data, "/tnt_eval_%O", (off_t)(uintptr_t) clcf)
839850
- name.data;
840851

841852
clcf->loc_conf = ctx->loc_conf;

src/ngx_http_tnt_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
#ifndef NGX_HTTP_TNT_VERSION_H
3434
#define NGX_HTTP_TNT_VERSION_H 1
3535

36-
#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.4.3"
36+
#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.4.4-beta"
3737

3838
#endif

test/eval_basic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def do_get(url, code, headers):
124124

125125
# =============
126126
#
127-
print('[+] Test headers codes')
128-
127+
print('[+] Test headers')
128+
loc = BASE_URL + '/eval_headers'
129+
result = post_success(loc, {'params': []}, {'in_h': 1}, default_print_f)
129130
print('[+] OK')

test/ngx_confs/tnt_server_test.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,5 +317,18 @@ http {
317317
tnt_pass tnt;
318318
}
319319

320+
location /eval_headers {
321+
tnt_eval_buffer_size 1m;
322+
tnt_eval $tnt_status $tnt_res {
323+
tnt_buffer_size 1m;
324+
tnt_pass_http_request on parse_args;
325+
tnt_http_rest_methods all;
326+
tnt_method test_eval_headers;
327+
tnt_pass tnt;
328+
}
329+
add_header 'X-t' $tnt_status;
330+
return 200 $tnt_res;
331+
}
332+
320333
}
321334
}

test/test.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,25 @@ function test_eval(req, ...)
157157
out
158158
end
159159

160+
function test_eval_headers(req, ...)
161+
162+
local headers = {}
163+
164+
for i = 1, 10 do
165+
headers['H' .. tostring(i)] = tostring(i)
166+
end
167+
168+
return
169+
{
170+
__ngx = {
171+
200,
172+
headers
173+
}
174+
},
175+
req,
176+
...
177+
end
178+
160179
-- CFG
161180
box.cfg {
162181
log_level = 5;

0 commit comments

Comments
 (0)