Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_stub_status_module.c @ 4009:3183165283cc
Fixing proxy_set_body and proxy_pass_request_body with SSL.
Flush flag wasn't set in constructed buffer and this prevented any data
from being actually sent to upstream due to SSL buffering. Make sure
we always set flush in the last buffer we are going to sent.
See here for report:
http://nginx.org/pipermail/nginx-ru/2011-June/041552.html
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 18 Aug 2011 16:34:24 +0000 |
parents | dd1570b6f237 |
children | d620f497c50f |
rev | line source |
---|---|
577 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
487 | 6 |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_http.h> | |
10 | |
11 | |
12 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, | |
13 void *conf); | |
577 | 14 |
487 | 15 static ngx_command_t ngx_http_status_commands[] = { |
16 | |
17 { ngx_string("stub_status"), | |
18 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
19 ngx_http_set_status, | |
20 0, | |
21 0, | |
22 NULL }, | |
23 | |
24 ngx_null_command | |
577 | 25 }; |
487 | 26 |
27 | |
577 | 28 |
667 | 29 static ngx_http_module_t ngx_http_stub_status_module_ctx = { |
509 | 30 NULL, /* preconfiguration */ |
31 NULL, /* postconfiguration */ | |
487 | 32 |
33 NULL, /* create main configuration */ | |
34 NULL, /* init main configuration */ | |
577 | 35 |
487 | 36 NULL, /* create server configuration */ |
37 NULL, /* merge server configuration */ | |
577 | 38 |
487 | 39 NULL, /* create location configuration */ |
40 NULL /* merge location configuration */ | |
41 }; | |
42 | |
43 | |
44 ngx_module_t ngx_http_stub_status_module = { | |
509 | 45 NGX_MODULE_V1, |
487 | 46 &ngx_http_stub_status_module_ctx, /* module context */ |
47 ngx_http_status_commands, /* module directives */ | |
48 NGX_HTTP_MODULE, /* module type */ | |
541 | 49 NULL, /* init master */ |
487 | 50 NULL, /* init module */ |
541 | 51 NULL, /* init process */ |
52 NULL, /* init thread */ | |
53 NULL, /* exit thread */ | |
54 NULL, /* exit process */ | |
55 NULL, /* exit master */ | |
56 NGX_MODULE_V1_PADDING | |
487 | 57 }; |
58 | |
59 | |
60 static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r) | |
61 { | |
495 | 62 size_t size; |
63 ngx_int_t rc; | |
64 ngx_buf_t *b; | |
65 ngx_chain_t out; | |
66 ngx_atomic_int_t ap, hn, ac, rq, rd, wr; | |
577 | 67 |
487 | 68 if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) { |
69 return NGX_HTTP_NOT_ALLOWED; | |
70 } | |
71 | |
1370
cc114c85be0f
rename ngx_http_discard_body() to ngx_http_discard_request_body()
Igor Sysoev <igor@sysoev.ru>
parents:
667
diff
changeset
|
72 rc = ngx_http_discard_request_body(r); |
487 | 73 |
1374 | 74 if (rc != NGX_OK) { |
487 | 75 return rc; |
76 } | |
77 | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
1563
diff
changeset
|
78 ngx_str_set(&r->headers_out.content_type, "text/plain"); |
487 | 79 |
80 if (r->method == NGX_HTTP_HEAD) { | |
81 r->headers_out.status = NGX_HTTP_OK; | |
82 | |
83 rc = ngx_http_send_header(r); | |
84 | |
85 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { | |
86 return rc; | |
87 } | |
88 } | |
89 | |
495 | 90 size = sizeof("Active connections: \n") + NGX_ATOMIC_T_LEN |
487 | 91 + sizeof("server accepts handled requests\n") - 1 |
495 | 92 + 6 + 3 * NGX_ATOMIC_T_LEN |
93 + sizeof("Reading: Writing: Waiting: \n") + 3 * NGX_ATOMIC_T_LEN; | |
487 | 94 |
501 | 95 b = ngx_create_temp_buf(r->pool, size); |
96 if (b == NULL) { | |
487 | 97 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
98 } | |
99 | |
100 out.buf = b; | |
101 out.next = NULL; | |
102 | |
103 ap = *ngx_stat_accepted; | |
495 | 104 hn = *ngx_stat_handled; |
487 | 105 ac = *ngx_stat_active; |
106 rq = *ngx_stat_requests; | |
107 rd = *ngx_stat_reading; | |
108 wr = *ngx_stat_writing; | |
109 | |
509 | 110 b->last = ngx_sprintf(b->last, "Active connections: %uA \n", ac); |
487 | 111 |
112 b->last = ngx_cpymem(b->last, "server accepts handled requests\n", | |
113 sizeof("server accepts handled requests\n") - 1); | |
114 | |
509 | 115 b->last = ngx_sprintf(b->last, " %uA %uA %uA \n", ap, hn, rq); |
487 | 116 |
509 | 117 b->last = ngx_sprintf(b->last, "Reading: %uA Writing: %uA Waiting: %uA \n", |
493 | 118 rd, wr, ac - (rd + wr)); |
487 | 119 |
120 r->headers_out.status = NGX_HTTP_OK; | |
121 r->headers_out.content_length_n = b->last - b->pos; | |
122 | |
123 b->last_buf = 1; | |
124 | |
125 rc = ngx_http_send_header(r); | |
126 | |
127 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { | |
128 return rc; | |
129 } | |
130 | |
1563
022ec9420f80
style fix: remove double semicolons
Igor Sysoev <igor@sysoev.ru>
parents:
1374
diff
changeset
|
131 return ngx_http_output_filter(r, &out); |
487 | 132 } |
133 | |
134 | |
135 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
136 { | |
137 ngx_http_core_loc_conf_t *clcf; | |
138 | |
139 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
140 clcf->handler = ngx_http_status_handler; | |
141 | |
142 return NGX_CONF_OK; | |
143 } |