nginxtra 1.6.3.9 → 1.8.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/bin/nginxtra +1 -1
  3. data/bin/nginxtra_rails +1 -1
  4. data/lib/nginxtra/version.rb +1 -1
  5. data/vendor/nginx/CHANGES +358 -14
  6. data/vendor/nginx/CHANGES.ru +372 -18
  7. data/vendor/nginx/LICENSE +2 -2
  8. data/vendor/nginx/auto/cc/clang +5 -0
  9. data/vendor/nginx/auto/cc/gcc +5 -0
  10. data/vendor/nginx/auto/lib/google-perftools/conf +1 -1
  11. data/vendor/nginx/auto/lib/openssl/make +0 -5
  12. data/vendor/nginx/auto/lib/perl/conf +9 -1
  13. data/vendor/nginx/auto/make +1 -1
  14. data/vendor/nginx/auto/modules +11 -0
  15. data/vendor/nginx/auto/options +10 -2
  16. data/vendor/nginx/auto/os/darwin +0 -1
  17. data/vendor/nginx/auto/os/freebsd +6 -23
  18. data/vendor/nginx/auto/sources +16 -14
  19. data/vendor/nginx/auto/summary +3 -24
  20. data/vendor/nginx/auto/threads +20 -0
  21. data/vendor/nginx/auto/types/sizeof +2 -12
  22. data/vendor/nginx/auto/unix +50 -6
  23. data/vendor/nginx/configure +5 -0
  24. data/vendor/nginx/contrib/vim/syntax/nginx.vim +183 -50
  25. data/vendor/nginx/src/core/nginx.c +21 -9
  26. data/vendor/nginx/src/core/nginx.h +8 -2
  27. data/vendor/nginx/src/core/ngx_buf.c +88 -0
  28. data/vendor/nginx/src/core/ngx_buf.h +15 -1
  29. data/vendor/nginx/src/core/ngx_conf_file.c +4 -1
  30. data/vendor/nginx/src/core/ngx_connection.c +25 -66
  31. data/vendor/nginx/src/core/ngx_connection.h +1 -3
  32. data/vendor/nginx/src/core/ngx_core.h +11 -3
  33. data/vendor/nginx/src/core/ngx_crypt.c +1 -1
  34. data/vendor/nginx/src/core/ngx_cycle.c +7 -1
  35. data/vendor/nginx/src/core/ngx_cycle.h +6 -2
  36. data/vendor/nginx/src/core/ngx_file.c +13 -5
  37. data/vendor/nginx/src/core/ngx_file.h +6 -0
  38. data/vendor/nginx/src/core/ngx_log.c +215 -21
  39. data/vendor/nginx/src/core/ngx_log.h +9 -1
  40. data/vendor/nginx/src/core/ngx_output_chain.c +104 -15
  41. data/vendor/nginx/src/core/ngx_palloc.c +3 -7
  42. data/vendor/nginx/src/core/ngx_rbtree.c +2 -4
  43. data/vendor/nginx/src/core/ngx_rbtree.h +2 -4
  44. data/vendor/nginx/src/core/ngx_regex.c +14 -6
  45. data/vendor/nginx/src/core/ngx_resolver.c +16 -23
  46. data/vendor/nginx/src/core/ngx_resolver.h +8 -7
  47. data/vendor/nginx/src/core/ngx_shmtx.c +1 -1
  48. data/vendor/nginx/src/core/ngx_slab.c +89 -2
  49. data/vendor/nginx/src/core/ngx_slab.h +3 -0
  50. data/vendor/nginx/src/core/ngx_string.c +58 -2
  51. data/vendor/nginx/src/core/ngx_string.h +1 -0
  52. data/vendor/nginx/src/core/ngx_syslog.c +374 -0
  53. data/vendor/nginx/src/core/ngx_syslog.h +30 -0
  54. data/vendor/nginx/src/core/ngx_thread_pool.c +630 -0
  55. data/vendor/nginx/src/core/ngx_thread_pool.h +36 -0
  56. data/vendor/nginx/src/core/ngx_times.c +19 -2
  57. data/vendor/nginx/src/core/ngx_times.h +1 -0
  58. data/vendor/nginx/src/event/modules/ngx_aio_module.c +1 -1
  59. data/vendor/nginx/src/event/modules/ngx_devpoll_module.c +9 -24
  60. data/vendor/nginx/src/event/modules/ngx_epoll_module.c +152 -28
  61. data/vendor/nginx/src/event/modules/ngx_eventport_module.c +43 -25
  62. data/vendor/nginx/src/event/modules/ngx_kqueue_module.c +86 -156
  63. data/vendor/nginx/src/event/modules/ngx_poll_module.c +21 -37
  64. data/vendor/nginx/src/event/modules/ngx_rtsig_module.c +15 -27
  65. data/vendor/nginx/src/event/modules/ngx_select_module.c +10 -12
  66. data/vendor/nginx/src/event/modules/ngx_win32_select_module.c +7 -9
  67. data/vendor/nginx/src/event/ngx_event.c +5 -33
  68. data/vendor/nginx/src/event/ngx_event.h +15 -50
  69. data/vendor/nginx/src/event/ngx_event_accept.c +11 -10
  70. data/vendor/nginx/src/event/ngx_event_connect.c +0 -11
  71. data/vendor/nginx/src/event/ngx_event_connect.h +1 -4
  72. data/vendor/nginx/src/event/ngx_event_openssl.c +622 -38
  73. data/vendor/nginx/src/event/ngx_event_openssl.h +20 -2
  74. data/vendor/nginx/src/event/ngx_event_openssl_stapling.c +5 -1
  75. data/vendor/nginx/src/event/ngx_event_pipe.c +45 -19
  76. data/vendor/nginx/src/event/ngx_event_pipe.h +3 -0
  77. data/vendor/nginx/src/event/ngx_event_posted.c +7 -145
  78. data/vendor/nginx/src/event/ngx_event_posted.h +12 -39
  79. data/vendor/nginx/src/event/ngx_event_timer.c +50 -70
  80. data/vendor/nginx/src/event/ngx_event_timer.h +2 -14
  81. data/vendor/nginx/src/http/modules/ngx_http_addition_filter_module.c +1 -1
  82. data/vendor/nginx/src/http/modules/ngx_http_autoindex_module.c +416 -71
  83. data/vendor/nginx/src/http/modules/ngx_http_charset_filter_module.c +19 -15
  84. data/vendor/nginx/src/http/modules/ngx_http_dav_module.c +16 -4
  85. data/vendor/nginx/src/http/modules/ngx_http_fastcgi_module.c +601 -134
  86. data/vendor/nginx/src/http/modules/ngx_http_geo_module.c +1 -1
  87. data/vendor/nginx/src/http/modules/ngx_http_geoip_module.c +9 -3
  88. data/vendor/nginx/src/http/modules/ngx_http_gunzip_filter_module.c +9 -3
  89. data/vendor/nginx/src/http/modules/ngx_http_gzip_filter_module.c +9 -3
  90. data/vendor/nginx/src/http/modules/ngx_http_gzip_static_module.c +0 -2
  91. data/vendor/nginx/src/http/modules/ngx_http_headers_filter_module.c +197 -91
  92. data/vendor/nginx/src/http/modules/ngx_http_image_filter_module.c +1 -0
  93. data/vendor/nginx/src/http/modules/ngx_http_limit_conn_module.c +65 -162
  94. data/vendor/nginx/src/http/modules/ngx_http_limit_req_module.c +53 -67
  95. data/vendor/nginx/src/http/modules/ngx_http_log_module.c +128 -23
  96. data/vendor/nginx/src/http/modules/ngx_http_memcached_module.c +25 -6
  97. data/vendor/nginx/src/http/modules/ngx_http_mp4_module.c +1 -1
  98. data/vendor/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +39 -13
  99. data/vendor/nginx/src/http/modules/ngx_http_proxy_module.c +697 -141
  100. data/vendor/nginx/src/http/modules/ngx_http_rewrite_module.c +5 -1
  101. data/vendor/nginx/src/http/modules/ngx_http_scgi_module.c +282 -125
  102. data/vendor/nginx/src/http/modules/ngx_http_ssi_filter_module.c +4 -1
  103. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.c +44 -1
  104. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.h +2 -0
  105. data/vendor/nginx/src/http/modules/ngx_http_stub_status_module.c +10 -8
  106. data/vendor/nginx/src/http/modules/ngx_http_sub_filter_module.c +18 -3
  107. data/vendor/nginx/src/http/modules/ngx_http_upstream_hash_module.c +641 -0
  108. data/vendor/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +1 -1
  109. data/vendor/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +3 -21
  110. data/vendor/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c +0 -5
  111. data/vendor/nginx/src/http/modules/ngx_http_uwsgi_module.c +449 -125
  112. data/vendor/nginx/src/http/modules/ngx_http_xslt_filter_module.c +4 -2
  113. data/vendor/nginx/src/http/modules/perl/ngx_http_perl_module.c +2 -1
  114. data/vendor/nginx/src/http/ngx_http.c +10 -5
  115. data/vendor/nginx/src/http/ngx_http.h +4 -4
  116. data/vendor/nginx/src/http/ngx_http_cache.h +26 -1
  117. data/vendor/nginx/src/http/ngx_http_copy_filter_module.c +109 -68
  118. data/vendor/nginx/src/http/ngx_http_core_module.c +191 -46
  119. data/vendor/nginx/src/http/ngx_http_core_module.h +16 -4
  120. data/vendor/nginx/src/http/ngx_http_file_cache.c +584 -67
  121. data/vendor/nginx/src/http/ngx_http_parse.c +55 -4
  122. data/vendor/nginx/src/http/ngx_http_request.c +14 -6
  123. data/vendor/nginx/src/http/ngx_http_request.h +12 -4
  124. data/vendor/nginx/src/http/ngx_http_request_body.c +114 -28
  125. data/vendor/nginx/src/http/ngx_http_spdy.c +383 -229
  126. data/vendor/nginx/src/http/ngx_http_spdy.h +8 -5
  127. data/vendor/nginx/src/http/ngx_http_spdy_filter_module.c +12 -4
  128. data/vendor/nginx/src/http/ngx_http_special_response.c +2 -2
  129. data/vendor/nginx/src/http/ngx_http_upstream.c +808 -132
  130. data/vendor/nginx/src/http/ngx_http_upstream.h +33 -3
  131. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.c +72 -65
  132. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.h +1 -2
  133. data/vendor/nginx/src/http/ngx_http_variables.c +47 -3
  134. data/vendor/nginx/src/http/ngx_http_write_filter_module.c +15 -6
  135. data/vendor/nginx/src/mail/ngx_mail.c +2 -3
  136. data/vendor/nginx/src/mail/ngx_mail.h +2 -0
  137. data/vendor/nginx/src/mail/ngx_mail_auth_http_module.c +140 -11
  138. data/vendor/nginx/src/mail/ngx_mail_core_module.c +3 -3
  139. data/vendor/nginx/src/mail/ngx_mail_handler.c +79 -2
  140. data/vendor/nginx/src/mail/ngx_mail_imap_module.c +3 -1
  141. data/vendor/nginx/src/mail/ngx_mail_pop3_module.c +3 -1
  142. data/vendor/nginx/src/mail/ngx_mail_smtp_module.c +3 -1
  143. data/vendor/nginx/src/mail/ngx_mail_ssl_module.c +125 -1
  144. data/vendor/nginx/src/mail/ngx_mail_ssl_module.h +8 -0
  145. data/vendor/nginx/src/misc/ngx_cpp_test_module.cpp +1 -1
  146. data/vendor/nginx/src/os/unix/ngx_aio_read_chain.c +1 -1
  147. data/vendor/nginx/src/os/unix/ngx_channel.c +0 -7
  148. data/vendor/nginx/src/os/unix/ngx_darwin_config.h +0 -3
  149. data/vendor/nginx/src/os/unix/ngx_darwin_sendfile_chain.c +44 -208
  150. data/vendor/nginx/src/os/unix/ngx_file_aio_read.c +25 -17
  151. data/vendor/nginx/src/os/unix/ngx_files.c +109 -0
  152. data/vendor/nginx/src/os/unix/ngx_files.h +6 -0
  153. data/vendor/nginx/src/os/unix/ngx_freebsd_config.h +0 -6
  154. data/vendor/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +78 -206
  155. data/vendor/nginx/src/os/unix/ngx_linux_aio_read.c +25 -14
  156. data/vendor/nginx/src/os/unix/ngx_linux_config.h +4 -1
  157. data/vendor/nginx/src/os/unix/ngx_linux_sendfile_chain.c +235 -194
  158. data/vendor/nginx/src/os/unix/ngx_os.h +25 -3
  159. data/vendor/nginx/src/os/unix/ngx_posix_init.c +4 -2
  160. data/vendor/nginx/src/os/unix/ngx_process_cycle.c +13 -195
  161. data/vendor/nginx/src/os/unix/ngx_process_cycle.h +0 -1
  162. data/vendor/nginx/src/os/unix/ngx_readv_chain.c +27 -108
  163. data/vendor/nginx/src/os/unix/ngx_setproctitle.h +2 -2
  164. data/vendor/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +12 -67
  165. data/vendor/nginx/src/os/unix/ngx_thread.h +26 -83
  166. data/vendor/nginx/src/os/unix/ngx_thread_cond.c +87 -0
  167. data/vendor/nginx/src/os/unix/ngx_thread_id.c +70 -0
  168. data/vendor/nginx/src/os/unix/ngx_thread_mutex.c +174 -0
  169. data/vendor/nginx/src/os/unix/ngx_user.c +2 -20
  170. data/vendor/nginx/src/os/unix/ngx_writev_chain.c +129 -98
  171. metadata +16 -17
  172. data/vendor/nginx/auto/lib/zlib/patch.zlib.h +0 -10
  173. data/vendor/nginx/src/event/ngx_event_busy_lock.c +0 -286
  174. data/vendor/nginx/src/event/ngx_event_busy_lock.h +0 -65
  175. data/vendor/nginx/src/event/ngx_event_mutex.c +0 -70
  176. data/vendor/nginx/src/http/ngx_http_busy_lock.c +0 -307
  177. data/vendor/nginx/src/http/ngx_http_busy_lock.h +0 -54
  178. data/vendor/nginx/src/os/unix/ngx_freebsd_rfork_thread.c +0 -756
  179. data/vendor/nginx/src/os/unix/ngx_freebsd_rfork_thread.h +0 -122
  180. data/vendor/nginx/src/os/unix/ngx_pthread_thread.c +0 -278
  181. data/vendor/nginx/src/os/unix/rfork_thread.S +0 -73
