1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| static void ngx_stream_return_handler(ngx_stream_session_t *s) { ngx_str_t text; ngx_buf_t *b; ngx_connection_t *c; ngx_stream_return_ctx_t *ctx; ngx_stream_return_srv_conf_t *rscf;
c = s->connection;
c->log->action = "returning text";
rscf = ngx_stream_get_module_srv_conf(s, ngx_stream_return_module);
if (ngx_stream_complex_value(s, &rscf->text, &text) != NGX_OK) { ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); return; }
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "stream return text: \"%V\"", &text);
if (text.len == 0) { ngx_stream_finalize_session(s, NGX_STREAM_OK); return; }
ctx = ngx_pcalloc(c->pool, sizeof(ngx_stream_return_ctx_t)); if (ctx == NULL) { ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); return; }
ngx_stream_set_ctx(s, ctx, ngx_stream_return_module);
b = ngx_calloc_buf(c->pool); if (b == NULL) { ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); return; }
b->memory = 1; b->pos = text.data; b->last = text.data + text.len; b->last_buf = 1;
ctx->out = ngx_alloc_chain_link(c->pool); if (ctx->out == NULL) { ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); return; }
ctx->out->buf = b; ctx->out->next = NULL;
c->write->handler = ngx_stream_return_write_handler;
ngx_stream_return_write_handler(c->write); }
|