nginxtra 1.2.8.8 → 1.4.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/bin/nginxtra +1 -1
  2. data/bin/nginxtra_rails +1 -1
  3. data/lib/nginxtra/version.rb +1 -1
  4. data/vendor/nginx/CHANGES +202 -63
  5. data/vendor/nginx/CHANGES.ru +208 -66
  6. data/vendor/nginx/auto/lib/md5/conf +3 -3
  7. data/vendor/nginx/auto/lib/perl/conf +3 -1
  8. data/vendor/nginx/auto/lib/perl/make +21 -16
  9. data/vendor/nginx/auto/lib/sha1/conf +1 -1
  10. data/vendor/nginx/auto/modules +25 -4
  11. data/vendor/nginx/auto/options +7 -1
  12. data/vendor/nginx/auto/sources +15 -1
  13. data/vendor/nginx/auto/unix +14 -0
  14. data/vendor/nginx/src/core/nginx.h +2 -2
  15. data/vendor/nginx/src/core/ngx_array.c +1 -7
  16. data/vendor/nginx/src/core/ngx_array.h +2 -2
  17. data/vendor/nginx/src/core/ngx_connection.c +13 -7
  18. data/vendor/nginx/src/core/ngx_connection.h +1 -2
  19. data/vendor/nginx/src/core/ngx_core.h +1 -2
  20. data/vendor/nginx/src/core/ngx_crypt.c +37 -0
  21. data/vendor/nginx/src/core/ngx_cycle.h +1 -1
  22. data/vendor/nginx/src/core/ngx_inet.c +219 -48
  23. data/vendor/nginx/src/core/ngx_inet.h +1 -1
  24. data/vendor/nginx/src/event/modules/ngx_devpoll_module.c +7 -1
  25. data/vendor/nginx/src/event/modules/ngx_eventport_module.c +1 -1
  26. data/vendor/nginx/src/event/ngx_event.c +5 -1
  27. data/vendor/nginx/src/event/ngx_event.h +1 -0
  28. data/vendor/nginx/src/event/ngx_event_connect.c +1 -1
  29. data/vendor/nginx/src/event/ngx_event_openssl.c +135 -9
  30. data/vendor/nginx/src/event/ngx_event_openssl.h +9 -0
  31. data/vendor/nginx/src/event/ngx_event_openssl_stapling.c +1749 -0
  32. data/vendor/nginx/src/http/modules/ngx_http_addition_filter_module.c +1 -0
  33. data/vendor/nginx/src/http/modules/ngx_http_chunked_filter_module.c +1 -0
  34. data/vendor/nginx/src/http/modules/ngx_http_fastcgi_module.c +5 -0
  35. data/vendor/nginx/src/http/modules/ngx_http_flv_module.c +4 -0
  36. data/vendor/nginx/src/http/modules/ngx_http_geo_module.c +7 -8
  37. data/vendor/nginx/src/http/modules/ngx_http_geoip_module.c +10 -12
  38. data/vendor/nginx/src/http/modules/ngx_http_gunzip_filter_module.c +677 -0
  39. data/vendor/nginx/src/http/modules/ngx_http_gzip_filter_module.c +3 -0
  40. data/vendor/nginx/src/http/modules/ngx_http_gzip_static_module.c +36 -10
  41. data/vendor/nginx/src/http/modules/ngx_http_headers_filter_module.c +31 -13
  42. data/vendor/nginx/src/http/modules/ngx_http_image_filter_module.c +13 -0
  43. data/vendor/nginx/src/http/modules/ngx_http_limit_conn_module.c +18 -2
  44. data/vendor/nginx/src/http/modules/ngx_http_limit_req_module.c +19 -2
  45. data/vendor/nginx/src/http/modules/ngx_http_map_module.c +1 -1
  46. data/vendor/nginx/src/http/modules/ngx_http_memcached_module.c +60 -8
  47. data/vendor/nginx/src/http/modules/ngx_http_mp4_module.c +4 -8
  48. data/vendor/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +126 -29
  49. data/vendor/nginx/src/http/modules/ngx_http_proxy_module.c +59 -301
  50. data/vendor/nginx/src/http/modules/ngx_http_range_filter_module.c +34 -6
  51. data/vendor/nginx/src/http/modules/ngx_http_realip_module.c +13 -12
  52. data/vendor/nginx/src/http/modules/ngx_http_scgi_module.c +30 -11
  53. data/vendor/nginx/src/http/modules/ngx_http_ssi_filter_module.c +1 -0
  54. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.c +155 -4
  55. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.h +6 -0
  56. data/vendor/nginx/src/http/modules/ngx_http_static_module.c +4 -0
  57. data/vendor/nginx/src/http/modules/ngx_http_stub_status_module.c +90 -3
  58. data/vendor/nginx/src/http/modules/ngx_http_sub_filter_module.c +1 -0
  59. data/vendor/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +5 -0
  60. data/vendor/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c +5 -0
  61. data/vendor/nginx/src/http/modules/ngx_http_uwsgi_module.c +14 -1
  62. data/vendor/nginx/src/http/modules/ngx_http_xslt_filter_module.c +1 -0
  63. data/vendor/nginx/src/http/modules/perl/Makefile.PL +4 -2
  64. data/vendor/nginx/src/http/modules/perl/nginx.pm +1 -1
  65. data/vendor/nginx/src/http/modules/perl/nginx.xs +36 -3
  66. data/vendor/nginx/src/http/ngx_http.c +24 -1
  67. data/vendor/nginx/src/http/ngx_http.h +26 -2
  68. data/vendor/nginx/src/http/ngx_http_core_module.c +136 -10
  69. data/vendor/nginx/src/http/ngx_http_core_module.h +37 -13
  70. data/vendor/nginx/src/http/ngx_http_header_filter_module.c +9 -2
  71. data/vendor/nginx/src/http/ngx_http_parse.c +404 -0
  72. data/vendor/nginx/src/http/ngx_http_request.c +840 -517
  73. data/vendor/nginx/src/http/ngx_http_request.h +37 -25
  74. data/vendor/nginx/src/http/ngx_http_request_body.c +585 -156
  75. data/vendor/nginx/src/http/ngx_http_spdy.c +2882 -0
  76. data/vendor/nginx/src/http/ngx_http_spdy.h +235 -0
  77. data/vendor/nginx/src/http/ngx_http_spdy_filter_module.c +999 -0
  78. data/vendor/nginx/src/http/ngx_http_spdy_module.c +351 -0
  79. data/vendor/nginx/src/http/ngx_http_spdy_module.h +36 -0
  80. data/vendor/nginx/src/http/ngx_http_special_response.c +3 -1
  81. data/vendor/nginx/src/http/ngx_http_upstream.c +415 -26
  82. data/vendor/nginx/src/http/ngx_http_upstream.h +11 -1
  83. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.c +2 -45
  84. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.h +0 -2
  85. data/vendor/nginx/src/http/ngx_http_variables.c +72 -12
  86. data/vendor/nginx/src/mail/ngx_mail.h +2 -2
  87. data/vendor/nginx/src/mail/ngx_mail_auth_http_module.c +35 -25
  88. data/vendor/nginx/src/mail/ngx_mail_core_module.c +5 -1
  89. metadata +9 -2
