comparison src/stream/ngx_stream_return_module.c @ 6674:38143d1abdec

Stream: the $status variable. The stream session status is one of the following: 200 - normal completion 403 - access forbidden 500 - internal server error 502 - bad gateway 503 - limit conn
author Roman Arutyunyan <arut@nginx.com>
date Thu, 11 Aug 2016 20:22:23 +0300
parents 8ed51b02f655
children 56fc55e32f23
comparison
equal deleted inserted replaced
6673:e4c1f5b32868 6674:38143d1abdec
81 c->log->action = "returning text"; 81 c->log->action = "returning text";
82 82
83 rscf = ngx_stream_get_module_srv_conf(s, ngx_stream_return_module); 83 rscf = ngx_stream_get_module_srv_conf(s, ngx_stream_return_module);
84 84
85 if (ngx_stream_complex_value(s, &rscf->text, &text) != NGX_OK) { 85 if (ngx_stream_complex_value(s, &rscf->text, &text) != NGX_OK) {
86 ngx_stream_close_connection(c); 86 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
87 return; 87 return;
88 } 88 }
89 89
90 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, 90 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0,
91 "stream return text: \"%V\"", &text); 91 "stream return text: \"%V\"", &text);
92 92
93 if (text.len == 0) { 93 if (text.len == 0) {
94 ngx_stream_close_connection(c); 94 ngx_stream_finalize_session(s, NGX_STREAM_OK);
95 return; 95 return;
96 } 96 }
97 97
98 ctx = ngx_pcalloc(c->pool, sizeof(ngx_stream_return_ctx_t)); 98 ctx = ngx_pcalloc(c->pool, sizeof(ngx_stream_return_ctx_t));
99 if (ctx == NULL) { 99 if (ctx == NULL) {
100 ngx_stream_close_connection(c); 100 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
101 return; 101 return;
102 } 102 }
103 103
104 ngx_stream_set_ctx(s, ctx, ngx_stream_return_module); 104 ngx_stream_set_ctx(s, ctx, ngx_stream_return_module);
105 105
124 c = ev->data; 124 c = ev->data;
125 s = c->data; 125 s = c->data;
126 126
127 if (ev->timedout) { 127 if (ev->timedout) {
128 ngx_connection_error(c, NGX_ETIMEDOUT, "connection timed out"); 128 ngx_connection_error(c, NGX_ETIMEDOUT, "connection timed out");
129 ngx_stream_close_connection(c); 129 ngx_stream_finalize_session(s, NGX_STREAM_OK);
130 return; 130 return;
131 } 131 }
132 132
133 if (ev->ready) { 133 if (ev->ready) {
134 ctx = ngx_stream_get_module_ctx(s, ngx_stream_return_module); 134 ctx = ngx_stream_get_module_ctx(s, ngx_stream_return_module);
135 135
136 b = &ctx->buf; 136 b = &ctx->buf;
137 137
138 n = c->send(c, b->pos, b->last - b->pos); 138 n = c->send(c, b->pos, b->last - b->pos);
139 if (n == NGX_ERROR) { 139 if (n == NGX_ERROR) {
140 ngx_stream_close_connection(c); 140 ngx_stream_finalize_session(s, NGX_STREAM_OK);
141 return; 141 return;
142 } 142 }
143 143
144 if (n > 0) { 144 if (n > 0) {
145 b->pos += n; 145 b->pos += n;
146 146
147 if (b->pos == b->last) { 147 if (b->pos == b->last) {
148 ngx_stream_close_connection(c); 148 ngx_stream_finalize_session(s, NGX_STREAM_OK);
149 return; 149 return;
150 } 150 }
151 } 151 }
152 } 152 }
153 153
154 if (ngx_handle_write_event(ev, 0) != NGX_OK) { 154 if (ngx_handle_write_event(ev, 0) != NGX_OK) {
155 ngx_stream_close_connection(c); 155 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
156 return; 156 return;
157 } 157 }
158 158
159 ngx_add_timer(ev, 5000); 159 ngx_add_timer(ev, 5000);
160 } 160 }