@@ -1012,6 +1012,7 @@ transparent:
1012
1012
  b->last_buf = 1;
1013
1013
 
1014
1014
  ngx_http_image_length(r, b);
1015
+ ngx_http_weak_etag(r);
1015
1016
 
1016
1017
  return b;
1017
1018
  }
@@ -11,41 +11,40 @@
11
11
 
12
12
 
13
13
  typedef struct {
14
- u_char color;
15
- u_char len;
16
- u_short conn;
17
- u_char data[1];
14
+ u_char color;
15
+ u_char len;
16
+ u_short conn;
17
+ u_char data[1];
18
18
  } ngx_http_limit_conn_node_t;
19
19
 
20
20
 
21
21
  typedef struct {
22
- ngx_shm_zone_t *shm_zone;
23
- ngx_rbtree_node_t *node;
22
+ ngx_shm_zone_t *shm_zone;
23
+ ngx_rbtree_node_t *node;
24
24
  } ngx_http_limit_conn_cleanup_t;
25
25
 
26
26
 
27
27
  typedef struct {
28
- ngx_rbtree_t *rbtree;
29
- ngx_int_t index;
30
- ngx_str_t var;
28
+ ngx_rbtree_t *rbtree;
29
+ ngx_http_complex_value_t key;
31
30
  } ngx_http_limit_conn_ctx_t;