@@ -306,6 +306,7 @@ ngx_http_gzip_header_filter(ngx_http_request_t *r)
306
306
 
307
307
  ngx_http_clear_content_length(r);
308
308
  ngx_http_clear_accept_ranges(r);
309
+ ngx_http_clear_etag(r);
309
310
 
310
311
  return ngx_http_next_header_filter(r);
311
312
  }
@@ -619,6 +620,8 @@ ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r,
619
620
  return NGX_ERROR;
620
621
  }
621
622
 
623
+ r->connection->buffered |= NGX_HTTP_GZIP_BUFFERED;
624
+
622
625
  ctx->last_out = &ctx->out;
623
626
  ctx->crc32 = crc32(0L, Z_NULL, 0);
624
627
  ctx->flush = Z_NO_FLUSH;
@@ -10,8 +10,13 @@
10
10
  #include <ngx_http.h>
11
11
 
12
12
 
13
+ #define NGX_HTTP_GZIP_STATIC_OFF 0
14
+ #define NGX_HTTP_GZIP_STATIC_ON 1
15
+ #define NGX_HTTP_GZIP_STATIC_ALWAYS 2
16
+
17
+
13
18
  typedef struct {
14
- ngx_flag_t enable;
19
+ ngx_uint_t enable;
15
20
  } ngx_http_gzip_static_conf_t;
