nginxtra 1.2.1.3 → 1.2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. data/VERSION +1 -1
  2. data/bin/nginxtra +1 -1
  3. data/src/nginx/CHANGES +60 -0
  4. data/src/nginx/CHANGES.ru +57 -0
  5. data/src/nginx/auto/{endianess → endianness} +5 -5
  6. data/src/nginx/auto/lib/google-perftools/conf +16 -0
  7. data/src/nginx/auto/modules +10 -0
  8. data/src/nginx/auto/options +3 -0
  9. data/src/nginx/auto/os/conf +2 -0
  10. data/src/nginx/auto/sources +5 -0
  11. data/src/nginx/auto/unix +1 -1
  12. data/src/nginx/src/core/nginx.h +2 -2
  13. data/src/nginx/src/core/ngx_hash.c +13 -11
  14. data/src/nginx/src/core/ngx_inet.c +32 -31
  15. data/src/nginx/src/core/ngx_regex.c +3 -3
  16. data/src/nginx/src/core/ngx_regex.h +2 -2
  17. data/src/nginx/src/core/ngx_resolver.c +22 -16
  18. data/src/nginx/src/event/ngx_event_openssl.c +18 -1
  19. data/src/nginx/src/http/modules/ngx_http_geo_module.c +1 -1
  20. data/src/nginx/src/http/modules/ngx_http_geoip_module.c +15 -4
  21. data/src/nginx/src/http/modules/ngx_http_log_module.c +3 -6
  22. data/src/nginx/src/http/modules/ngx_http_mp4_module.c +18 -1
  23. data/src/nginx/src/http/modules/ngx_http_rewrite_module.c +6 -0
  24. data/src/nginx/src/http/modules/ngx_http_split_clients_module.c +7 -0
  25. data/src/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +44 -17
  26. data/src/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +4 -29
  27. data/src/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c +402 -0
  28. data/src/nginx/src/http/modules/ngx_http_xslt_filter_module.c +2 -2
  29. data/src/nginx/src/http/modules/perl/nginx.pm +1 -1
  30. data/src/nginx/src/http/modules/perl/nginx.xs +1 -1
  31. data/src/nginx/src/http/ngx_http_core_module.c +1 -1
  32. data/src/nginx/src/http/ngx_http_header_filter_module.c +2 -2
  33. data/src/nginx/src/http/ngx_http_request.c +1 -1
  34. data/src/nginx/src/http/ngx_http_request.h +8 -1
  35. data/src/nginx/src/http/ngx_http_upstream.c +15 -1
  36. data/src/nginx/src/http/ngx_http_upstream_round_robin.c +11 -1
  37. data/src/nginx/src/http/ngx_http_upstream_round_robin.h +5 -1
  38. data/src/nginx/src/http/ngx_http_variables.c +49 -3
  39. data/src/nginx/src/os/unix/ngx_errno.c +1 -1
  40. data/src/nginx/src/os/unix/ngx_errno.h +1 -1
  41. data/src/nginx/src/os/unix/ngx_freebsd_init.c +2 -2
  42. data/src/nginx/src/os/unix/ngx_posix_config.h +1 -0
  43. data/src/nginx/src/os/unix/ngx_process_cycle.c +4 -0
  44. metadata +5 -4
@@ -28,7 +28,7 @@ typedef struct {
28
28
  } ngx_http_geoip_var_t;
29
29
 
30
30
 
31
- typedef const char *(*ngx_http_geoip_variable_handler_pt)(GeoIP *, u_long addr);
31
+ typedef char *(*ngx_http_geoip_variable_handler_pt)(GeoIP *, u_long addr);
32
32
 
33
33
  static u_long ngx_http_geoip_addr(ngx_http_request_t *r,
34
34
  ngx_http_geoip_conf_t *gcf);