32
31
 
33
32
 
34
33
  typedef struct {
35
- ngx_shm_zone_t *shm_zone;
36
- ngx_uint_t conn;
34
+ ngx_shm_zone_t *shm_zone;
35
+ ngx_uint_t conn;
37
36
  } ngx_http_limit_conn_limit_t;
38
37
 
39
38
 
40
39
  typedef struct {
41
- ngx_array_t limits;
42
- ngx_uint_t log_level;
43
- ngx_uint_t status_code;
40
+ ngx_array_t limits;
41
+ ngx_uint_t log_level;
42
+ ngx_uint_t status_code;
44
43
  } ngx_http_limit_conn_conf_t;
45
44
 
46
45
 
47
46
  static ngx_rbtree_node_t *ngx_http_limit_conn_lookup(ngx_rbtree_t *rbtree,
48
- ngx_http_variable_value_t *vv, uint32_t hash);
47
+ ngx_str_t *key, uint32_t hash);
49
48
  static void ngx_http_limit_conn_cleanup(void *data);
50
49
  static ngx_inline void ngx_http_limit_conn_cleanup_all(ngx_pool_t *pool);
51
50
 
@@ -54,18 +53,11 @@ static char *ngx_http_limit_conn_merge_conf(ngx_conf_t *cf, void *parent,
54
53
  void *child);