16
21
 
17
22
 
@@ -22,14 +27,22 @@ static char *ngx_http_gzip_static_merge_conf(ngx_conf_t *cf, void *parent,
22
27
  static ngx_int_t ngx_http_gzip_static_init(ngx_conf_t *cf);
23
28
 
24
29
 
30
+ static ngx_conf_enum_t ngx_http_gzip_static[] = {
31
+ { ngx_string("off"), NGX_HTTP_GZIP_STATIC_OFF },
32
+ { ngx_string("on"), NGX_HTTP_GZIP_STATIC_ON },
33
+ { ngx_string("always"), NGX_HTTP_GZIP_STATIC_ALWAYS },
34
+ { ngx_null_string, 0 }
35
+ };
36
+
37
+
25
38
  static ngx_command_t ngx_http_gzip_static_commands[] = {
26
39
 
27
40
  { ngx_string("gzip_static"),
28
41
  NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
29
- ngx_conf_set_flag_slot,
42
+ ngx_conf_set_enum_slot,
30
43
  NGX_HTTP_LOC_CONF_OFFSET,
31
44
  offsetof(ngx_http_gzip_static_conf_t, enable),
32
- NULL },
45
+ &ngx_http_gzip_static },
33
46
 
34
47
  ngx_null_command
35
48
  };
@@ -92,11 +105,17 @@ ngx_http_gzip_static_handler(ngx_http_request_t *r)
92
105
 
93
106
  gzcf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_static_module);
94
107
 
95
- if (!gzcf->enable) {
108
+ if (gzcf->enable == NGX_HTTP_GZIP_STATIC_OFF) {
96
109
  return NGX_DECLINED;
97
110
  }
98
111
 
99
- rc = ngx_http_gzip_ok(r);
112
+ if (gzcf->enable == NGX_HTTP_GZIP_STATIC_ON) {
113
+ rc = ngx_http_gzip_ok(r);
114
+
115
+ } else {
116
+ /* always */
117
+ rc = NGX_OK;
118
+ }
100
119
 
101
120
  clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
102
121
 
@@ -169,10 +188,12 @@ ngx_http_gzip_static_handler(ngx_http_request_t *r)
169
188
  return NGX_DECLINED;
170
189
  }
171
190
 
172
- r->gzip_vary = 1;
191
+ if (gzcf->enable == NGX_HTTP_GZIP_STATIC_ON) {
192
+ r->gzip_vary = 1;
173
193
 
174
- if (rc != NGX_OK) {
175
- return NGX_DECLINED;
194
+ if (rc != NGX_OK) {
195
+ return NGX_DECLINED;
196
+ }
176
197
  }
177
198
 
178
199
  ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "http static fd: %d", of.fd);
@@ -207,6 +228,10 @@ ngx_http_gzip_static_handler(ngx_http_request_t *r)
207
228
  r->headers_out.content_length_n = of.size;
208
229
  r->headers_out.last_modified_time = of.mtime;
209
230
 