@@ -291,7 +291,8 @@ ngx_http_geoip_org_variable(ngx_http_request_t *r,
291
291
  ngx_http_geoip_variable_handler_pt handler =
292
292
  (ngx_http_geoip_variable_handler_pt) data;
293
293
 
294
- const char *val;
294
+ size_t len;
295
+ char *val;
295
296
  ngx_http_geoip_conf_t *gcf;
296
297
 
297
298
  gcf = ngx_http_get_module_main_conf(r, ngx_http_geoip_module);
@@ -306,11 +307,21 @@ ngx_http_geoip_org_variable(ngx_http_request_t *r,
306
307
  goto not_found;
307
308
  }
308
309
 
309
- v->len = ngx_strlen(val);
310
+ len = ngx_strlen(val);
311
+ v->data = ngx_pnalloc(r->pool, len);
312
+ if (v->data == NULL) {
313
+ ngx_free(val);
314
+ return NGX_ERROR;
315
+ }
316
+
317
+ ngx_memcpy(v->data, val, len);
318
+
319
+ v->len = len;
310
320
  v->valid = 1;
311
321
  v->no_cacheable = 0;
312
322
  v->not_found = 0;
313
- v->data = (u_char *) val;
323
+
324
+ ngx_free(val);
314
325
 
315
326
  return NGX_OK;
316
327
 
@@ -205,7 +205,7 @@ static ngx_http_log_var_t ngx_http_log_vars[] = {
205
205
  { ngx_string("msec"), NGX_TIME_T_LEN + 4, ngx_http_log_msec },
206
206
  { ngx_string("request_time"), NGX_TIME_T_LEN + 4,
207
207
  ngx_http_log_request_time },
208
- { ngx_string("status"), 3, ngx_http_log_status },
208
+ { ngx_string("status"), NGX_INT_T_LEN, ngx_http_log_status },
209
209
  { ngx_string("bytes_sent"), NGX_OFF_T_LEN, ngx_http_log_bytes_sent },
210
210
  { ngx_string("body_bytes_sent"), NGX_OFF_T_LEN,
211
211
  ngx_http_log_body_bytes_sent },
@@ -584,16 +584,13 @@ ngx_http_log_status(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
584
584
  status = r->headers_out.status;
585
585
 
586
586
  } else if (r->http_version == NGX_HTTP_VERSION_9) {
587
- *buf++ = '0';
588
- *buf++ = '0';
589
- *buf++ = '9';
590
- return buf;
587
+ status = 9;
591
588
 
592
589
  } else {
593
590
  status = 0;
594
591
  }
595
592
 
596
- return ngx_sprintf(buf, "%ui", status);
593
+ return ngx_sprintf(buf, "%03ui", status);
597
594
  }
598
595
 
599
596
 
@@ -1024,6 +1024,10 @@ ngx_http_mp4_read_moov_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
1024
1024
  + NGX_HTTP_MP4_MOOV_BUFFER_EXCESS * no_mdat;
1025
1025
  }
1026
1026
 
1027
+ if (ngx_http_mp4_read(mp4, (size_t) atom_data_size) != NGX_OK) {
1028
+ return NGX_ERROR;
1029
+ }
1030
+
1027
1031
  mp4->trak.elts = &mp4->traks;
1028
1032
  mp4->trak.size = sizeof(ngx_http_mp4_trak_t);
1029
1033
  mp4->trak.nalloc = 2;
@@ -1044,6 +1048,12 @@ ngx_http_mp4_read_moov_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
1044
1048
  mp4->buffer_start = mp4->buffer_pos;
1045
1049
  mp4->buffer_size = NGX_HTTP_MP4_MOOV_BUFFER_EXCESS;
1046
1050
 
