Skip to content

Commit d3b17e4

Browse files
committed
show upstream through brower
1 parent afe47ac commit d3b17e4

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

src/ngx_stream_upsync_module.c

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,50 +3685,51 @@ ngx_stream_upsync_show_upstream(ngx_stream_upstream_srv_conf_t *uscf, ngx_buf_t
36853685
static void
36863686
ngx_stream_upsync_show(ngx_stream_session_t *s)
36873687
{
3688-
ngx_buf_t *b;
3689-
ngx_uint_t i;
3690-
ngx_stream_upstream_srv_conf_t **uscfp = NULL;
3691-
ngx_stream_upstream_main_conf_t *umcf;
3688+
ngx_buf_t *b_header, *b_body;
3689+
ngx_uint_t i;
3690+
ngx_stream_upstream_srv_conf_t **uscfp = NULL;
3691+
ngx_stream_upstream_main_conf_t *umcf;
36923692

36933693
umcf = ngx_stream_cycle_get_module_main_conf(ngx_cycle,
36943694
ngx_stream_upstream_module);
36953695

36963696
uscfp = umcf->upstreams.elts;
36973697

3698-
b = ngx_create_temp_buf(s->connection->pool,
3699-
NGX_PAGE_SIZE * NGX_PAGE_NUMBER);
3700-
if (b == NULL) {
3698+
b_header = ngx_create_temp_buf(s->connection->pool, NGX_PAGE_SIZE);
3699+
b_body = ngx_create_temp_buf(s->connection->pool,
3700+
NGX_PAGE_SIZE * NGX_PAGE_NUMBER);
3701+
if (b_header == NULL || b_body == NULL) {
37013702
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
37023703
"alloc upsync_show buf failed");
37033704

37043705
ngx_stream_close_connection(s->connection);
37053706
return;
37063707
}
37073708

3708-
//HTTP Header
3709-
b->last = ngx_snprintf(b->last, b->end - b->last,
3710-
"HTTP/1.0 200 OK\r\n");
3711-
b->last = ngx_snprintf(b->last, b->end - b->last,
3712-
"Server: nginx\r\n");
3713-
b->last = ngx_snprintf(b->last, b->end - b->last,
3714-
"Content-Type: text/plain\r\n");
3715-
b->last = ngx_snprintf(b->last, b->end - b->last,
3716-
"Connection: close\r\n\r\n");
3717-
3718-
ngx_stream_upsync_show_send(s, b); //send header
3719-
3720-
b->pos = b->last;
37213709
if (umcf->upstreams.nelts == 0) {
3722-
b->last = ngx_snprintf(b->last, b->end - b->last,
3723-
"No upstreams defined\n");
3710+
b_body->last = ngx_snprintf(b_body->last, b_body->end - b_body->last,
3711+
"No upstreams defined\n");
37243712
}
37253713

37263714
for (i = 0; i < umcf->upstreams.nelts; i++) {
3727-
ngx_stream_upsync_show_upstream(uscfp[i], b);
3728-
b->last = ngx_snprintf(b->last, b->end - b->last, "\n");
3715+
ngx_stream_upsync_show_upstream(uscfp[i], b_body);
3716+
b_body->last = ngx_snprintf(b_body->last, b_body->end - b_body->last, "\n");
37293717
}
37303718

3731-
ngx_stream_upsync_show_send(s, b); //send body
3719+
//HTTP Header
3720+
b_header->last = ngx_snprintf(b_header->last, b_header->end - b_header->last,
3721+
"HTTP/1.0 200 OK\r\n");
3722+
b_header->last = ngx_snprintf(b_header->last, b_header->end - b_header->last,
3723+
"Server: nginx\r\n");
3724+
b_header->last = ngx_snprintf(b_header->last, b_header->end - b_header->last,
3725+
"Content-Type: text/plain\r\n");
3726+
b_header->last = ngx_snprintf(b_header->last, b_header->end - b_header->last,
3727+
"Content-Length: %d\r\n", b_body->last - b_body->pos);
3728+
b_header->last = ngx_snprintf(b_header->last, b_header->end - b_header->last,
3729+
"Connection: close\r\n\r\n");
3730+
3731+
ngx_stream_upsync_show_send(s, b_header); //send header
3732+
ngx_stream_upsync_show_send(s, b_body); //send body
37323733

37333734
ngx_stream_close_connection(s->connection);
37343735

0 commit comments

Comments
 (0)