mirror of
https://github.com/nginx/nginx.git
synced 2025-06-09 19:12:47 +08:00
nginx-0.0.7-2004-06-25-18:42:03 import
This commit is contained in:
parent
59f3aa3a9b
commit
b1af9bbcab
@ -4,13 +4,24 @@
|
|||||||
#include <ngx_http.h>
|
#include <ngx_http.h>
|
||||||
|
|
||||||
|
|
||||||
static char *ngx_http_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
typedef struct {
|
||||||
|
ngx_http_request_t *request;
|
||||||
|
ngx_pool_t *pool;
|
||||||
|
ngx_chain_t *head;
|
||||||
|
ngx_buf_t *last;
|
||||||
|
size_t size;
|
||||||
|
} ngx_http_status_ctx_t;
|
||||||
|
|
||||||
|
|
||||||
|
static ngx_int_t ngx_http_status(ngx_http_status_ctx_t *ctx);
|
||||||
|
static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
|
void *conf);
|
||||||
|
|
||||||
static ngx_command_t ngx_http_status_commands[] = {
|
static ngx_command_t ngx_http_status_commands[] = {
|
||||||
|
|
||||||
{ ngx_string("status"),
|
{ ngx_string("status"),
|
||||||
NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
||||||
ngx_http_status,
|
ngx_http_set_status,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
NULL },
|
NULL },
|
||||||
@ -46,14 +57,8 @@ ngx_module_t ngx_http_status_module = {
|
|||||||
|
|
||||||
static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
|
static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
|
||||||
{
|
{
|
||||||
u_char ch;
|
|
||||||
size_t len;
|
|
||||||
ngx_int_t rc;
|
ngx_int_t rc;
|
||||||
ngx_uint_t i, dash;
|
ngx_http_status_ctx_t ctx;
|
||||||
ngx_buf_t *b;
|
|
||||||
ngx_chain_t out;
|
|
||||||
ngx_connection_t *c;
|
|
||||||
ngx_http_request_t *rq;
|
|
||||||
|
|
||||||
if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
|
if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
|
||||||
return NGX_HTTP_NOT_ALLOWED;
|
return NGX_HTTP_NOT_ALLOWED;
|
||||||
@ -86,53 +91,85 @@ static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
len = 0;
|
ctx.request = r;
|
||||||
dash = 0;
|
ctx.pool = r->pool;
|
||||||
|
ctx.head = NULL;
|
||||||
|
ctx.size = 0;
|
||||||
|
|
||||||
c = ngx_cycle->connections;
|
if (ngx_http_status(&ctx) != NGX_OK) {
|
||||||
for (i = 0; i < ngx_cycle->connection_n; i++) {
|
|
||||||
rq = c[i].data;
|
|
||||||
if (rq && rq->signature == NGX_HTTP_MODULE) {
|
|
||||||
|
|
||||||
/* STUB: should be NGX_PID_T_LEN */
|
|
||||||
len += NGX_INT64_LEN /* pid */
|
|
||||||
+ 1 + NGX_INT32_LEN /* connection */
|
|
||||||
+ 1 + 1 /* state */
|
|
||||||
+ 1 + c[i].addr_text.len
|
|
||||||
+ 1 + rq->server_name->len
|
|
||||||
+ 2; /* "\r\n" */
|
|
||||||
|
|
||||||
if (rq->request_line.len) {
|
|
||||||
len += 1 + rq->request_line.len + 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
dash = 0;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dash) {
|
|
||||||
len += 3;
|
|
||||||
dash = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(b = ngx_create_temp_buf(r->pool, len))) {
|
|
||||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r->headers_out.status = NGX_HTTP_OK;
|
||||||
|
r->headers_out.content_length_n = ctx.size;
|
||||||
|
|
||||||
|
rc = ngx_http_send_header(r);
|
||||||
|
|
||||||
|
if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!r->main) {
|
||||||
|
ctx.last->last_buf = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ngx_http_output_filter(r, ctx.head);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ngx_int_t ngx_http_status(ngx_http_status_ctx_t *ctx)
|
||||||
|
{
|
||||||
|
u_char ch;
|
||||||
|
size_t len, n;
|
||||||
|
ngx_uint_t i, dash;
|
||||||
|
ngx_buf_t *b;
|
||||||
|
ngx_chain_t *cl, **ll;
|
||||||
|
ngx_connection_t *c;
|
||||||
|
ngx_http_request_t *r;
|
||||||
|
ngx_http_core_main_conf_t *cmcf;
|
||||||
|
|
||||||
|
cmcf = ngx_http_get_module_main_conf(ctx->request, ngx_http_core_module);
|
||||||
|
|
||||||
|
#if (NGX_SUPPRESS_WARN)
|
||||||
|
b = NULL;
|
||||||
|
ll = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
dash = 0;
|
dash = 0;
|
||||||
|
|
||||||
|
/* TODO: old connections */
|
||||||
|
|
||||||
|
c = ngx_cycle->connections;
|
||||||
for (i = 0; i < ngx_cycle->connection_n; i++) {
|
for (i = 0; i < ngx_cycle->connection_n; i++) {
|
||||||
rq = c[i].data;
|
|
||||||
if (rq && rq->signature == NGX_HTTP_MODULE) {
|
/* TODO: trylock connection mutex */
|
||||||
|
|
||||||
|
r = c[i].data;
|
||||||
|
if (r && r->signature == NGX_HTTP_MODULE) {
|
||||||
|
|
||||||
|
/* STUB: should be NGX_PID_T_LEN */
|
||||||
|
len = NGX_INT64_LEN /* pid */
|
||||||
|
+ 1 + NGX_INT32_LEN /* connection */
|
||||||
|
+ 1 + 1 /* state */
|
||||||
|
+ 1 + INET_ADDRSTRLEN
|
||||||
|
+ 1 + (r->server_name ? cmcf->max_server_name_len : 1)
|
||||||
|
+ 2; /* "\r\n" */
|
||||||
|
|
||||||
|
if (r->request_line.len) {
|
||||||
|
len += 1 + 1 + r->request_line.len + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(b = ngx_create_temp_buf(ctx->pool, len))) {
|
||||||
|
/* TODO: unlock mutex */
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
b->last += ngx_snprintf((char *) b->last,
|
b->last += ngx_snprintf((char *) b->last,
|
||||||
/* STUB: should be NGX_PID_T_LEN */
|
/* STUB: should be NGX_PID_T_LEN */
|
||||||
NGX_INT64_LEN + NGX_INT32_LEN,
|
NGX_INT64_LEN + NGX_INT32_LEN,
|
||||||
PID_T_FMT " %u", ngx_pid, i);
|
PID_T_FMT " %4u", ngx_pid, i);
|
||||||
|
|
||||||
switch (rq->http_state) {
|
switch (r->http_state) {
|
||||||
case NGX_HTTP_INITING_REQUEST_STATE:
|
case NGX_HTTP_INITING_REQUEST_STATE:
|
||||||
ch = 'I';
|
ch = 'I';
|
||||||
break;
|
break;
|
||||||
@ -163,12 +200,26 @@ static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
|
|||||||
*(b->last++) = ' ';
|
*(b->last++) = ' ';
|
||||||
b->last = ngx_cpymem(b->last, c[i].addr_text.data,
|
b->last = ngx_cpymem(b->last, c[i].addr_text.data,
|
||||||
c[i].addr_text.len);
|
c[i].addr_text.len);
|
||||||
|
for (n = c[i].addr_text.len; n < INET_ADDRSTRLEN; n++) {
|
||||||
|
*(b->last++) = ' ';
|
||||||
|
}
|
||||||
|
|
||||||
*(b->last++) = ' ';
|
*(b->last++) = ' ';
|
||||||
b->last = ngx_cpymem(b->last, rq->server_name->data,
|
if (r->server_name) {
|
||||||
rq->server_name->len);
|
b->last = ngx_cpymem(b->last, r->server_name->data,
|
||||||
|
r->server_name->len);
|
||||||
|
for (n = r->server_name->len;
|
||||||
|
n < cmcf->max_server_name_len;
|
||||||
|
n++)
|
||||||
|
{
|
||||||
|
*(b->last++) = ' ';
|
||||||
|
}
|
||||||
|
|
||||||
if (rq->request_line.len) {
|
} else {
|
||||||
|
*(b->last++) = '?';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r->request_line.len) {
|
||||||
*(b->last++) = ' ';
|
*(b->last++) = ' ';
|
||||||
*(b->last++) = '"';
|
*(b->last++) = '"';
|
||||||
b->last = ngx_cpymem(b->last, r->request_line.data,
|
b->last = ngx_cpymem(b->last, r->request_line.data,
|
||||||
@ -181,36 +232,72 @@ static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
|
|||||||
|
|
||||||
dash = 0;
|
dash = 0;
|
||||||
|
|
||||||
|
} else if (c[i].fd != -1) {
|
||||||
|
len = NGX_INT64_LEN /* pid */
|
||||||
|
+ 1 + NGX_INT32_LEN /* connection */
|
||||||
|
+ 1 + 1 /* state */
|
||||||
|
+ 2; /* "\r\n" */
|
||||||
|
|
||||||
|
if (!(b = ngx_create_temp_buf(ctx->pool, len))) {
|
||||||
|
/* TODO: unlock mutex */
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
b->last += ngx_snprintf((char *) b->last,
|
||||||
|
/* STUB: should be NGX_PID_T_LEN */
|
||||||
|
NGX_INT64_LEN + NGX_INT32_LEN,
|
||||||
|
PID_T_FMT " %4u", ngx_pid, i);
|
||||||
|
|
||||||
|
*(b->last++) = ' ';
|
||||||
|
*(b->last++) = 's';
|
||||||
|
|
||||||
|
*(b->last++) = CR; *(b->last++) = LF;
|
||||||
|
|
||||||
|
dash = 0;
|
||||||
|
|
||||||
|
} else if (!dash) {
|
||||||
|
len = 3;
|
||||||
|
|
||||||
|
if (!(b = ngx_create_temp_buf(ctx->pool, len))) {
|
||||||
|
/* TODO: unlock mutex */
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(b->last++) = '-'; *(b->last++) = CR; *(b->last++) = LF;
|
||||||
|
|
||||||
|
dash = 1;
|
||||||
|
|
||||||
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dash) {
|
/* TODO: unlock mutex */
|
||||||
*(b->last++) = '-'; *(b->last++) = CR; *(b->last++) = LF;
|
|
||||||
dash = 1;
|
if (!(cl = ngx_alloc_chain_link(ctx->pool))) {
|
||||||
}
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->headers_out.status = NGX_HTTP_OK;
|
if (ctx->head) {
|
||||||
r->headers_out.content_length_n = b->last - b->pos;
|
*ll = cl;
|
||||||
|
|
||||||
rc = ngx_http_send_header(r);
|
} else {
|
||||||
|
ctx->head = cl;
|
||||||
if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!r->main) {
|
cl->buf = b;
|
||||||
b->last_buf = 1;
|
cl->next = NULL;
|
||||||
|
ll = &cl->next;
|
||||||
|
|
||||||
|
ctx->size += b->last - b->pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
out.buf = b;
|
ctx->last = b;
|
||||||
out.next = NULL;
|
|
||||||
|
|
||||||
return ngx_http_output_filter(r, &out);
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *ngx_http_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
{
|
{
|
||||||
ngx_http_conf_ctx_t *ctx;
|
ngx_http_conf_ctx_t *ctx;
|
||||||
ngx_http_core_loc_conf_t *clcf;
|
ngx_http_core_loc_conf_t *clcf;
|
||||||
|
@ -1159,7 +1159,9 @@ static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
|
|||||||
ngx_http_core_srv_conf_t *conf = child;
|
ngx_http_core_srv_conf_t *conf = child;
|
||||||
|
|
||||||
ngx_http_listen_t *l;
|
ngx_http_listen_t *l;
|
||||||
|
ngx_http_conf_ctx_t *ctx;
|
||||||
ngx_http_server_name_t *n;
|
ngx_http_server_name_t *n;
|
||||||
|
ngx_http_core_main_conf_t *cmcf;
|
||||||
|
|
||||||
/* TODO: it does not merge, it inits only */
|
/* TODO: it does not merge, it inits only */
|
||||||
|
|
||||||
@ -1188,6 +1190,14 @@ static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
|
|||||||
|
|
||||||
n->name.len = ngx_strlen(n->name.data);
|
n->name.len = ngx_strlen(n->name.data);
|
||||||
n->core_srv_conf = conf;
|
n->core_srv_conf = conf;
|
||||||
|
|
||||||
|
ctx = (ngx_http_conf_ctx_t *)
|
||||||
|
cf->cycle->conf_ctx[ngx_http_module.index];
|
||||||
|
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
||||||
|
|
||||||
|
if (cmcf->max_server_name_len < n->name.len) {
|
||||||
|
cmcf->max_server_name_len = n->name.len;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngx_conf_merge_size_value(conf->connection_pool_size,
|
ngx_conf_merge_size_value(conf->connection_pool_size,
|
||||||
@ -1427,11 +1437,16 @@ static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
|
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
ngx_str_t *value;
|
ngx_str_t *value;
|
||||||
|
ngx_http_conf_ctx_t *ctx;
|
||||||
ngx_http_server_name_t *sn;
|
ngx_http_server_name_t *sn;
|
||||||
|
ngx_http_core_main_conf_t *cmcf;
|
||||||
|
|
||||||
/* TODO: several names */
|
/* TODO: several names */
|
||||||
/* TODO: warn about duplicate 'server_name' directives */
|
/* TODO: warn about duplicate 'server_name' directives */
|
||||||
|
|
||||||
|
ctx = (ngx_http_conf_ctx_t *) cf->cycle->conf_ctx[ngx_http_module.index];
|
||||||
|
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
|
||||||
|
|
||||||
value = cf->args->elts;
|
value = cf->args->elts;
|
||||||
|
|
||||||
for (i = 1; i < cf->args->nelts; i++) {
|
for (i = 1; i < cf->args->nelts; i++) {
|
||||||
@ -1448,6 +1463,10 @@ static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
sn->name.len = value[i].len;
|
sn->name.len = value[i].len;
|
||||||
sn->name.data = value[i].data;
|
sn->name.data = value[i].data;
|
||||||
sn->core_srv_conf = scf;
|
sn->core_srv_conf = scf;
|
||||||
|
|
||||||
|
if (cmcf->max_server_name_len < sn->name.len) {
|
||||||
|
cmcf->max_server_name_len = sn->name.len;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NGX_CONF_OK;
|
return NGX_CONF_OK;
|
||||||
|
@ -41,6 +41,8 @@ typedef struct {
|
|||||||
|
|
||||||
ngx_http_phase_t phases[NGX_HTTP_LAST_PHASE];
|
ngx_http_phase_t phases[NGX_HTTP_LAST_PHASE];
|
||||||
ngx_array_t index_handlers;
|
ngx_array_t index_handlers;
|
||||||
|
|
||||||
|
size_t max_server_name_len;
|
||||||
} ngx_http_core_main_conf_t;
|
} ngx_http_core_main_conf_t;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1013,6 +1013,7 @@ void ngx_http_finalize_request(ngx_http_request_t *r, int rc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (r->connection->write->timer_set) {
|
if (r->connection->write->timer_set) {
|
||||||
|
r->connection->write->delayed = 0;
|
||||||
ngx_del_timer(r->connection->write);
|
ngx_del_timer(r->connection->write);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1055,12 +1056,12 @@ static void ngx_http_set_write_handler(ngx_http_request_t *r)
|
|||||||
wev = r->connection->write;
|
wev = r->connection->write;
|
||||||
wev->event_handler = ngx_http_writer;
|
wev->event_handler = ngx_http_writer;
|
||||||
|
|
||||||
|
r->http_state = NGX_HTTP_WRITING_REQUEST_STATE;
|
||||||
|
|
||||||
if (wev->ready && wev->delayed) {
|
if (wev->ready && wev->delayed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->http_state = NGX_HTTP_WRITING_REQUEST_STATE;
|
|
||||||
|
|
||||||
clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
|
clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
|
||||||
ngx_http_core_module);
|
ngx_http_core_module);
|
||||||
if (!wev->delayed) {
|
if (!wev->delayed) {
|
||||||
|
Loading…
Reference in New Issue
Block a user