231
+ if (ngx_http_set_etag(r) != NGX_OK) {
232
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
233
+ }
234
+
210
235
  if (ngx_http_set_content_type(r) != NGX_OK) {
211
236
  return NGX_HTTP_INTERNAL_SERVER_ERROR;
212
237
  }
@@ -270,7 +295,7 @@ ngx_http_gzip_static_create_conf(ngx_conf_t *cf)
270
295
  return NULL;
271
296
  }
272
297
 
273
- conf->enable = NGX_CONF_UNSET;
298
+ conf->enable = NGX_CONF_UNSET_UINT;
274
299
 
275
300
  return conf;
276
301
  }
@@ -282,7 +307,8 @@ ngx_http_gzip_static_merge_conf(ngx_conf_t *cf, void *parent, void *child)
282
307
  ngx_http_gzip_static_conf_t *prev = parent;
283
308
  ngx_http_gzip_static_conf_t *conf = child;
284
309
 
285
- ngx_conf_merge_value(conf->enable, prev->enable, 0);
310
+ ngx_conf_merge_uint_value(conf->enable, prev->enable,
311
+ NGX_HTTP_GZIP_STATIC_OFF);
286
312
 
287
313
  return NGX_CONF_OK;
288
314
  }
@@ -57,6 +57,8 @@ static ngx_int_t ngx_http_add_header(ngx_http_request_t *r,
57
57
  ngx_http_header_val_t *hv, ngx_str_t *value);
58
58
  static ngx_int_t ngx_http_set_last_modified(ngx_http_request_t *r,
59
59
  ngx_http_header_val_t *hv, ngx_str_t *value);
60
+ static ngx_int_t ngx_http_set_response_header(ngx_http_request_t *r,
61
+ ngx_http_header_val_t *hv, ngx_str_t *value);
60
62
 
61
63
  static void *ngx_http_headers_create_conf(ngx_conf_t *cf);
62
64
  static char *ngx_http_headers_merge_conf(ngx_conf_t *cf,
@@ -76,6 +78,10 @@ static ngx_http_set_header_t ngx_http_set_headers[] = {
76
78
  offsetof(ngx_http_headers_out_t, last_modified),
77
79
  ngx_http_set_last_modified },
78
80
 
81
+ { ngx_string("ETag"),
82
+ offsetof(ngx_http_headers_out_t, etag),
83
+ ngx_http_set_response_header },
84
+
79
85
  { ngx_null_string, 0, NULL }
80
86
  };
81
87
 