55
54
  static char *ngx_http_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd,
56
55
  void *conf);
57
- static char *ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd,
58
- void *conf);
59
56
  static char *ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd,
60
57
  void *conf);
61
58
  static ngx_int_t ngx_http_limit_conn_init(ngx_conf_t *cf);
62
59
 
63
60
 
64
- static ngx_conf_deprecated_t ngx_conf_deprecated_limit_zone = {
65
- ngx_conf_deprecated, "limit_zone", "limit_conn_zone"
66
- };
67
-
68
-
69
61
  static ngx_conf_enum_t ngx_http_limit_conn_log_levels[] = {
70
62
  { ngx_string("info"), NGX_LOG_INFO },
71
63
  { ngx_string("notice"), NGX_LOG_NOTICE },
@@ -89,13 +81,6 @@ static ngx_command_t ngx_http_limit_conn_commands[] = {
89
81
  0,
90
82
  NULL },
91
83
 
92
- { ngx_string("limit_zone"),
93
- NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE3,
94
- ngx_http_limit_zone,
95
- 0,
96
- 0,
97
- NULL },
98
-
99
84
  { ngx_string("limit_conn"),
100
85
  NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
101
86
  ngx_http_limit_conn,
@@ -155,13 +140,13 @@ ngx_module_t ngx_http_limit_conn_module = {
155
140
  static ngx_int_t
156
141
  ngx_http_limit_conn_handler(ngx_http_request_t *r)
157
142
  {
158
- size_t len, n;
143
+ size_t n;
159
144
  uint32_t hash;
145
+ ngx_str_t key;
160
146
  ngx_uint_t i;
161
147
  ngx_slab_pool_t *shpool;
162
148
  ngx_rbtree_node_t *node;
163
149
  ngx_pool_cleanup_t *cln;
164
- ngx_http_variable_value_t *vv;
165
150
  ngx_http_limit_conn_ctx_t *ctx;
166
151
  ngx_http_limit_conn_node_t *lc;
167
152
  ngx_http_limit_conn_conf_t *lccf;
@@ -178,41 +163,37 @@ ngx_http_limit_conn_handler(ngx_http_request_t *r)
178
163
  for (i = 0; i < lccf->limits.nelts; i++) {
179
164
  ctx = limits[i].shm_zone->data;
180
165
 
181
- vv = ngx_http_get_indexed_variable(r, ctx->index);
182
-
183
- if (vv == NULL || vv->not_found) {
184
- continue;
166
+ if (ngx_http_complex_value(r, &ctx->key, &key) != NGX_OK) {
167
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
185
168
  }
186
169
 
187
- len = vv->len;
188
-
189
- if (len == 0) {
170
+ if (key.len == 0) {
190
171
  continue;
191
172
  }
192
173
 
193
- if (len > 255) {
174
+ if (key.len > 255) {
194
175
  ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
195
- "the value of the \"%V\" variable "
196
- "is more than 255 bytes: \"%v\"",
197
- &ctx->var, vv);
176
+ "the value of the \"%V\" key "
177
+ "is more than 255 bytes: \"%V\"",
178
+ &ctx->key.value, &key);
198
179
  continue;
199
180
  }
200
181
 
201
182
  r->main->limit_conn_set = 1;
202
183
 
203
- hash = ngx_crc32_short(vv->data, len);
184
+ hash = ngx_crc32_short(key.data, key.len);
204
185
 
205
186
  shpool = (ngx_slab_pool_t *) limits[i].shm_zone->shm.addr;
206
187
 
207
188
  ngx_shmtx_lock(&shpool->mutex);
208
189
 
209
- node = ngx_http_limit_conn_lookup(ctx->rbtree, vv, hash);
190
+ node = ngx_http_limit_conn_lookup(ctx->rbtree, &key, hash);
210
191
 
211
192
  if (node == NULL) {
212
193
 
213
194
  n = offsetof(ngx_rbtree_node_t, color)
214
195
  + offsetof(ngx_http_limit_conn_node_t, data)
215
- + len;
196
+ + key.len;
216
197
 
217
198
  node = ngx_slab_alloc_locked(shpool, n);
218
199
 
@@ -225,9 +206,9 @@ ngx_http_limit_conn_handler(ngx_http_request_t *r)
225
206
  lc = (ngx_http_limit_conn_node_t *) &node->color;
226
207
 
227
208
  node->key = hash;
228
- lc->len = (u_char) len;
209
+ lc->len = (u_char) key.len;
229
210
  lc->conn = 1;
230
- ngx_memcpy(lc->data, vv->data, len);
211
+ ngx_memcpy(lc->data, key.data, key.len);
231
212
 
232
213
  ngx_rbtree_insert(ctx->rbtree, node);
233
214
 
@@ -314,8 +295,7 @@ ngx_http_limit_conn_rbtree_insert_value(ngx_rbtree_node_t *temp,
314
295
 
315
296
 
316
297
  static ngx_rbtree_node_t *
317
- ngx_http_limit_conn_lookup(ngx_rbtree_t *rbtree, ngx_http_variable_value_t *vv,
318
- uint32_t hash)
298
+ ngx_http_limit_conn_lookup(ngx_rbtree_t *rbtree, ngx_str_t *key, uint32_t hash)
319
299
  {
320
300
  ngx_int_t rc;
321
301
  ngx_rbtree_node_t *node, *sentinel;
@@ -340,8 +320,8 @@ ngx_http_limit_conn_lookup(ngx_rbtree_t *rbtree, ngx_http_variable_value_t *vv,
340
320
 
341
321
  lcn = (ngx_http_limit_conn_node_t *) &node->color;
342
322
 
343
- rc = ngx_memn2cmp(vv->data, lcn->data,
344
- (size_t) vv->len, (size_t) lcn->len);
323
+ rc = ngx_memn2cmp(key->data, lcn->data, key->len, (size_t) lcn->len);
324
+
345
325
  if (rc == 0) {
346
326
  return node;
347
327
  }
@@ -413,11 +393,16 @@ ngx_http_limit_conn_init_zone(ngx_shm_zone_t *shm_zone, void *data)
413
393
  ctx = shm_zone->data;
414
394
 
415
395
  if (octx) {
416
- if (ngx_strcmp(ctx->var.data, octx->var.data) != 0) {
396
+ if (ctx->key.value.len != octx->key.value.len
397
+ || ngx_strncmp(ctx->key.value.data, octx->key.value.data,
398
+ ctx->key.value.len)
399
+ != 0)
400
+ {
417
401
  ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
418
- "limit_conn_zone \"%V\" uses the \"%V\" variable "
419
- "while previously it used the \"%V\" variable",
420
- &shm_zone->shm.name, &ctx->var, &octx->var);
402
+ "limit_conn_zone \"%V\" uses the \"%V\" key "
403
+ "while previously it used the \"%V\" key",
404
+ &shm_zone->shm.name, &ctx->key.value,
405
+ &octx->key.value);
421
406
  return NGX_ERROR;
422
407
  }
423
408
 
@@ -507,20 +492,35 @@ ngx_http_limit_conn_merge_conf(ngx_conf_t *cf, void *parent, void *child)
507
492
  static char *
508
493
  ngx_http_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
509
494
  {
510
- u_char *p;
511
- ssize_t size;
512
- ngx_str_t *value, name, s;
513
- ngx_uint_t i;
514
- ngx_shm_zone_t *shm_zone;
515
- ngx_http_limit_conn_ctx_t *ctx;
495
+ u_char *p;
496
+ ssize_t size;
497
+ ngx_str_t *value, name, s;
498
+ ngx_uint_t i;
499
+ ngx_shm_zone_t *shm_zone;
500
+ ngx_http_limit_conn_ctx_t *ctx;
501
+ ngx_http_compile_complex_value_t ccv;
516
502
 
517
503
  value = cf->args->elts;
518
504
 
519
- ctx = NULL;
505
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_conn_ctx_t));
506
+ if (ctx == NULL) {
507
+ return NGX_CONF_ERROR;
508
+ }
509
+
510
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
511
+
512
+ ccv.cf = cf;
513
+ ccv.value = &value[1];
514
+ ccv.complex_value = &ctx->key;
515
+
516
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
517
+ return NGX_CONF_ERROR;
518
+ }
519
+
520
520
  size = 0;
521
521
  name.len = 0;
522
522
 
523
- for (i = 1; i < cf->args->nelts; i++) {
523
+ for (i = 2; i < cf->args->nelts; i++) {
524
524
 
525
525
  if (ngx_strncmp(value[i].data, "zone=", 5) == 0) {
526
526
 
@@ -556,26 +556,6 @@ ngx_http_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
556
556
  continue;
557
557
  }
558
558
 
559
- if (value[i].data[0] == '$') {
560
-
561
- value[i].len--;
562
- value[i].data++;
563
-
564
- ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_conn_ctx_t));
565
- if (ctx == NULL) {
566
- return NGX_CONF_ERROR;
567
- }
568
-
569
- ctx->index = ngx_http_get_variable_index(cf, &value[i]);
570
- if (ctx->index == NGX_ERROR) {
571
- return NGX_CONF_ERROR;
572
- }
573
-
574
- ctx->var = value[i];
575
-
576
- continue;
577
- }
578
-
579
559
  ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
580
560
  "invalid parameter \"%V\"", &value[i]);
581
561
  return NGX_CONF_ERROR;
@@ -588,13 +568,6 @@ ngx_http_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
588
568
  return NGX_CONF_ERROR;
589
569
  }
590
570
 
591
- if (ctx == NULL) {
592
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
593
- "no variable is defined for %V \"%V\"",
594
- &cmd->name, &name);
595
- return NGX_CONF_ERROR;
596
- }
597
-
598
571
  shm_zone = ngx_shared_memory_add(cf, &name, size,
599
572
  &ngx_http_limit_conn_module);
600
573
  if (shm_zone == NULL) {
@@ -605,78 +578,8 @@ ngx_http_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
605
578
  ctx = shm_zone->data;
606
579
 
607
580
  ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
608
- "%V \"%V\" is already bound to variable \"%V\"",
609
- &cmd->name, &name, &ctx->var);
610
- return NGX_CONF_ERROR;
611
- }
612
-
613
- shm_zone->init = ngx_http_limit_conn_init_zone;
614
- shm_zone->data = ctx;
615
-
616
- return NGX_CONF_OK;
617
- }
618
-
619
-
620
- static char *
621
- ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
622
- {
623
- ssize_t n;
624
- ngx_str_t *value;
625
- ngx_shm_zone_t *shm_zone;
626
- ngx_http_limit_conn_ctx_t *ctx;
627
-
628
- ngx_conf_deprecated(cf, &ngx_conf_deprecated_limit_zone, NULL);
629
-
630
- value = cf->args->elts;
631
-
632
- if (value[2].data[0] != '$') {
633
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
634
- "invalid variable name \"%V\"", &value[2]);
635
- return NGX_CONF_ERROR;
636
- }
637
-
638
- value[2].len--;
639
- value[2].data++;
640
-
641
- ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_conn_ctx_t));
642
- if (ctx == NULL) {
643
- return NGX_CONF_ERROR;
644
- }
645
-
646
- ctx->index = ngx_http_get_variable_index(cf, &value[2]);
647
- if (ctx->index == NGX_ERROR) {
648
- return NGX_CONF_ERROR;
649
- }
650
-
651
- ctx->var = value[2];
652
-
653
- n = ngx_parse_size(&value[3]);
654
-
655
- if (n == NGX_ERROR) {
656
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
657
- "invalid size of limit_zone \"%V\"", &value[3]);
658
- return NGX_CONF_ERROR;
659
- }
660
-
661
- if (n < (ngx_int_t) (8 * ngx_pagesize)) {
662
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
663
- "limit_zone \"%V\" is too small", &value[1]);
664
- return NGX_CONF_ERROR;
665
- }
666
-
667
-
668
- shm_zone = ngx_shared_memory_add(cf, &value[1], n,
669
- &ngx_http_limit_conn_module);
670
- if (shm_zone == NULL) {
671
- return NGX_CONF_ERROR;
672
- }
673
-
674
- if (shm_zone->data) {
675
- ctx = shm_zone->data;
676
-
677
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
678
- "limit_zone \"%V\" is already bound to variable \"%V\"",
679
- &value[1], &ctx->var);
581
+ "%V \"%V\" is already bound to key \"%V\"",
582
+ &cmd->name, &name, &ctx->key.value);
680
583
  return NGX_CONF_ERROR;
