Skip to content

Commit a6c6832

Browse files
committed
apply pull openresty#4
1 parent dfe4a61 commit a6c6832

3 files changed

+37
-3
lines changed

src/ngx_http_rds_json_filter_module.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ ngx_http_rds_json_header_filter(ngx_http_request_t *r)
243243
ctx->tag = (ngx_buf_tag_t) &ngx_http_rds_json_filter_module;
244244

245245
ctx->state = state_expect_header;
246+
ctx->handler = ngx_http_rds_json_process_header;
246247

247248
ctx->header_sent = 0;
248249

@@ -299,6 +300,22 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
299300
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
300301
"rds json body filter postponed header sending");
301302

303+
if (ctx->handler) {
304+
rc = ctx->handler(r, in, ctx);
305+
} else {
306+
/* status done */
307+
308+
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
309+
"rds json body filter discarding unexpected trailing buffers");
310+
311+
/* mark the remaining bufs as consumed */
312+
313+
ngx_http_rds_json_discard_bufs(r->pool, in);
314+
315+
return NGX_OK;
316+
}
317+
318+
#if 0
302319
switch (ctx->state) {
303320
case state_expect_header:
304321
rc = ngx_http_rds_json_process_header(r, in, ctx);
@@ -341,7 +358,7 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
341358

342359
break;
343360
}
344-
361+
#endif
345362
dd("body filter rc: %d", (int) rc);
346363

347364
if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {

src/ngx_http_rds_json_filter_module.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ typedef enum {
7878
} ngx_http_rds_json_state_t;
7979

8080

81-
typedef struct {
81+
typedef struct ngx_http_rds_json_ctx_s ngx_http_rds_json_ctx_t;
82+
83+
typedef ngx_int_t (*rds_json_process_handler_pt)(ngx_http_request_t *r,
84+
ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx);
85+
86+
struct ngx_http_rds_json_ctx_s {
8287
ngx_http_rds_json_state_t state;
8388

8489
ngx_str_t *col_name;
@@ -106,10 +111,13 @@ typedef struct {
106111

107112
uint32_t field_data_rest;
108113

114+
rds_json_process_handler_pt handler;
115+
109116
ngx_flag_t header_sent:1;
110117
ngx_flag_t seen_stream_end:1;
111118
ngx_flag_t generated_col_names:1;
112-
} ngx_http_rds_json_ctx_t;
119+
};
120+
113121

114122

115123
#endif /* NGX_HTTP_RDS_JSON_FILTER_MODULE_H */

src/ngx_http_rds_json_processor.c

+9
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ ngx_http_rds_json_process_header(ngx_http_request_t *r,
7373
}
7474

7575
ctx->state = state_done;
76+
ctx->handler = NULL;
7677

7778
/* now we send the postponed response header */
7879
if (!ctx->header_sent) {
@@ -104,6 +105,7 @@ ngx_http_rds_json_process_header(ngx_http_request_t *r,
104105
}
105106

106107
ctx->state = state_expect_col;
108+
ctx->handler = ngx_http_rds_json_process_col;
107109
ctx->cur_col = 0;
108110
ctx->col_count = header.col_count;
109111

@@ -189,6 +191,7 @@ ngx_http_rds_json_process_col(ngx_http_request_t *r, ngx_chain_t *in,
189191
dd("end of column list");
190192

191193
ctx->state = state_expect_row;
194+
ctx->handler = ngx_http_rds_json_process_row;
192195
ctx->row = 0;
193196

194197
dd("output \"[\"");
@@ -285,6 +288,7 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, ngx_chain_t *in,
285288
if (*b->pos++ == 0) {
286289
/* end of row list */
287290
ctx->state = state_done;
291+
ctx->handler = NULL;
288292

289293
if (b->pos != b->last) {
290294
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
@@ -318,6 +322,7 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, ngx_chain_t *in,
318322
ctx->row++;
319323
ctx->cur_col = 0;
320324
ctx->state = state_expect_field;
325+
ctx->handler = ngx_http_rds_json_process_field;
321326

322327
if (b->pos == b->last) {
323328
in = in->next;
@@ -417,6 +422,7 @@ ngx_http_rds_json_process_field(ngx_http_request_t *r, ngx_chain_t *in,
417422
dd("process field: need to read more field data");
418423

419424
ctx->state = state_expect_more_field_data;
425+
ctx->handler = ngx_http_rds_json_process_more_field_data;
420426

421427
return ngx_http_rds_json_process_more_field_data(r, in, ctx);
422428
}
@@ -427,6 +433,7 @@ ngx_http_rds_json_process_field(ngx_http_request_t *r, ngx_chain_t *in,
427433
dd("reached the end of the current row");
428434

429435
ctx->state = state_expect_row;
436+
ctx->handler = ngx_http_rds_json_process_row;
430437

431438
return ngx_http_rds_json_process_row(r, in, ctx);
432439
}
@@ -494,13 +501,15 @@ ngx_http_rds_json_process_more_field_data(ngx_http_request_t *r,
494501
dd("process more field data: reached the end of the current row");
495502

496503
ctx->state = state_expect_row;
504+
ctx->handler = ngx_http_rds_json_process_row;
497505

498506
return ngx_http_rds_json_process_row(r, in, ctx);
499507
}
500508

501509
dd("proces more field data: read the next field");
502510

503511
ctx->state = state_expect_field;
512+
ctx->handler = ngx_http_rds_json_process_field;
504513

505514
return ngx_http_rds_json_process_field(r, in, ctx);
506515
}

0 commit comments

Comments
 (0)