@@ -368,33 +374,45 @@ ngx_http_add_cache_control(ngx_http_request_t *r, ngx_http_header_val_t *hv,
368
374
  static ngx_int_t
369
375
  ngx_http_set_last_modified(ngx_http_request_t *r, ngx_http_header_val_t *hv,
370
376
  ngx_str_t *value)
377
+ {
378
+ if (ngx_http_set_response_header(r, hv, value) != NGX_OK) {
379
+ return NGX_ERROR;
380
+ }
381
+
382
+ r->headers_out.last_modified_time =
383
+ (value->len) ? ngx_http_parse_time(value->data, value->len) : -1;
384
+
385
+ return NGX_OK;
386
+ }
387
+
388
+
389
+ static ngx_int_t
390
+ ngx_http_set_response_header(ngx_http_request_t *r, ngx_http_header_val_t *hv,
391
+ ngx_str_t *value)
371
392
  {
372
393
  ngx_table_elt_t *h, **old;
373
394
 
374
395
  old = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset);
375
396
 
376
- r->headers_out.last_modified_time = -1;
397
+ if (value->len == 0) {
398
+ if (*old) {
399
+ (*old)->hash = 0;
400
+ *old = NULL;
401
+ }
377
402
 
378
- if (*old == NULL) {
403
+ return NGX_OK;
404
+ }
379
405
 
380
- if (value->len == 0) {
381
- return NGX_OK;
382
- }
406
+ if (*old) {
407
+ h = *old;
383
408
 
409
+ } else {
384
410
  h = ngx_list_push(&r->headers_out.headers);
385
411
  if (h == NULL) {
386
412
  return NGX_ERROR;
387
413
  }
388
414
 
389
415
  *old = h;
390
-
391
- } else {
392
- h = *old;
393
-
394
- if (value->len == 0) {
395
- h->hash = 0;
396
- return NGX_OK;
397
- }
398
416
  }
399
417
 
400
418
  h->hash = 1;
@@ -45,6 +45,7 @@ typedef struct {
45
45
  ngx_uint_t sharpen;
46
46
 
47
47
  ngx_flag_t transparency;
48
+ ngx_flag_t interlace;
48
49
 
49
50
  ngx_http_complex_value_t *wcv;
50
51
  ngx_http_complex_value_t *hcv;
@@ -143,6 +144,13 @@ static ngx_command_t ngx_http_image_filter_commands[] = {
143
144
  offsetof(ngx_http_image_filter_conf_t, transparency),
144
145
  NULL },
145
146
 
147
+ { ngx_string("image_filter_interlace"),
148
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
149
+ ngx_conf_set_flag_slot,
150
+ NGX_HTTP_LOC_CONF_OFFSET,
151
+ offsetof(ngx_http_image_filter_conf_t, interlace),
152
+ NULL },
153
+
146
154
  { ngx_string("image_filter_buffer"),
147
155
  NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
148
156
  ngx_conf_set_size_slot,
@@ -963,6 +971,8 @@ transparent:
963
971
  gdImageSharpen(dst, sharpen);
964
972
  }
965
973
 
974
+ gdImageInterlace(dst, (int) conf->interlace);
975
+
966
976
  out = ngx_http_image_out(r, ctx->type, dst, &size);
967
977
 
968
978
  ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
@@ -1186,6 +1196,7 @@ ngx_http_image_filter_create_conf(ngx_conf_t *cf)
1186
1196
  conf->jpeg_quality = NGX_CONF_UNSET_UINT;
1187
1197
  conf->sharpen = NGX_CONF_UNSET_UINT;
1188
1198
  conf->transparency = NGX_CONF_UNSET;
1199
+ conf->interlace = NGX_CONF_UNSET;
1189
1200
  conf->buffer_size = NGX_CONF_UNSET_SIZE;
1190
1201
 
1191
1202
  return conf;
@@ -1234,6 +1245,8 @@ ngx_http_image_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child)
1234
1245
 
1235
1246
  ngx_conf_merge_value(conf->transparency, prev->transparency, 1);
1236
1247
 
1248
+ ngx_conf_merge_value(conf->interlace, prev->interlace, 0);
1249
+
1237
1250
  ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
1238
1251
  1 * 1024 * 1024);
1239
1252
 
@@ -40,6 +40,7 @@ typedef struct {
40
40
  typedef struct {
41
41
  ngx_array_t limits;
42
42
  ngx_uint_t log_level;
43
+ ngx_uint_t status_code;
43
44
  } ngx_http_limit_conn_conf_t;
44
45
 
45
46
 
@@ -74,6 +75,11 @@ static ngx_conf_enum_t ngx_http_limit_conn_log_levels[] = {
74
75
  };
75
76
 
76
77
 
78
+ static ngx_conf_num_bounds_t ngx_http_limit_conn_status_bounds = {
79
+ ngx_conf_check_num_bounds, 400, 599
80
+ };
81
+
82
+
77
83
  static ngx_command_t ngx_http_limit_conn_commands[] = {
78
84
 
79
85
  { ngx_string("limit_conn_zone"),
@@ -104,6 +110,13 @@ static ngx_command_t ngx_http_limit_conn_commands[] = {
104
110
  offsetof(ngx_http_limit_conn_conf_t, log_level),
105
111
  &ngx_http_limit_conn_log_levels },
106
112
 
113
+ { ngx_string("limit_conn_status"),
114
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
115
+ ngx_conf_set_num_slot,
116
+ NGX_HTTP_LOC_CONF_OFFSET,
117
+ offsetof(ngx_http_limit_conn_conf_t, status_code),
118
+ &ngx_http_limit_conn_status_bounds },
119
+
107
120
  ngx_null_command
108
121
  };
109
122
 
@@ -206,7 +219,7 @@ ngx_http_limit_conn_handler(ngx_http_request_t *r)
206
219
  if (node == NULL) {
207
220
  ngx_shmtx_unlock(&shpool->mutex);
208
221
  ngx_http_limit_conn_cleanup_all(r->pool);
209
- return NGX_HTTP_SERVICE_UNAVAILABLE;
222
+ return lccf->status_code;
210
223
  }
211
224
 
212
225
  lc = (ngx_http_limit_conn_node_t *) &node->color;
@@ -231,7 +244,7 @@ ngx_http_limit_conn_handler(ngx_http_request_t *r)
231
244
  &limits[i].shm_zone->shm.name);
232
245
 
233
246
  ngx_http_limit_conn_cleanup_all(r->pool);
234
- return NGX_HTTP_SERVICE_UNAVAILABLE;
247
+ return lccf->status_code;
235
248
  }
236
249
 
237
250
  lc->conn++;
@@ -467,6 +480,7 @@ ngx_http_limit_conn_create_conf(ngx_conf_t *cf)
467
480
  */
468
481
 
469
482
  conf->log_level = NGX_CONF_UNSET_UINT;
483
+ conf->status_code = NGX_CONF_UNSET_UINT;
470
484
 
471
485
  return conf;
472
486
  }
