annotate src/http/modules/ngx_http_stub_status_module.c @ 58:b55cbf18157e NGINX_0_1_29

nginx 0.1.29 *) Feature: the ngx_http_ssi_module supports "include virtual" command. *) Feature: the ngx_http_ssi_module supports the condition command like 'if expr="$NAME"' and "else" and "endif" commands. Only one nested level is supported. *) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and DATE_GMT variables and "config timefmt" command. *) Feature: the "ssi_ignore_recycled_buffers" directive. *) Bugfix: the "echo" command did not show the default value for the empty QUERY_STRING variable. *) Change: the ngx_http_proxy_module was rewritten. *) Feature: the "proxy_redirect", "proxy_pass_request_headers", "proxy_pass_request_body", and "proxy_method" directives. *) Feature: the "proxy_set_header" directive. The "proxy_x_var" was canceled and must be replaced with the proxy_set_header directive. *) Change: the "proxy_preserve_host" is canceled and must be replaced with the "proxy_set_header Host $host" and the "proxy_redirect off" directives, the "proxy_set_header Host $host:$proxy_port" directive and the appropriate proxy_redirect directives. *) Change: the "proxy_set_x_real_ip" is canceled and must be replaced with the "proxy_set_header X-Real-IP $remote_addr" directive. *) Change: the "proxy_add_x_forwarded_for" is canceled and must be replaced with the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for" directive. *) Change: the "proxy_set_x_url" is canceled and must be replaced with the "proxy_set_header X-URL http://$host:$server_port$request_uri" directive. *) Feature: the "fastcgi_param" directive. *) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params" directive are canceled and must be replaced with the fastcgi_param directives. *) Feature: the "index" directive can use the variables. *) Feature: the "index" directive can be used at http and server levels. *) Change: the last index only in the "index" directive can be absolute. *) Feature: the "rewrite" directive can use the variables. *) Feature: the "internal" directive. *) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR, SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME, REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables. *) Change: nginx now passes the invalid lines in a client request headers or a backend response header. *) Bugfix: if the backend did not transfer response for a long time and the "send_timeout" was less than "proxy_read_timeout", then nginx returned the 408 response. *) Bugfix: the segmentation fault was occurred if the backend sent an invalid line in response header; bug appeared in 0.1.26. *) Bugfix: the segmentation fault may occurred in FastCGI fault tolerance configuration. *) Bugfix: the "expires" directive did not remove the previous "Expires" and "Cache-Control" headers. *) Bugfix: nginx did not take into account trailing dot in "Host" header line. *) Bugfix: the ngx_http_auth_module did not work under Linux. *) Bugfix: the rewrite directive worked incorrectly, if the arguments were in a request. *) Bugfix: nginx could not be built on MacOS X.
author Igor Sysoev <http://sysoev.ru>
date Thu, 12 May 2005 00:00:00 +0400
parents 72eb30262aac
children 71c46860eb55
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 #include <ngx_config.h>
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 #include <ngx_core.h>
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 #include <ngx_http.h>
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd,
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 void *conf);
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10 static ngx_command_t ngx_http_status_commands[] = {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12 { ngx_string("stub_status"),
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14 ngx_http_set_status,
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15 0,
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
16 0,
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
17 NULL },
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
18
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19 ngx_null_command
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20 };
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
23
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24 ngx_http_module_t ngx_http_stub_status_module_ctx = {
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
25 NULL, /* preconfiguration */
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
26 NULL, /* postconfiguration */
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28 NULL, /* create main configuration */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29 NULL, /* init main configuration */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31 NULL, /* create server configuration */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32 NULL, /* merge server configuration */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 NULL, /* create location configuration */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35 NULL /* merge location configuration */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36 };
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39 ngx_module_t ngx_http_stub_status_module = {
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
40 NGX_MODULE_V1,
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
41 &ngx_http_stub_status_module_ctx, /* module context */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 ngx_http_status_commands, /* module directives */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43 NGX_HTTP_MODULE, /* module type */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 NULL, /* init module */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 NULL /* init process */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46 };
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49 static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
50 {
44
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
51 size_t size;
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
52 ngx_int_t rc;
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
53 ngx_buf_t *b;
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
54 ngx_chain_t out;
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
55 ngx_atomic_int_t ap, hn, ac, rq, rd, wr;
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58 return NGX_HTTP_NOT_ALLOWED;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61 rc = ngx_http_discard_body(r);
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63 if (rc != NGX_OK && rc != NGX_AGAIN) {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 return rc;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
67 r->headers_out.content_type.len = sizeof("text/plain") - 1;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
68 r->headers_out.content_type.data = (u_char *) "text/plain";
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70 if (r->method == NGX_HTTP_HEAD) {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 r->headers_out.status = NGX_HTTP_OK;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73 rc = ngx_http_send_header(r);
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76 return rc;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
77 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79
44
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
80 size = sizeof("Active connections: \n") + NGX_ATOMIC_T_LEN
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81 + sizeof("server accepts handled requests\n") - 1
44
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
82 + 6 + 3 * NGX_ATOMIC_T_LEN
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
83 + sizeof("Reading: Writing: Waiting: \n") + 3 * NGX_ATOMIC_T_LEN;
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 44
diff changeset
85 b = ngx_create_temp_buf(r->pool, size);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 44
diff changeset
86 if (b == NULL) {
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87 return NGX_HTTP_INTERNAL_SERVER_ERROR;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
88 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90 out.buf = b;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
91 out.next = NULL;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
92
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
93 ap = *ngx_stat_accepted;
44
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
94 hn = *ngx_stat_handled;
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
95 ac = *ngx_stat_active;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
96 rq = *ngx_stat_requests;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
97 rd = *ngx_stat_reading;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
98 wr = *ngx_stat_writing;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
99
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
100 b->last = ngx_sprintf(b->last, "Active connections: %uA \n", ac);
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
101
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
102 b->last = ngx_cpymem(b->last, "server accepts handled requests\n",
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
103 sizeof("server accepts handled requests\n") - 1);
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
105 b->last = ngx_sprintf(b->last, " %uA %uA %uA \n", ap, hn, rq);
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
106
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
107 b->last = ngx_sprintf(b->last, "Reading: %uA Writing: %uA Waiting: %uA \n",
42
41ccba1aba45 nginx 0.1.21
Igor Sysoev <http://sysoev.ru>
parents: 36
diff changeset
108 rd, wr, ac - (rd + wr));
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
110 r->headers_out.status = NGX_HTTP_OK;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
111 r->headers_out.content_length_n = b->last - b->pos;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
112
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
113 b->last_buf = 1;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
114
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115 rc = ngx_http_send_header(r);
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118 return rc;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121 return ngx_http_output_filter(r, &out);;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
124
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
125 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
126 {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
127 ngx_http_core_loc_conf_t *clcf;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
128
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130 clcf->handler = ngx_http_status_handler;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
132 return NGX_CONF_OK;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
133 }