1051
+ if (mp4->buffer_start + mp4->buffer_size > mp4->buffer_end) {
1052
+ mp4->buffer = NULL;
1053
+ mp4->buffer_pos = NULL;
1054
+ mp4->buffer_end = NULL;
1055
+ }
1056
+
1047
1057
  } else {
1048
1058
  /* skip atoms after moov atom */
1049
1059
  mp4->offset = mp4->end;
@@ -2488,7 +2498,13 @@ found:
2488
2498
 
2489
2499
  ngx_mp4_set_32value(entry->chunk, 1);
2490
2500
 
2491
- if (trak->chunk_samples) {
2501
+ if (trak->chunk_samples && next_chunk - trak->start_chunk == 2) {
2502
+
2503
+ /* last chunk in the entry */
2504
+
2505
+ ngx_mp4_set_32value(entry->samples, samples - trak->chunk_samples);
2506
+
2507
+ } else if (trak->chunk_samples) {
2492
2508
 
2493
2509
  first = &trak->stsc_chunk_entry;
2494
2510
  ngx_mp4_set_32value(first->chunk, 1);
@@ -2504,6 +2520,7 @@ found:
2504
2520
 
2505
2521
  ngx_mp4_set_32value(entry->chunk, 2);
2506
2522
 
2523
+ entries++;
2507
2524
  atom_size += sizeof(ngx_mp4_stsc_entry_t);
2508
2525
  }
2509
2526
 
@@ -485,6 +485,12 @@ ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
485
485
 
486
486
  } else {
487
487
 
488
+ if (ret->status > 999) {
489
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
490
+ "invalid return code \"%V\"", &value[1]);
491
+ return NGX_CONF_ERROR;
492
+ }
493
+
488
494
  if (cf->args->nelts == 2) {
489
495
  return NGX_CONF_OK;
490
496
  }
@@ -138,6 +138,13 @@ ngx_conf_split_clients_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
138
138
  }
139
139
 
140
140
  name = value[2];
141
+
142
+ if (name.len < 2 || name.data[0] != '$') {
143
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
144
+ "invalid variable name \"%V\"", &name);
145
+ return NGX_CONF_ERROR;
146
+ }
147
+
141
148
  name.len--;
142
149
  name.data++;
143
150
 