@@ -483,6 +497,8 @@ ngx_http_limit_conn_merge_conf(ngx_conf_t *cf, void *parent, void *child)
483
497
  }
484
498
 
485
499
  ngx_conf_merge_uint_value(conf->log_level, prev->log_level, NGX_LOG_ERR);
500
+ ngx_conf_merge_uint_value(conf->status_code, prev->status_code,
501
+ NGX_HTTP_SERVICE_UNAVAILABLE);
486
502
 
487
503
  return NGX_CONF_OK;
488
504
  }
@@ -53,6 +53,7 @@ typedef struct {
53
53
  ngx_array_t limits;
54
54
  ngx_uint_t limit_log_level;
55
55
  ngx_uint_t delay_log_level;
56
+ ngx_uint_t status_code;
56
57
  } ngx_http_limit_req_conf_t;
57
58
 
58
59
 
@@ -84,6 +85,11 @@ static ngx_conf_enum_t ngx_http_limit_req_log_levels[] = {
84
85
  };
85
86
 
86
87
 
88
+ static ngx_conf_num_bounds_t ngx_http_limit_req_status_bounds = {
89
+ ngx_conf_check_num_bounds, 400, 599
90
+ };
91
+
92
+
87
93
  static ngx_command_t ngx_http_limit_req_commands[] = {
88
94
 
89
95
  { ngx_string("limit_req_zone"),
@@ -107,6 +113,13 @@ static ngx_command_t ngx_http_limit_req_commands[] = {
107
113
  offsetof(ngx_http_limit_req_conf_t, limit_log_level),
108
114
  &ngx_http_limit_req_log_levels },
109
115
 
116
+ { ngx_string("limit_req_status"),
117
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
118
+ ngx_conf_set_num_slot,
119
+ NGX_HTTP_LOC_CONF_OFFSET,
120
+ offsetof(ngx_http_limit_req_conf_t, status_code),
121
+ &ngx_http_limit_req_status_bounds },
122
+
110
123
  ngx_null_command
111
124
  };
112
125
 
@@ -245,7 +258,7 @@ ngx_http_limit_req_handler(ngx_http_request_t *r)
245
258
  ctx->node = NULL;
246
259
  }
247
260
 