681
584
  }
682
585
 
@@ -35,8 +35,7 @@ typedef struct {
35
35
  ngx_slab_pool_t *shpool;
36
36
  /* integer value, 1 corresponds to 0.001 r/s */
37
37
  ngx_uint_t rate;
38
- ngx_int_t index;
39
- ngx_str_t var;
38
+ ngx_http_complex_value_t key;
40
39
  ngx_http_limit_req_node_t *node;
41
40
  } ngx_http_limit_req_ctx_t;
42
41
 
@@ -59,8 +58,7 @@ typedef struct {
59
58
 
60
59
  static void ngx_http_limit_req_delay(ngx_http_request_t *r);
61
60
  static ngx_int_t ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit,
62
- ngx_uint_t hash, u_char *data, size_t len, ngx_uint_t *ep,
63
- ngx_uint_t account);
61
+ ngx_uint_t hash, ngx_str_t *key, ngx_uint_t *ep, ngx_uint_t account);
64
62
  static ngx_msec_t ngx_http_limit_req_account(ngx_http_limit_req_limit_t *limits,
65
63
  ngx_uint_t n, ngx_uint_t *ep, ngx_http_limit_req_limit_t **limit);
66
64
  static void ngx_http_limit_req_expire(ngx_http_limit_req_ctx_t *ctx,
@@ -158,12 +156,11 @@ ngx_module_t ngx_http_limit_req_module = {
158
156
  static ngx_int_t
159
157
  ngx_http_limit_req_handler(ngx_http_request_t *r)
160
158
  {
161
- size_t len;
162
159
  uint32_t hash;
160
+ ngx_str_t key;
163
161
  ngx_int_t rc;
164
162
  ngx_uint_t n, excess;
165
163
  ngx_msec_t delay;
166
- ngx_http_variable_value_t *vv;
167
164
  ngx_http_limit_req_ctx_t *ctx;
168
165
  ngx_http_limit_req_conf_t *lrcf;
169
166
  ngx_http_limit_req_limit_t *limit, *limits;
@@ -189,31 +186,27 @@ ngx_http_limit_req_handler(ngx_http_request_t *r)
189
186
 
190
187
  ctx = limit->shm_zone->data;
191
188
 
192
- vv = ngx_http_get_indexed_variable(r, ctx->index);
193
-
194
- if (vv == NULL || vv->not_found) {
195
- continue;
189
+ if (ngx_http_complex_value(r, &ctx->key, &key) != NGX_OK) {
190
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
196
191
  }
197
192
 
198
- len = vv->len;
199
-
200
- if (len == 0) {
193
+ if (key.len == 0) {
201
194
  continue;
202
195
  }
203
196
 
204
- if (len > 65535) {
197
+ if (key.len > 65535) {
205
198
  ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
206
- "the value of the \"%V\" variable "
207
- "is more than 65535 bytes: \"%v\"",
208
- &ctx->var, vv);
199
+ "the value of the \"%V\" key "
200
+ "is more than 65535 bytes: \"%V\"",
201
+ &ctx->key.value, &key);
209
202
  continue;
210
203
  }
211
204
 
212
- hash = ngx_crc32_short(vv->data, len);
205
+ hash = ngx_crc32_short(key.data, key.len);
213
206
 
214
207
  ngx_shmtx_lock(&ctx->shpool->mutex);
215
208
 
216
- rc = ngx_http_limit_req_lookup(limit, hash, vv->data, len, &excess,
209
+ rc = ngx_http_limit_req_lookup(limit, hash, &key, &excess,
217
210
  (n == lrcf->limits.nelts - 1));
218
211
 
219
212
  ngx_shmtx_unlock(&ctx->shpool->mutex);
@@ -365,7 +358,7 @@ ngx_http_limit_req_rbtree_insert_value(ngx_rbtree_node_t *temp,
365
358
 
366
359
  static ngx_int_t
367
360
  ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, ngx_uint_t hash,
368
- u_char *data, size_t len, ngx_uint_t *ep, ngx_uint_t account)
361
+ ngx_str_t *key, ngx_uint_t *ep, ngx_uint_t account)
369
362
  {
370
363
  size_t size;
371
364
  ngx_int_t rc, excess;
@@ -400,7 +393,7 @@ ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, ngx_uint_t hash,
400
393
 
401
394
  lr = (ngx_http_limit_req_node_t *) &node->color;
402
395
 
403
- rc = ngx_memn2cmp(data, lr->data, len, (size_t) lr->len);
396
+ rc = ngx_memn2cmp(key->data, lr->data, key->len, (size_t) lr->len);
404
397
 
405
398
  if (rc == 0) {
406
399
  ngx_queue_remove(&lr->queue);
@@ -440,7 +433,7 @@ ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, ngx_uint_t hash,
440
433
 
441
434
  size = offsetof(ngx_rbtree_node_t, color)
442
435
  + offsetof(ngx_http_limit_req_node_t, data)
443
- + len;
436
+ + key->len;
444
437
 
445
438
  ngx_http_limit_req_expire(ctx, 1);
446
439
 
@@ -461,10 +454,10 @@ ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, ngx_uint_t hash,
461
454
 
462
455
  lr = (ngx_http_limit_req_node_t *) &node->color;
463
456
 
464
- lr->len = (u_char) len;
457
+ lr->len = (u_short) key->len;
465
458
  lr->excess = 0;
466
459
 
467
- ngx_memcpy(lr->data, data, len);
460
+ ngx_memcpy(lr->data, key->data, key->len);
468
461
 
469
462
  ngx_rbtree_insert(&ctx->sh->rbtree, node);
470
463
 
@@ -632,11 +625,16 @@ ngx_http_limit_req_init_zone(ngx_shm_zone_t *shm_zone, void *data)
632
625
  ctx = shm_zone->data;
633
626
 
634
627
  if (octx) {
635
- if (ngx_strcmp(ctx->var.data, octx->var.data) != 0) {
628
+ if (ctx->key.value.len != octx->key.value.len
629
+ || ngx_strncmp(ctx->key.value.data, octx->key.value.data,
630
+ ctx->key.value.len)
631
+ != 0)
632
+ {
636
633
  ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
637
- "limit_req \"%V\" uses the \"%V\" variable "
638
- "while previously it used the \"%V\" variable",
639
- &shm_zone->shm.name, &ctx->var, &octx->var);
634
+ "limit_req \"%V\" uses the \"%V\" key "
635
+ "while previously it used the \"%V\" key",
636
+ &shm_zone->shm.name, &ctx->key.value,
637
+ &octx->key.value);
640
638
  return NGX_ERROR;
641
639
  }
642
640
 
@@ -731,24 +729,39 @@ ngx_http_limit_req_merge_conf(ngx_conf_t *cf, void *parent, void *child)
731
729
  static char *
732
730
  ngx_http_limit_req_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
733
731
  {
734
- u_char *p;
735
- size_t len;
736
- ssize_t size;
737
- ngx_str_t *value, name, s;
738
- ngx_int_t rate, scale;
739
- ngx_uint_t i;
740
- ngx_shm_zone_t *shm_zone;
741
- ngx_http_limit_req_ctx_t *ctx;
732
+ u_char *p;
733
+ size_t len;
734
+ ssize_t size;
735
+ ngx_str_t *value, name, s;
736
+ ngx_int_t rate, scale;
737
+ ngx_uint_t i;
738
+ ngx_shm_zone_t *shm_zone;
739
+ ngx_http_limit_req_ctx_t *ctx;
740
+ ngx_http_compile_complex_value_t ccv;
742
741
 
743
742
  value = cf->args->elts;
744
743
 
745
- ctx = NULL;
744
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_req_ctx_t));
745
+ if (ctx == NULL) {
746
+ return NGX_CONF_ERROR;
747
+ }
748
+
749
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
750
+
751
+ ccv.cf = cf;
752
+ ccv.value = &value[1];
753
+ ccv.complex_value = &ctx->key;
754
+
755
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
756
+ return NGX_CONF_ERROR;
757
+ }
758
+
746
759
  size = 0;
747
760
  rate = 1;
748
761
  scale = 1;
749
762
  name.len = 0;
750
763
 
751
- for (i = 1; i < cf->args->nelts; i++) {
764
+ for (i = 2; i < cf->args->nelts; i++) {
752
765
 
753
766
  if (ngx_strncmp(value[i].data, "zone=", 5) == 0) {
754
767
 
@@ -808,26 +821,6 @@ ngx_http_limit_req_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
808
821
  continue;
809
822
  }
810
823
 
811
- if (value[i].data[0] == '$') {
812
-
813
- value[i].len--;
814
- value[i].data++;
815
-
816
- ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_req_ctx_t));
817
- if (ctx == NULL) {
818
- return NGX_CONF_ERROR;
819
- }
820
-
821
- ctx->index = ngx_http_get_variable_index(cf, &value[i]);
822
- if (ctx->index == NGX_ERROR) {
823
- return NGX_CONF_ERROR;
824
- }
825
-
826
- ctx->var = value[i];
827
-
828
- continue;
829
- }
830
-
831
824
  ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
832
825
  "invalid parameter \"%V\"", &value[i]);
833
826
  return NGX_CONF_ERROR;
@@ -840,13 +833,6 @@ ngx_http_limit_req_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
840
833
  return NGX_CONF_ERROR;
841
834
  }
842
835
 
843
- if (ctx == NULL) {
844
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
845
- "no variable is defined for %V \"%V\"",
846
- &cmd->name, &name);
847
- return NGX_CONF_ERROR;
848
- }
849
-
850
836
  ctx->rate = rate * 1000 / scale;
851
837
 
852
838
  shm_zone = ngx_shared_memory_add(cf, &name, size,
@@ -859,8 +845,8 @@ ngx_http_limit_req_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
859
845
  ctx = shm_zone->data;
860
846
 
861
847
  ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
862
- "%V \"%V\" is already bound to variable \"%V\"",
863
- &cmd->name, &name, &ctx->var);
848
+ "%V \"%V\" is already bound to key \"%V\"",
849
+ &cmd->name, &name, &ctx->key.value);
864
850
  return NGX_CONF_ERROR;
865
851
  }
866
852