annotate src/http/modules/ngx_http_stub_status_module.c @ 5497:2cfc095a607a

Fixed setting of content type in some cases. This fixes content type set in stub_status and autoindex responses to be usable in content type checks made by filter modules, such as charset and sub filters.
author Ruslan Ermilov <ru@nginx.com>
date Fri, 27 Dec 2013 19:40:04 +0400
parents ee739104d164
children dc7c139fca21
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
1
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
2 /*
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 3516
diff changeset
4 * Copyright (C) Nginx, Inc.
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
5 */
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
6
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_config.h>
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_core.h>
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10 #include <ngx_http.h>
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
5079
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
13 static ngx_int_t ngx_http_stub_status_variable(ngx_http_request_t *r,
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
14 ngx_http_variable_value_t *v, uintptr_t data);
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
15 static ngx_int_t ngx_http_stub_status_add_variables(ngx_conf_t *cf);
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
16
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd,
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18 void *conf);
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
19
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20 static ngx_command_t ngx_http_status_commands[] = {
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 { ngx_string("stub_status"),
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 ngx_http_set_status,
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25 0,
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 0,
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27 NULL },
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29 ngx_null_command
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
30 };
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
33
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
34 static ngx_http_module_t ngx_http_stub_status_module_ctx = {
5079
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
35 ngx_http_stub_status_add_variables, /* preconfiguration */
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
36 NULL, /* postconfiguration */
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38 NULL, /* create main configuration */
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39 NULL, /* init main configuration */
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
40
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 NULL, /* create server configuration */
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42 NULL, /* merge server configuration */
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
43
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 NULL, /* create location configuration */
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 NULL /* merge location configuration */
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46 };
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49 ngx_module_t ngx_http_stub_status_module = {
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
50 NGX_MODULE_V1,
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51 &ngx_http_stub_status_module_ctx, /* module context */
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52 ngx_http_status_commands, /* module directives */
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
53 NGX_HTTP_MODULE, /* module type */
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
54 NULL, /* init master */
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55 NULL, /* init module */
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
56 NULL, /* init process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
57 NULL, /* init thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
58 NULL, /* exit thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
59 NULL, /* exit process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
60 NULL, /* exit master */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
61 NGX_MODULE_V1_PADDING
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 };
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64
5079
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
65 static ngx_http_variable_t ngx_http_stub_status_vars[] = {
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
66
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
67 { ngx_string("connections_active"), NULL, ngx_http_stub_status_variable,
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
68 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
69
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
70 { ngx_string("connections_reading"), NULL, ngx_http_stub_status_variable,
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
71 1, NGX_HTTP_VAR_NOCACHEABLE, 0 },
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
72
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
73 { ngx_string("connections_writing"), NULL, ngx_http_stub_status_variable,
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
74 2, NGX_HTTP_VAR_NOCACHEABLE, 0 },
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
75
5115
a29c574d61fa Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents: 5079
diff changeset
76 { ngx_string("connections_waiting"), NULL, ngx_http_stub_status_variable,
a29c574d61fa Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents: 5079
diff changeset
77 3, NGX_HTTP_VAR_NOCACHEABLE, 0 },
a29c574d61fa Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents: 5079
diff changeset
78
5079
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
79 { ngx_null_string, NULL, NULL, 0, 0, 0 }
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
80 };
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
81
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
82
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 {
495
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
85 size_t size;
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
86 ngx_int_t rc;
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
87 ngx_buf_t *b;
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
88 ngx_chain_t out;
5115
a29c574d61fa Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents: 5079
diff changeset
89 ngx_atomic_int_t ap, hn, ac, rq, rd, wr, wa;
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
90
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 return NGX_HTTP_NOT_ALLOWED;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93 }
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94
1370
cc114c85be0f rename ngx_http_discard_body() to ngx_http_discard_request_body()
Igor Sysoev <igor@sysoev.ru>
parents: 667
diff changeset
95 rc = ngx_http_discard_request_body(r);
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96
1374
aabbf66b61ea omit unnecessary conditions
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
97 if (rc != NGX_OK) {
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 return rc;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 }
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100
5497
2cfc095a607a Fixed setting of content type in some cases.
Ruslan Ermilov <ru@nginx.com>
parents: 5243
diff changeset
101 r->headers_out.content_type_len = sizeof("text/plain") - 1;
3516
dd1570b6f237 ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents: 1563
diff changeset
102 ngx_str_set(&r->headers_out.content_type, "text/plain");
5497
2cfc095a607a Fixed setting of content type in some cases.
Ruslan Ermilov <ru@nginx.com>
parents: 5243
diff changeset
103 r->headers_out.content_type_lowcase = NULL;
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
104
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
105 if (r->method == NGX_HTTP_HEAD) {
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106 r->headers_out.status = NGX_HTTP_OK;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108 rc = ngx_http_send_header(r);
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
109
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111 return rc;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112 }
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
113 }
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114
495
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
115 size = sizeof("Active connections: \n") + NGX_ATOMIC_T_LEN
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116 + sizeof("server accepts handled requests\n") - 1
495
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
117 + 6 + 3 * NGX_ATOMIC_T_LEN
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
118 + sizeof("Reading: Writing: Waiting: \n") + 3 * NGX_ATOMIC_T_LEN;
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 495
diff changeset
120 b = ngx_create_temp_buf(r->pool, size);
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 495
diff changeset
121 if (b == NULL) {
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122 return NGX_HTTP_INTERNAL_SERVER_ERROR;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123 }
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125 out.buf = b;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126 out.next = NULL;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128 ap = *ngx_stat_accepted;
495
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
129 hn = *ngx_stat_handled;
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130 ac = *ngx_stat_active;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131 rq = *ngx_stat_requests;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132 rd = *ngx_stat_reading;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 wr = *ngx_stat_writing;
5115
a29c574d61fa Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents: 5079
diff changeset
134 wa = *ngx_stat_waiting;
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
136 b->last = ngx_sprintf(b->last, "Active connections: %uA \n", ac);
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138 b->last = ngx_cpymem(b->last, "server accepts handled requests\n",
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139 sizeof("server accepts handled requests\n") - 1);
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
141 b->last = ngx_sprintf(b->last, " %uA %uA %uA \n", ap, hn, rq);
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
143 b->last = ngx_sprintf(b->last, "Reading: %uA Writing: %uA Waiting: %uA \n",
5115
a29c574d61fa Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents: 5079
diff changeset
144 rd, wr, wa);
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 r->headers_out.status = NGX_HTTP_OK;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147 r->headers_out.content_length_n = b->last - b->pos;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148
4611
2b6cb7528409 Allows particular modules to handle subrequests properly.
Andrey Belov <defan@nginx.com>
parents: 4412
diff changeset
149 b->last_buf = (r == r->main) ? 1 : 0;
5243
ee739104d164 Status: the "last_in_chain" flag must be set.
Valentin Bartenev <vbart@nginx.com>
parents: 5115
diff changeset
150 b->last_in_chain = 1;
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152 rc = ngx_http_send_header(r);
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155 return rc;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 }
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157
1563
022ec9420f80 style fix: remove double semicolons
Igor Sysoev <igor@sysoev.ru>
parents: 1374
diff changeset
158 return ngx_http_output_filter(r, &out);
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159 }
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161
5079
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
162 static ngx_int_t
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
163 ngx_http_stub_status_variable(ngx_http_request_t *r,
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
164 ngx_http_variable_value_t *v, uintptr_t data)
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
165 {
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
166 u_char *p;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
167 ngx_atomic_int_t value;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
168
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
169 p = ngx_pnalloc(r->pool, NGX_ATOMIC_T_LEN);
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
170 if (p == NULL) {
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
171 return NGX_ERROR;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
172 }
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
173
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
174 switch (data) {
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
175 case 0:
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
176 value = *ngx_stat_active;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
177 break;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
178
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
179 case 1:
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
180 value = *ngx_stat_reading;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
181 break;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
182
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
183 case 2:
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
184 value = *ngx_stat_writing;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
185 break;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
186
5115
a29c574d61fa Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents: 5079
diff changeset
187 case 3:
a29c574d61fa Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents: 5079
diff changeset
188 value = *ngx_stat_waiting;
a29c574d61fa Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents: 5079
diff changeset
189 break;
a29c574d61fa Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents: 5079
diff changeset
190
5079
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
191 /* suppress warning */
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
192 default:
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
193 value = 0;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
194 break;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
195 }
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
196
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
197 v->len = ngx_sprintf(p, "%uA", value) - p;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
198 v->valid = 1;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
199 v->no_cacheable = 0;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
200 v->not_found = 0;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
201 v->data = p;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
202
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
203 return NGX_OK;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
204 }
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
205
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
206
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
207 static ngx_int_t
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
208 ngx_http_stub_status_add_variables(ngx_conf_t *cf)
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
209 {
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
210 ngx_http_variable_t *var, *v;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
211
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
212 for (v = ngx_http_stub_status_vars; v->name.len; v++) {
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
213 var = ngx_http_add_variable(cf, &v->name, v->flags);
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
214 if (var == NULL) {
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
215 return NGX_ERROR;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
216 }
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
217
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
218 var->get_handler = v->get_handler;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
219 var->data = v->data;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
220 }
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
221
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
222 return NGX_OK;
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
223 }
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
224
1c472e3b8c10 Introduced variables in ngx_http_stub_status module.
Andrey Belov <defan@nginx.com>
parents: 4611
diff changeset
225
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
226 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
227 {
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228 ngx_http_core_loc_conf_t *clcf;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
229
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
230 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
231 clcf->handler = ngx_http_status_handler;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
232
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233 return NGX_CONF_OK;
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234 }