248
- return NGX_HTTP_SERVICE_UNAVAILABLE;
261
+ return lrcf->status_code;
249
262
  }
250
263
 
251
264
  /* rc == NGX_AGAIN || rc == NGX_OK */
@@ -682,6 +695,7 @@ ngx_http_limit_req_create_conf(ngx_conf_t *cf)
682
695
  */
683
696
 
684
697
  conf->limit_log_level = NGX_CONF_UNSET_UINT;
698
+ conf->status_code = NGX_CONF_UNSET_UINT;
685
699
 
686
700
  return conf;
687
701
  }
@@ -703,6 +717,9 @@ ngx_http_limit_req_merge_conf(ngx_conf_t *cf, void *parent, void *child)
703
717
  conf->delay_log_level = (conf->limit_log_level == NGX_LOG_INFO) ?
704
718
  NGX_LOG_INFO : conf->limit_log_level + 1;
705
719
 
720
+ ngx_conf_merge_uint_value(conf->status_code, prev->status_code,
721
+ NGX_HTTP_SERVICE_UNAVAILABLE);
722
+
706
723
  return NGX_CONF_OK;
707
724
  }
708
725
 
@@ -778,7 +795,7 @@ ngx_http_limit_req_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
778
795
  }
779
796
 
780
797
  rate = ngx_atoi(value[i].data + 5, len - 5);
781
- if (rate <= NGX_ERROR) {
798
+ if (rate <= 0) {
782
799
  ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
783
800
  "invalid rate \"%V\"", &value[i]);
784
801
  return NGX_CONF_ERROR;
@@ -227,7 +227,7 @@ ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
227
227
  var->get_handler = ngx_http_map_variable;
228
228
  var->data = (uintptr_t) map;
229
229
 
230
- pool = ngx_create_pool(16384, cf->log);
230
+ pool = ngx_create_pool(NGX_DEFAULT_POOL_SIZE, cf->log);
231
231
  if (pool == NULL) {
232
232
  return NGX_CONF_ERROR;
233
233
  }
@@ -13,6 +13,7 @@
13
13
  typedef struct {
14
14
  ngx_http_upstream_conf_t upstream;
15
15
  ngx_int_t index;
16
+ ngx_uint_t gzip_flag;
16
17
  } ngx_http_memcached_loc_conf_t;
17
18
 
18
19
 
@@ -101,6 +102,13 @@ static ngx_command_t ngx_http_memcached_commands[] = {
101
102
  offsetof(ngx_http_memcached_loc_conf_t, upstream.next_upstream),
102
103
  &ngx_http_memcached_next_upstream_masks },
103
104
 
105
+ { ngx_string("memcached_gzip_flag"),
106
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
107
+ ngx_conf_set_num_slot,
108
+ NGX_HTTP_LOC_CONF_OFFSET,
109
+ offsetof(ngx_http_memcached_loc_conf_t, gzip_flag),
110
+ NULL },
111
+
104
112
  ngx_null_command
105
113
  };
106
114
 
@@ -281,10 +289,13 @@ ngx_http_memcached_reinit_request(ngx_http_request_t *r)
281
289
  static ngx_int_t
282
290
  ngx_http_memcached_process_header(ngx_http_request_t *r)
283
291
  {
284
- u_char *p, *len;
285
- ngx_str_t line;
286
- ngx_http_upstream_t *u;
287
- ngx_http_memcached_ctx_t *ctx;
292
+ u_char *p, *start;
293
+ ngx_str_t line;
294
+ ngx_uint_t flags;
295
+ ngx_table_elt_t *h;
296
+ ngx_http_upstream_t *u;
297
+ ngx_http_memcached_ctx_t *ctx;
298
+ ngx_http_memcached_loc_conf_t *mlcf;
288
299
 
289
300
  u = r->upstream;
290
301
 
@@ -309,6 +320,7 @@ found:
309
320
  p = u->buffer.pos;
310
321
 
311
322
  ctx = ngx_http_get_module_ctx(r, ngx_http_memcached_module);
323
+ mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module);
312
324
 
