annotate src/http/modules/ngx_http_degradation_module.c @ 4248:2fad4d19ea4b stable-1.0

Merging r4151, r4152, r4177: HTTP cache related fixes: *) Cache: fix for sending of empty responses. Revert wrong fix for empty responses introduced in 0.8.31 and apply new one, rewritten to match things done by static module as close as possible. *) Cache: fix for sending of stale responses. For normal cached responses ngx_http_cache_send() sends last buffer and then request finalized via ngx_http_finalize_request() call, i.e. everything is ok. But for stale responses (i.e. when upstream died, but we have something in cache) the same ngx_http_cache_send() sends last buffer, but then in ngx_http_upstream_finalize_request() another last buffer is send. This causes duplicate final chunk to appear if chunked encoding is used (and resulting problems with keepalive connections and so on). Fix this by not sending in ngx_http_upstream_finalize_request() another last buffer if we know response was from cache. *) Fixed cache bypass caching of non-cacheable replies (ticket #21). If cache was bypassed with proxy_cache_bypass, cache-controlling headers (Cache-Control, Expires) wasn't considered and response was cached even if it was actually non-cacheable. Patch by John Ferlito.
author Igor Sysoev <igor@sysoev.ru>
date Tue, 01 Nov 2011 13:49:31 +0000
parents 147d8a86dd02
children d620f497c50f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4 */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12 typedef struct {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 size_t sbrk_size;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14 } ngx_http_degradation_main_conf_t;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 typedef struct {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18 ngx_uint_t degrade;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19 } ngx_http_degradation_loc_conf_t;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 static ngx_conf_enum_t ngx_http_degrade[] = {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 { ngx_string("204"), 204 },
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 { ngx_string("444"), 444 },
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25 { ngx_null_string, 0 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 };
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29 static void *ngx_http_degradation_create_main_conf(ngx_conf_t *cf);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30 static void *ngx_http_degradation_create_loc_conf(ngx_conf_t *cf);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 static char *ngx_http_degradation_merge_loc_conf(ngx_conf_t *cf, void *parent,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 void *child);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33 static char *ngx_http_degradation(ngx_conf_t *cf, ngx_command_t *cmd,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 void *conf);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35 static ngx_int_t ngx_http_degradation_init(ngx_conf_t *cf);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38 static ngx_command_t ngx_http_degradation_commands[] = {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40 { ngx_string("degradation"),
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42 ngx_http_degradation,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43 NGX_HTTP_MAIN_CONF_OFFSET,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 0,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 NULL },
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47 { ngx_string("degrade"),
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49 ngx_conf_set_enum_slot,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50 NGX_HTTP_LOC_CONF_OFFSET,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51 offsetof(ngx_http_degradation_loc_conf_t, degrade),
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52 &ngx_http_degrade },
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
53
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
54 ngx_null_command
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55 };
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 static ngx_http_module_t ngx_http_degradation_module_ctx = {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 NULL, /* preconfiguration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60 ngx_http_degradation_init, /* postconfiguration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 ngx_http_degradation_create_main_conf, /* create main configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63 NULL, /* init main configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65 NULL, /* create server configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
66 NULL, /* merge server configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68 ngx_http_degradation_create_loc_conf, /* create location configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
69 ngx_http_degradation_merge_loc_conf /* merge location configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70 };
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
72
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 ngx_module_t ngx_http_degradation_module = {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74 NGX_MODULE_V1,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75 &ngx_http_degradation_module_ctx, /* module context */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 ngx_http_degradation_commands, /* module directives */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77 NGX_HTTP_MODULE, /* module type */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 NULL, /* init master */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 NULL, /* init module */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 NULL, /* init process */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81 NULL, /* init thread */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 NULL, /* exit thread */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 NULL, /* exit process */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 NULL, /* exit master */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85 NGX_MODULE_V1_PADDING
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 };
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 static ngx_int_t
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90 ngx_http_degradation_handler(ngx_http_request_t *r)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 {
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
92 ngx_http_degradation_loc_conf_t *dlcf;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_degradation_module);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
96 if (dlcf->degrade && ngx_http_degraded(r)) {
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
97 return dlcf->degrade;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
100 return NGX_DECLINED;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
101 }
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
102
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
103
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
104 ngx_uint_t
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
105 ngx_http_degraded(ngx_http_request_t *r)
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
106 {
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
107 time_t now;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
108 ngx_uint_t log;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
109 static size_t sbrk_size;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
110 static time_t sbrk_time;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
111 ngx_http_degradation_main_conf_t *dmcf;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
112
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
113 dmcf = ngx_http_get_module_main_conf(r, ngx_http_degradation_module);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
115 if (dmcf->sbrk_size) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
117 log = 0;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118 now = ngx_time();
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120 /* lock mutex */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122 if (now != sbrk_time) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124 /*
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125 * ELF/i386 is loaded at 0x08000000, 128M
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126 * ELF/amd64 is loaded at 0x00400000, 4M
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127 *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128 * use a function address to substract the loading address
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129 */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131 sbrk_size = (size_t) sbrk(0) - ((uintptr_t) ngx_palloc & ~0x3FFFFF);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132 sbrk_time = now;
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
133 log = 1;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136 /* unlock mutex */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138 if (sbrk_size >= dmcf->sbrk_size) {
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
139 if (log) {
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
140 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
141 "degradation sbrk:%uzM",
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
142 sbrk_size / (1024 * 1024));
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
143 }
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
144
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
145 return 1;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
149 return 0;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153 static void *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 ngx_http_degradation_create_main_conf(ngx_conf_t *cf)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 ngx_http_degradation_main_conf_t *dmcf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158 dmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_degradation_main_conf_t));
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159 if (dmcf == NULL) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160 return NULL;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
162
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
163 return dmcf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167 static void *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
168 ngx_http_degradation_create_loc_conf(ngx_conf_t *cf)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
169 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
170 ngx_http_degradation_loc_conf_t *conf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
171
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
172 conf = ngx_palloc(cf->pool, sizeof(ngx_http_degradation_loc_conf_t));
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173 if (conf == NULL) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174 return NULL;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
176
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177 conf->degrade = NGX_CONF_UNSET_UINT;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 return conf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 static char *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184 ngx_http_degradation_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186 ngx_http_degradation_loc_conf_t *prev = parent;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187 ngx_http_degradation_loc_conf_t *conf = child;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189 ngx_conf_merge_uint_value(conf->degrade, prev->degrade, 0);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191 return NGX_CONF_OK;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
195 static char *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
196 ngx_http_degradation(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
197 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 ngx_http_degradation_main_conf_t *dmcf = conf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200 ngx_str_t *value, s;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202 value = cf->args->elts;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
204 if (ngx_strncmp(value[1].data, "sbrk=", 5) == 0) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206 s.len = value[1].len - 5;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207 s.data = value[1].data + 5;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
209 dmcf->sbrk_size = ngx_parse_size(&s);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210 if (dmcf->sbrk_size == (size_t) NGX_ERROR) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
212 "invalid sbrk size \"%V\"", &value[1]);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
213 return NGX_CONF_ERROR;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
214 }
3389
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
215
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
216 return NGX_CONF_OK;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
217 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218
3389
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
219 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
220 "invalid parameter \"%V\"", &value[1]);
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
221
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
222 return NGX_CONF_ERROR;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
223 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
225
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
226 static ngx_int_t
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
227 ngx_http_degradation_init(ngx_conf_t *cf)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
229 ngx_http_handler_pt *h;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
230 ngx_http_core_main_conf_t *cmcf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
231
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
232 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234 h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
235 if (h == NULL) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
236 return NGX_ERROR;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239 *h = ngx_http_degradation_handler;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
240
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
241 return NGX_OK;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242 }