@@ -16,7 +16,8 @@ typedef struct {
16
16
 
17
17
  ngx_uint_t hash;
18
18
 
19
- u_char addr[3];
19
+ u_char addrlen;
20
+ u_char *addr;
20
21
 
21
22
  u_char tries;
22
23
 
@@ -76,7 +77,10 @@ ngx_module_t ngx_http_upstream_ip_hash_module = {
76
77
  };
77
78
 
78
79
 
79
- ngx_int_t
80
+ static u_char ngx_http_upstream_ip_hash_pseudo_addr[3];
81
+
82
+
83
+ static ngx_int_t
80
84
  ngx_http_upstream_init_ip_hash(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *us)
81
85
  {
82
86
  if (ngx_http_upstream_init_round_robin(cf, us) != NGX_OK) {
@@ -93,8 +97,10 @@ static ngx_int_t
93
97
  ngx_http_upstream_init_ip_hash_peer(ngx_http_request_t *r,
94
98
  ngx_http_upstream_srv_conf_t *us)
95
99
  {
96
- u_char *p;
97
100
  struct sockaddr_in *sin;
101
+ #if (NGX_HAVE_INET6)
102
+ struct sockaddr_in6 *sin6;
103
+ #endif
98
104
  ngx_http_upstream_ip_hash_peer_data_t *iphp;
99
105
 
100
106
  iphp = ngx_palloc(r->pool, sizeof(ngx_http_upstream_ip_hash_peer_data_t));
@@ -110,20 +116,25 @@ ngx_http_upstream_init_ip_hash_peer(ngx_http_request_t *r,
110
116
 
111
117
  r->upstream->peer.get = ngx_http_upstream_get_ip_hash_peer;
112
118
 
113
- /* AF_INET only */
114
-
115
- if (r->connection->sockaddr->sa_family == AF_INET) {
119
+ switch (r->connection->sockaddr->sa_family) {
116
120
 
121
+ case AF_INET:
117
122
  sin = (struct sockaddr_in *) r->connection->sockaddr;
118
- p = (u_char *) &sin->sin_addr.s_addr;
119
- iphp->addr[0] = p[0];
120
- iphp->addr[1] = p[1];
121
- iphp->addr[2] = p[2];
122
-
123
- } else {
124
- iphp->addr[0] = 0;
125
- iphp->addr[1] = 0;
126
- iphp->addr[2] = 0;
123
+ iphp->addr = (u_char *) &sin->sin_addr.s_addr;
124
+ iphp->addrlen = 3;
125
+ break;
126
+
127
+ #if (NGX_HAVE_INET6)
128
+ case AF_INET6:
129
+ sin6 = (struct sockaddr_in6 *) r->connection->sockaddr;
130
+ iphp->addr = (u_char *) &sin6->sin6_addr.s6_addr;
131
+ iphp->addrlen = 16;
132
+ break;
133
+ #endif
134
+
135
+ default:
136
+ iphp->addr = ngx_http_upstream_ip_hash_pseudo_addr;
137
+ iphp->addrlen = 3;
127
138
  }
128
139
 
129
140
  iphp->hash = 89;
@@ -140,6 +151,7 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
140
151
  ngx_http_upstream_ip_hash_peer_data_t *iphp = data;
141
152
 
142
153
  time_t now;
154
+ ngx_int_t w;
143
155
  uintptr_t m;
144
156
  ngx_uint_t i, n, p, hash;
145
157
  ngx_http_upstream_rr_peer_t *peer;
@@ -162,11 +174,25 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
162
174
 
163
175
  for ( ;; ) {
164
176
 
165
- for (i = 0; i < 3; i++) {
177
+ for (i = 0; i < iphp->addrlen; i++) {
166
178
  hash = (hash * 113 + iphp->addr[i]) % 6271;
167
179
  }
168
180
 
169
- p = hash % iphp->rrp.peers->number;
181
+ if (!iphp->rrp.peers->weighted) {
182
+ p = hash % iphp->rrp.peers->number;
183
+
184
+ } else {
185
+ w = hash % iphp->rrp.peers->total_weight;
186
+
187
+ for (i = 0; i < iphp->rrp.peers->number; i++) {
188
+ w -= iphp->rrp.peers->peer[i].weight;
189
+ if (w < 0) {
190
+ break;
191
+ }
192
+ }
193
+
194
+ p = i;
195
+ }
170
196
 
171
197
  n = p / (8 * sizeof(uintptr_t));
172
198
  m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t));
@@ -229,6 +255,7 @@ ngx_http_upstream_ip_hash(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
229
255
  uscf->peer.init_upstream = ngx_http_upstream_init_ip_hash;
230
256
 
231
257
  uscf->flags = NGX_HTTP_UPSTREAM_CREATE
258
+ |NGX_HTTP_UPSTREAM_WEIGHT
232
259
  |NGX_HTTP_UPSTREAM_MAX_FAILS
233
260
  |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT
234
261
  |NGX_HTTP_UPSTREAM_DOWN;
@@ -12,7 +12,6 @@
12
12
 
13
13
  typedef struct {
14
14
  ngx_uint_t max_cached;
15
- ngx_uint_t single; /* unsigned:1 */
16
15
 
17
16
  ngx_queue_t cache;
18
17
  ngx_queue_t free;
@@ -223,36 +222,11 @@ ngx_http_upstream_get_keepalive_peer(ngx_peer_connection_t *pc, void *data)
223
222
 
224
223
  kp->failed = 0;
225
224
 
226
- /* single pool of cached connections */
227
-
228
- if (kp->conf->single && !ngx_queue_empty(&kp->conf->cache)) {
229
-
230
- q = ngx_queue_head(&kp->conf->cache);
231
-
232
- item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue);
233
- c = item->connection;
234
-
235
- ngx_queue_remove(q);
236
- ngx_queue_insert_head(&kp->conf->free, q);
237
-
238
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
239
- "get keepalive peer: using connection %p", c);
240
-
241
- c->idle = 0;
242
- c->log = pc->log;
243
- c->read->log = pc->log;
244
- c->write->log = pc->log;
245
- c->pool->log = pc->log;
246
-
247
- pc->connection = c;
248
- pc->cached = 1;
249
-
250
- return NGX_DONE;
251
- }
225
+ /* ask balancer */
252
226
 
253
227
  rc = kp->original_get_peer(pc, kp->data);
254
228
 
255
- if (kp->conf->single || rc != NGX_OK) {
229
+ if (rc != NGX_OK) {
256
230
  return rc;
257
231
  }
258
232
 
@@ -552,7 +526,8 @@ ngx_http_upstream_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
552
526
  for (i = 2; i < cf->args->nelts; i++) {
553
527
 
554
528
  if (ngx_strcmp(value[i].data, "single") == 0) {
555
- kcf->single = 1;
529
+ ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
530
+ "the \"single\" parameter is deprecated");
556
531
  continue;
557
532
  }
558
533