313
325
  if (ngx_strncmp(p, "VALUE ", sizeof("VALUE ") - 1) == 0) {
314
326
 
@@ -329,23 +341,56 @@ found:
329
341
  goto no_valid;
330
342
  }
331
343
 
332
- /* skip flags */
344
+ /* flags */
345
+
346
+ start = p;
333
347
 
334
348
  while (*p) {
335
349
  if (*p++ == ' ') {
336
- goto length;
350
+ if (mlcf->gzip_flag) {
351
+ goto flags;
352
+ } else {
353
+ goto length;
354
+ }
337
355
  }
338
356
  }
339
357
 
340
358
  goto no_valid;
341
359
 
360
+ flags:
361
+
362
+ flags = ngx_atoi(start, p - start - 1);
363
+
364
+ if (flags == (ngx_uint_t) NGX_ERROR) {
365
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
366
+ "memcached sent invalid flags in response \"%V\" "
367
+ "for key \"%V\"",
368
+ &line, &ctx->key);
369
+ return NGX_HTTP_UPSTREAM_INVALID_HEADER;
370
+ }
371
+
372
+ if (flags & mlcf->gzip_flag) {
373
+ h = ngx_list_push(&r->headers_out.headers);
374
+ if (h == NULL) {
375
+ return NGX_ERROR;
376
+ }
377
+
378
+ h->hash = 1;
379
+ h->key.len = sizeof("Content-Encoding") - 1;
380
+ h->key.data = (u_char *) "Content-Encoding";
381
+ h->value.len = sizeof("gzip") - 1;
382
+ h->value.data = (u_char *) "gzip";
383
+
384
+ r->headers_out.content_encoding = h;
385
+ }
386
+
342
387
  length:
343
388
 
344
- len = p;
389
+ start = p;
345
390
 
346
391
  while (*p && *p++ != CR) { /* void */ }
347
392
 
348
- u->headers_in.content_length_n = ngx_atoof(len, p - len - 1);
393
+ u->headers_in.content_length_n = ngx_atoof(start, p - start - 1);
349
394
  if (u->headers_in.content_length_n == -1) {
350
395
  ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
351
396
  "memcached sent invalid length in response \"%V\" "
@@ -529,6 +574,7 @@ ngx_http_memcached_create_loc_conf(ngx_conf_t *cf)
529
574
  * conf->upstream.location = NULL;
530
575
  */
531
576
 
577
+ conf->upstream.local = NGX_CONF_UNSET_PTR;
532
578
  conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC;
533
579
  conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC;
534
580
  conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC;
@@ -550,6 +596,7 @@ ngx_http_memcached_create_loc_conf(ngx_conf_t *cf)
550
596
  conf->upstream.pass_request_body = 0;
551
597
 
552
598
  conf->index = NGX_CONF_UNSET;
599
+ conf->gzip_flag = NGX_CONF_UNSET_UINT;
553
600
 
554
601
  return conf;
555
602
  }
@@ -561,6 +608,9 @@ ngx_http_memcached_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
561
608
  ngx_http_memcached_loc_conf_t *prev = parent;
562
609
  ngx_http_memcached_loc_conf_t *conf = child;
563
610
 
611
+ ngx_conf_merge_ptr_value(conf->upstream.local,
612
+ prev->upstream.local, NULL);
613
+
564
614
  ngx_conf_merge_msec_value(conf->upstream.connect_timeout,
565
615
  prev->upstream.connect_timeout, 60000);
566
616
 
@@ -593,6 +643,8 @@ ngx_http_memcached_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
593
643
  conf->index = prev->index;
594
644
  }
595
645
 
646
+ ngx_conf_merge_uint_value(conf->gzip_flag, prev->gzip_flag, 0);
647
+
596
648
  return NGX_CONF_OK;
597
649
  }
598
650