nginxtra 1.8.1.12 → 1.10.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) 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 +363 -25
  6. data/vendor/nginx/CHANGES.ru +365 -21
  7. data/vendor/nginx/LICENSE +2 -2
  8. data/vendor/nginx/auto/cc/conf +32 -0
  9. data/vendor/nginx/auto/cc/gcc +1 -1
  10. data/vendor/nginx/auto/cc/icc +2 -2
  11. data/vendor/nginx/auto/cc/msvc +29 -8
  12. data/vendor/nginx/auto/cc/name +2 -25
  13. data/vendor/nginx/auto/cc/sunc +3 -0
  14. data/vendor/nginx/auto/endianness +7 -2
  15. data/vendor/nginx/auto/install +60 -26
  16. data/vendor/nginx/auto/lib/conf +4 -4
  17. data/vendor/nginx/auto/lib/geoip/conf +6 -1
  18. data/vendor/nginx/auto/lib/libgd/conf +6 -1
  19. data/vendor/nginx/auto/lib/libxslt/conf +11 -2
  20. data/vendor/nginx/auto/lib/make +1 -1
  21. data/vendor/nginx/auto/lib/md5/conf +2 -2
  22. data/vendor/nginx/auto/lib/md5/make +2 -2
  23. data/vendor/nginx/auto/lib/openssl/conf +52 -3
  24. data/vendor/nginx/auto/lib/openssl/make +1 -1
  25. data/vendor/nginx/auto/lib/pcre/conf +2 -2
  26. data/vendor/nginx/auto/lib/pcre/make +2 -2
  27. data/vendor/nginx/auto/lib/perl/conf +6 -3
  28. data/vendor/nginx/auto/lib/perl/make +4 -1
  29. data/vendor/nginx/auto/lib/sha1/conf +2 -2
  30. data/vendor/nginx/auto/lib/sha1/make +2 -2
  31. data/vendor/nginx/auto/lib/zlib/conf +2 -2
  32. data/vendor/nginx/auto/lib/zlib/make +2 -2
  33. data/vendor/nginx/auto/make +281 -16
  34. data/vendor/nginx/auto/module +122 -0
  35. data/vendor/nginx/auto/modules +909 -178
  36. data/vendor/nginx/auto/options +81 -19
  37. data/vendor/nginx/auto/os/conf +9 -0
  38. data/vendor/nginx/auto/os/darwin +3 -0
  39. data/vendor/nginx/auto/os/freebsd +0 -20
  40. data/vendor/nginx/auto/os/linux +0 -12
  41. data/vendor/nginx/auto/os/win32 +5 -1
  42. data/vendor/nginx/auto/sources +11 -311
  43. data/vendor/nginx/auto/summary +1 -0
  44. data/vendor/nginx/auto/types/sizeof +5 -3
  45. data/vendor/nginx/auto/types/typedef +9 -4
  46. data/vendor/nginx/auto/types/uintptr_t +7 -2
  47. data/vendor/nginx/auto/unix +72 -12
  48. data/vendor/nginx/conf/fastcgi.conf +1 -0
  49. data/vendor/nginx/conf/fastcgi_params +1 -0
  50. data/vendor/nginx/conf/scgi_params +1 -0
  51. data/vendor/nginx/conf/uwsgi_params +1 -0
  52. data/vendor/nginx/configure +1 -1
  53. data/vendor/nginx/contrib/vim/syntax/nginx.vim +2 -2
  54. data/vendor/nginx/man/nginx.8 +6 -2
  55. data/vendor/nginx/src/core/nginx.c +281 -114
  56. data/vendor/nginx/src/core/nginx.h +2 -2
  57. data/vendor/nginx/src/core/ngx_conf_file.c +54 -13
  58. data/vendor/nginx/src/core/ngx_conf_file.h +8 -52
  59. data/vendor/nginx/src/core/ngx_config.h +0 -5
  60. data/vendor/nginx/src/core/ngx_connection.c +270 -37
  61. data/vendor/nginx/src/core/ngx_connection.h +35 -12
  62. data/vendor/nginx/src/core/ngx_core.h +4 -0
  63. data/vendor/nginx/src/core/ngx_crypt.c +2 -2
  64. data/vendor/nginx/src/core/ngx_cycle.c +72 -25
  65. data/vendor/nginx/src/core/ngx_cycle.h +28 -39
  66. data/vendor/nginx/src/core/ngx_file.c +14 -5
  67. data/vendor/nginx/src/core/ngx_file.h +2 -0
  68. data/vendor/nginx/src/core/ngx_hash.c +13 -1
  69. data/vendor/nginx/src/core/ngx_inet.c +20 -18
  70. data/vendor/nginx/src/core/ngx_log.c +12 -12
  71. data/vendor/nginx/src/core/ngx_log.h +13 -6
  72. data/vendor/nginx/src/core/ngx_module.c +360 -0
  73. data/vendor/nginx/src/core/ngx_module.h +307 -0
  74. data/vendor/nginx/src/core/ngx_open_file_cache.c +2 -2
  75. data/vendor/nginx/src/core/ngx_output_chain.c +8 -4
  76. data/vendor/nginx/src/core/ngx_palloc.c +42 -44
  77. data/vendor/nginx/src/{http/ngx_http_parse_time.c → core/ngx_parse_time.c} +2 -3
  78. data/vendor/nginx/src/core/ngx_parse_time.h +22 -0
  79. data/vendor/nginx/src/core/ngx_proxy_protocol.c +50 -1
  80. data/vendor/nginx/src/core/ngx_proxy_protocol.h +3 -1
  81. data/vendor/nginx/src/core/ngx_regex.c +1 -38
  82. data/vendor/nginx/src/core/ngx_resolver.c +1814 -320
  83. data/vendor/nginx/src/core/ngx_resolver.h +67 -10
  84. data/vendor/nginx/src/core/ngx_rwlock.c +120 -0
  85. data/vendor/nginx/src/core/ngx_rwlock.h +21 -0
  86. data/vendor/nginx/src/core/ngx_slab.c +6 -5
  87. data/vendor/nginx/src/core/ngx_string.c +1 -1
  88. data/vendor/nginx/src/core/ngx_syslog.c +11 -3
  89. data/vendor/nginx/src/core/ngx_syslog.h +2 -1
  90. data/vendor/nginx/src/core/ngx_thread_pool.c +4 -0
  91. data/vendor/nginx/src/core/ngx_times.c +2 -2
  92. data/vendor/nginx/src/event/modules/ngx_devpoll_module.c +3 -1
  93. data/vendor/nginx/src/event/modules/ngx_epoll_module.c +5 -2
  94. data/vendor/nginx/src/event/modules/ngx_eventport_module.c +5 -5
  95. data/vendor/nginx/src/event/modules/ngx_kqueue_module.c +15 -8
  96. data/vendor/nginx/src/event/modules/ngx_poll_module.c +0 -10
  97. data/vendor/nginx/src/event/modules/ngx_select_module.c +0 -10
  98. data/vendor/nginx/src/event/ngx_event.c +60 -103
  99. data/vendor/nginx/src/event/ngx_event.h +22 -26
  100. data/vendor/nginx/src/event/ngx_event_accept.c +414 -88
  101. data/vendor/nginx/src/event/ngx_event_connect.c +27 -18
  102. data/vendor/nginx/src/event/ngx_event_connect.h +1 -0
  103. data/vendor/nginx/src/event/ngx_event_openssl.c +65 -25
  104. data/vendor/nginx/src/event/ngx_event_openssl.h +17 -0
  105. data/vendor/nginx/src/event/ngx_event_openssl_stapling.c +73 -7
  106. data/vendor/nginx/src/event/ngx_event_pipe.c +85 -27
  107. data/vendor/nginx/src/event/ngx_event_pipe.h +10 -0
  108. data/vendor/nginx/src/http/modules/ngx_http_auth_basic_module.c +1 -1
  109. data/vendor/nginx/src/http/modules/ngx_http_auth_request_module.c +2 -2
  110. data/vendor/nginx/src/http/modules/ngx_http_chunked_filter_module.c +2 -2
  111. data/vendor/nginx/src/http/modules/ngx_http_dav_module.c +6 -6
  112. data/vendor/nginx/src/http/modules/ngx_http_fastcgi_module.c +17 -11
  113. data/vendor/nginx/src/http/modules/ngx_http_gzip_filter_module.c +2 -2
  114. data/vendor/nginx/src/http/modules/ngx_http_headers_filter_module.c +9 -9
  115. data/vendor/nginx/src/http/modules/ngx_http_image_filter_module.c +2 -2
  116. data/vendor/nginx/src/http/modules/ngx_http_limit_conn_module.c +2 -2
  117. data/vendor/nginx/src/http/modules/ngx_http_limit_req_module.c +0 -7
  118. data/vendor/nginx/src/http/modules/ngx_http_map_module.c +6 -6
  119. data/vendor/nginx/src/http/modules/ngx_http_memcached_module.c +2 -1
  120. data/vendor/nginx/src/http/modules/ngx_http_mp4_module.c +13 -13
  121. data/vendor/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +2 -2
  122. data/vendor/nginx/src/http/modules/ngx_http_proxy_module.c +26 -21
  123. data/vendor/nginx/src/http/modules/ngx_http_random_index_module.c +1 -1
  124. data/vendor/nginx/src/http/modules/ngx_http_range_filter_module.c +26 -8
  125. data/vendor/nginx/src/http/modules/ngx_http_realip_module.c +73 -3
  126. data/vendor/nginx/src/http/modules/ngx_http_referer_module.c +1 -1
  127. data/vendor/nginx/src/http/modules/ngx_http_rewrite_module.c +6 -6
  128. data/vendor/nginx/src/http/modules/ngx_http_scgi_module.c +5 -3
  129. data/vendor/nginx/src/http/modules/ngx_http_slice_filter_module.c +526 -0
  130. data/vendor/nginx/src/http/modules/ngx_http_ssi_filter_module.c +7 -7
  131. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.c +19 -16
  132. data/vendor/nginx/src/http/modules/ngx_http_static_module.c +1 -1
  133. data/vendor/nginx/src/http/modules/ngx_http_stub_status_module.c +1 -1
  134. data/vendor/nginx/src/http/modules/ngx_http_sub_filter_module.c +373 -173
  135. data/vendor/nginx/src/http/modules/ngx_http_upstream_hash_module.c +72 -46
  136. data/vendor/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +18 -30
  137. data/vendor/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +50 -39
  138. data/vendor/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c +38 -129
  139. data/vendor/nginx/src/http/modules/ngx_http_upstream_zone_module.c +246 -0
  140. data/vendor/nginx/src/http/modules/ngx_http_uwsgi_module.c +6 -5
  141. data/vendor/nginx/src/http/modules/perl/nginx.xs +9 -9
  142. data/vendor/nginx/src/http/ngx_http.c +46 -43
  143. data/vendor/nginx/src/http/ngx_http.h +4 -9
  144. data/vendor/nginx/src/http/ngx_http_cache.h +4 -0
  145. data/vendor/nginx/src/http/ngx_http_copy_filter_module.c +13 -5
  146. data/vendor/nginx/src/http/ngx_http_core_module.c +92 -91
  147. data/vendor/nginx/src/http/ngx_http_core_module.h +12 -8
  148. data/vendor/nginx/src/http/ngx_http_file_cache.c +61 -10
  149. data/vendor/nginx/src/http/ngx_http_request.c +37 -50
  150. data/vendor/nginx/src/http/ngx_http_request.h +10 -15
  151. data/vendor/nginx/src/http/ngx_http_request_body.c +64 -88
  152. data/vendor/nginx/src/http/ngx_http_script.c +3 -3
  153. data/vendor/nginx/src/http/ngx_http_special_response.c +1 -4
  154. data/vendor/nginx/src/http/ngx_http_upstream.c +245 -109
  155. data/vendor/nginx/src/http/ngx_http_upstream.h +11 -5
  156. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.c +212 -65
  157. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.h +66 -5
  158. data/vendor/nginx/src/http/ngx_http_variables.c +28 -15
  159. data/vendor/nginx/src/http/ngx_http_write_filter_module.c +1 -1
  160. data/vendor/nginx/src/http/v2/ngx_http_v2.c +4349 -0
  161. data/vendor/nginx/src/http/v2/ngx_http_v2.h +337 -0
  162. data/vendor/nginx/src/http/v2/ngx_http_v2_filter_module.c +1391 -0
  163. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_decode.c +2714 -0
  164. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_encode.c +254 -0
  165. data/vendor/nginx/src/http/v2/ngx_http_v2_module.c +469 -0
  166. data/vendor/nginx/src/http/{ngx_http_spdy_module.h → v2/ngx_http_v2_module.h} +10 -9
  167. data/vendor/nginx/src/http/v2/ngx_http_v2_table.c +349 -0
  168. data/vendor/nginx/src/mail/ngx_mail.c +49 -82
  169. data/vendor/nginx/src/mail/ngx_mail.h +16 -23
  170. data/vendor/nginx/src/mail/ngx_mail_auth_http_module.c +1 -1
  171. data/vendor/nginx/src/mail/ngx_mail_core_module.c +60 -34
  172. data/vendor/nginx/src/mail/ngx_mail_handler.c +17 -12
  173. data/vendor/nginx/src/mail/ngx_mail_proxy_module.c +1 -14
  174. data/vendor/nginx/src/mail/ngx_mail_smtp_handler.c +1 -1
  175. data/vendor/nginx/src/mail/ngx_mail_ssl_module.c +5 -5
  176. data/vendor/nginx/src/os/unix/ngx_atomic.h +10 -10
  177. data/vendor/nginx/src/os/unix/ngx_channel.h +4 -4
  178. data/vendor/nginx/src/os/unix/ngx_darwin_config.h +2 -0
  179. data/vendor/nginx/src/os/unix/ngx_darwin_init.c +1 -0
  180. data/vendor/nginx/src/os/unix/ngx_dlopen.c +28 -0
  181. data/vendor/nginx/src/os/unix/ngx_dlopen.h +31 -0
  182. data/vendor/nginx/src/os/unix/ngx_errno.h +1 -0
  183. data/vendor/nginx/src/os/unix/ngx_file_aio_read.c +1 -1
  184. data/vendor/nginx/src/os/unix/ngx_files.c +313 -80
  185. data/vendor/nginx/src/os/unix/ngx_files.h +5 -2
  186. data/vendor/nginx/src/os/unix/ngx_freebsd_config.h +3 -1
  187. data/vendor/nginx/src/os/unix/ngx_freebsd_init.c +1 -0
  188. data/vendor/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +13 -0
  189. data/vendor/nginx/src/os/unix/ngx_linux.h +0 -2
  190. data/vendor/nginx/src/os/unix/ngx_linux_aio_read.c +1 -1
  191. data/vendor/nginx/src/os/unix/ngx_linux_config.h +2 -6
  192. data/vendor/nginx/src/os/unix/ngx_linux_init.c +1 -33
  193. data/vendor/nginx/src/os/unix/ngx_linux_sendfile_chain.c +55 -12
  194. data/vendor/nginx/src/os/unix/ngx_os.h +3 -9
  195. data/vendor/nginx/src/os/unix/ngx_posix_config.h +14 -1
  196. data/vendor/nginx/src/os/unix/ngx_posix_init.c +2 -1
  197. data/vendor/nginx/src/os/unix/ngx_process.c +1 -1
  198. data/vendor/nginx/src/os/unix/ngx_process_cycle.c +25 -51
  199. data/vendor/nginx/src/os/unix/ngx_process_cycle.h +1 -0
  200. data/vendor/nginx/src/os/unix/ngx_readv_chain.c +24 -28
  201. data/vendor/nginx/src/os/unix/ngx_recv.c +30 -79
  202. data/vendor/nginx/src/os/unix/ngx_send.c +1 -1
  203. data/vendor/nginx/src/os/unix/ngx_setaffinity.c +14 -30
  204. data/vendor/nginx/src/os/unix/ngx_setaffinity.h +15 -1
  205. data/vendor/nginx/src/os/unix/ngx_solaris_config.h +2 -0
  206. data/vendor/nginx/src/os/unix/ngx_solaris_init.c +1 -0
  207. data/vendor/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +23 -0
  208. data/vendor/nginx/src/os/unix/ngx_sunpro_amd64.il +3 -3
  209. data/vendor/nginx/src/os/unix/ngx_sunpro_x86.il +3 -3
  210. data/vendor/nginx/src/os/unix/ngx_udp_recv.c +5 -48
  211. data/vendor/nginx/src/os/unix/ngx_udp_send.c +56 -0
  212. data/vendor/nginx/src/stream/ngx_stream.c +564 -0
  213. data/vendor/nginx/src/stream/ngx_stream.h +212 -0
  214. data/vendor/nginx/src/stream/ngx_stream_access_module.c +451 -0
  215. data/vendor/nginx/src/stream/ngx_stream_core_module.c +562 -0
  216. data/vendor/nginx/src/stream/ngx_stream_handler.c +344 -0
  217. data/vendor/nginx/src/stream/ngx_stream_limit_conn_module.c +632 -0
  218. data/vendor/nginx/src/stream/ngx_stream_proxy_module.c +1674 -0
  219. data/vendor/nginx/src/stream/ngx_stream_ssl_module.c +460 -0
  220. data/vendor/nginx/src/stream/ngx_stream_ssl_module.h +49 -0
  221. data/vendor/nginx/src/stream/ngx_stream_upstream.c +464 -0
  222. data/vendor/nginx/src/stream/ngx_stream_upstream.h +107 -0
  223. data/vendor/nginx/src/stream/ngx_stream_upstream_hash_module.c +656 -0
  224. data/vendor/nginx/src/stream/ngx_stream_upstream_least_conn_module.c +307 -0
  225. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.c +702 -0
  226. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.h +139 -0
  227. data/vendor/nginx/src/stream/ngx_stream_upstream_zone_module.c +242 -0
  228. metadata +39 -15
  229. data/vendor/nginx/src/event/modules/ngx_aio_module.c +0 -171
  230. data/vendor/nginx/src/event/modules/ngx_rtsig_module.c +0 -735
  231. data/vendor/nginx/src/http/ngx_http_spdy.c +0 -3701
  232. data/vendor/nginx/src/http/ngx_http_spdy.h +0 -261
  233. data/vendor/nginx/src/http/ngx_http_spdy_filter_module.c +0 -1222
  234. data/vendor/nginx/src/http/ngx_http_spdy_module.c +0 -408
  235. data/vendor/nginx/src/os/unix/ngx_aio_read.c +0 -109
  236. data/vendor/nginx/src/os/unix/ngx_aio_read_chain.c +0 -78
  237. data/vendor/nginx/src/os/unix/ngx_aio_write.c +0 -109
  238. data/vendor/nginx/src/os/unix/ngx_aio_write_chain.c +0 -100
@@ -109,7 +109,7 @@ ngx_module_t ngx_http_referer_module = {
109
109
 
110
110
  static ngx_int_t
111
111
  ngx_http_referer_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
112
- uintptr_t data)
112
+ uintptr_t data)
113
113
  {
114
114
  u_char *p, *ref, *last;
115
115
  size_t len;
@@ -560,21 +560,21 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
560
560
  return NGX_CONF_ERROR;
561
561
  }
562
562
 
563
- for (i = 0; ngx_modules[i]; i++) {
564
- if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
563
+ for (i = 0; cf->cycle->modules[i]; i++) {
564
+ if (cf->cycle->modules[i]->type != NGX_HTTP_MODULE) {
565
565
  continue;
566
566
  }
567
567
 
568
- module = ngx_modules[i]->ctx;
568
+ module = cf->cycle->modules[i]->ctx;
569
569
 
570
570
  if (module->create_loc_conf) {
571
571
 
572
572
  mconf = module->create_loc_conf(cf);
573
573
  if (mconf == NULL) {
574
- return NGX_CONF_ERROR;
574
+ return NGX_CONF_ERROR;
575
575
  }
576
576
 
577
- ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
577
+ ctx->loc_conf[cf->cycle->modules[i]->ctx_index] = mconf;
578
578
  }
579
579
  }
580
580
 
@@ -612,7 +612,7 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
612
612
  save = *cf;
613
613
  cf->ctx = ctx;
614
614
 
615
- if (pclcf->name.len == 0) {
615
+ if (cf->cmd_type == NGX_HTTP_SRV_CONF) {
616
616
  if_code->loc_conf = NULL;
617
617
  cf->cmd_type = NGX_HTTP_SIF_CONF;
618
618
 
@@ -77,6 +77,7 @@ static ngx_conf_bitmask_t ngx_http_scgi_next_upstream_masks[] = {
77
77
  { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
78
78
  { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
79
79
  { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER },
80
+ { ngx_string("non_idempotent"), NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT },
80
81
  { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 },
81
82
  { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
82
83
  { ngx_string("http_403"), NGX_HTTP_UPSTREAM_FT_HTTP_403 },
@@ -569,10 +570,11 @@ ngx_http_scgi_eval(ngx_http_request_t *r, ngx_http_scgi_loc_conf_t * scf)
569
570
 
570
571
  } else {
571
572
  u->resolved->host = url.host;
572
- u->resolved->port = url.port;
573
- u->resolved->no_port = url.no_port;
574
573
  }
575
574
 
575
+ u->resolved->port = url.port;
576
+ u->resolved->no_port = url.no_port;
577
+
576
578
  return NGX_OK;
577
579
  }
578
580
 
@@ -874,7 +876,7 @@ ngx_http_scgi_create_request(ngx_http_request_t *r)
874
876
  next:
875
877
 
876
878
  continue;
877
- }
879
+ }
878
880
  }
879
881
 
880
882
  *b->last++ = (u_char) ',';
@@ -0,0 +1,526 @@
1
+
2
+ /*
3
+ * Copyright (C) Roman Arutyunyan
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #include <ngx_config.h>
9
+ #include <ngx_core.h>
10
+ #include <ngx_http.h>
11
+
12
+
13
+ typedef struct {
14
+ size_t size;
15
+ } ngx_http_slice_loc_conf_t;
16
+
17
+
18
+ typedef struct {
19
+ off_t start;
20
+ off_t end;
21
+ ngx_str_t range;
22
+ ngx_str_t etag;
23
+ ngx_uint_t last; /* unsigned last:1; */
24
+ } ngx_http_slice_ctx_t;
25
+
26
+
27
+ typedef struct {
28
+ off_t start;
29
+ off_t end;
30
+ off_t complete_length;
31
+ } ngx_http_slice_content_range_t;
32
+
33
+
34
+ static ngx_int_t ngx_http_slice_header_filter(ngx_http_request_t *r);
35
+ static ngx_int_t ngx_http_slice_body_filter(ngx_http_request_t *r,
36
+ ngx_chain_t *in);
37
+ static ngx_int_t ngx_http_slice_parse_content_range(ngx_http_request_t *r,
38
+ ngx_http_slice_content_range_t *cr);
39
+ static ngx_int_t ngx_http_slice_range_variable(ngx_http_request_t *r,
40
+ ngx_http_variable_value_t *v, uintptr_t data);
41
+ static off_t ngx_http_slice_get_start(ngx_http_request_t *r);
42
+ static void *ngx_http_slice_create_loc_conf(ngx_conf_t *cf);
43
+ static char *ngx_http_slice_merge_loc_conf(ngx_conf_t *cf, void *parent,
44
+ void *child);
45
+ static ngx_int_t ngx_http_slice_add_variables(ngx_conf_t *cf);
46
+ static ngx_int_t ngx_http_slice_init(ngx_conf_t *cf);
47
+
48
+
49
+ static ngx_command_t ngx_http_slice_filter_commands[] = {
50
+
51
+ { ngx_string("slice"),
52
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
53
+ ngx_conf_set_size_slot,
54
+ NGX_HTTP_LOC_CONF_OFFSET,
55
+ offsetof(ngx_http_slice_loc_conf_t, size),
56
+ NULL },
57
+
58
+ ngx_null_command
59
+ };
60
+
61
+
62
+ static ngx_http_module_t ngx_http_slice_filter_module_ctx = {
63
+ ngx_http_slice_add_variables, /* preconfiguration */
64
+ ngx_http_slice_init, /* postconfiguration */
65
+
66
+ NULL, /* create main configuration */
67
+ NULL, /* init main configuration */
68
+
69
+ NULL, /* create server configuration */
70
+ NULL, /* merge server configuration */
71
+
72
+ ngx_http_slice_create_loc_conf, /* create location configuration */
73
+ ngx_http_slice_merge_loc_conf /* merge location configuration */
74
+ };
75
+
76
+
77
+ ngx_module_t ngx_http_slice_filter_module = {
78
+ NGX_MODULE_V1,
79
+ &ngx_http_slice_filter_module_ctx, /* module context */
80
+ ngx_http_slice_filter_commands, /* module directives */
81
+ NGX_HTTP_MODULE, /* module type */
82
+ NULL, /* init master */
83
+ NULL, /* init module */
84
+ NULL, /* init process */
85
+ NULL, /* init thread */
86
+ NULL, /* exit thread */
87
+ NULL, /* exit process */
88
+ NULL, /* exit master */
89
+ NGX_MODULE_V1_PADDING
90
+ };
91
+
92
+
93
+ static ngx_str_t ngx_http_slice_range_name = ngx_string("slice_range");
94
+
95
+ static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
96
+ static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
97
+
98
+
99
+ static ngx_int_t
100
+ ngx_http_slice_header_filter(ngx_http_request_t *r)
101
+ {
102
+ off_t end;
103
+ ngx_int_t rc;
104
+ ngx_table_elt_t *h;
105
+ ngx_http_slice_ctx_t *ctx;
106
+ ngx_http_slice_loc_conf_t *slcf;
107
+ ngx_http_slice_content_range_t cr;
108
+
109
+ ctx = ngx_http_get_module_ctx(r, ngx_http_slice_filter_module);
110
+ if (ctx == NULL) {
111
+ return ngx_http_next_header_filter(r);
112
+ }
113
+
114
+ if (r->headers_out.status != NGX_HTTP_PARTIAL_CONTENT) {
115
+ if (r == r->main) {
116
+ ngx_http_set_ctx(r, NULL, ngx_http_slice_filter_module);
117
+ return ngx_http_next_header_filter(r);
118
+ }
119
+
120
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
121
+ "unexpected status code %ui in slice response",
122
+ r->headers_out.status);
123
+ return NGX_ERROR;
124
+ }
125
+
126
+ h = r->headers_out.etag;
127
+
128
+ if (ctx->etag.len) {
129
+ if (h == NULL
130
+ || h->value.len != ctx->etag.len
131
+ || ngx_strncmp(h->value.data, ctx->etag.data, ctx->etag.len)
132
+ != 0)
133
+ {
134
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
135
+ "etag mismatch in slice response");
136
+ return NGX_ERROR;
137
+ }
138
+ }
139
+
140
+ if (h) {
141
+ ctx->etag = h->value;
142
+ }
143
+
144
+ if (ngx_http_slice_parse_content_range(r, &cr) != NGX_OK) {
145
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
146
+ "invalid range in slice response");
147
+ return NGX_ERROR;
148
+ }
149
+
150
+ if (cr.complete_length == -1) {
151
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
152
+ "no complete length in slice response");
153
+ return NGX_ERROR;
154
+ }
155
+
156
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
157
+ "http slice response range: %O-%O/%O",
158
+ cr.start, cr.end, cr.complete_length);
159
+
160
+ slcf = ngx_http_get_module_loc_conf(r, ngx_http_slice_filter_module);
161
+
162
+ end = ngx_min(cr.start + (off_t) slcf->size, cr.complete_length);
163
+
164
+ if (cr.start != ctx->start || cr.end != end) {
165
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
166
+ "unexpected range in slice response: %O-%O",
167
+ cr.start, cr.end);
168
+ return NGX_ERROR;
169
+ }
170
+
171
+ ctx->start = end;
172
+
173
+ r->headers_out.status = NGX_HTTP_OK;
174
+ r->headers_out.status_line.len = 0;
175
+ r->headers_out.content_length_n = cr.complete_length;
176
+ r->headers_out.content_offset = cr.start;
177
+ r->headers_out.content_range->hash = 0;
178
+ r->headers_out.content_range = NULL;
179
+
180
+ r->allow_ranges = 1;
181
+ r->subrequest_ranges = 1;
182
+ r->single_range = 1;
183
+
184
+ rc = ngx_http_next_header_filter(r);
185
+
186
+ if (r != r->main) {
187
+ return rc;
188
+ }
189
+
190
+ if (r->headers_out.status == NGX_HTTP_PARTIAL_CONTENT) {
191
+ if (ctx->start + (off_t) slcf->size <= r->headers_out.content_offset) {
192
+ ctx->start = slcf->size
193
+ * (r->headers_out.content_offset / slcf->size);
194
+ }
195
+
196
+ ctx->end = r->headers_out.content_offset
197
+ + r->headers_out.content_length_n;
198
+
199
+ } else {
200
+ ctx->end = cr.complete_length;
201
+ }
202
+
203
+ return rc;
204
+ }
205
+
206
+
207
+ static ngx_int_t
208
+ ngx_http_slice_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
209
+ {
210
+ ngx_int_t rc;
211
+ ngx_chain_t *cl;
212
+ ngx_http_request_t *sr;
213
+ ngx_http_slice_ctx_t *ctx;
214
+ ngx_http_slice_loc_conf_t *slcf;
215
+
216
+ ctx = ngx_http_get_module_ctx(r, ngx_http_slice_filter_module);
217
+
218
+ if (ctx == NULL || r != r->main) {
219
+ return ngx_http_next_body_filter(r, in);
220
+ }
221
+
222
+ for (cl = in; cl; cl = cl->next) {
223
+ if (cl->buf->last_buf) {
224
+ cl->buf->last_buf = 0;
225
+ cl->buf->last_in_chain = 1;
226
+ cl->buf->sync = 1;
227
+ ctx->last = 1;
228
+ }
229
+ }
230
+
231
+ rc = ngx_http_next_body_filter(r, in);
232
+
233
+ if (rc == NGX_ERROR || !ctx->last) {
234
+ return rc;
235
+ }
236
+
237
+ if (ctx->start >= ctx->end) {
238
+ ngx_http_set_ctx(r, NULL, ngx_http_slice_filter_module);
239
+ ngx_http_send_special(r, NGX_HTTP_LAST);
240
+ return rc;
241
+ }
242
+
243
+ if (r->buffered) {
244
+ return rc;
245
+ }
246
+
247
+ if (ngx_http_subrequest(r, &r->uri, &r->args, &sr, NULL, 0) != NGX_OK) {
248
+ return NGX_ERROR;
249
+ }
250
+
251
+ ngx_http_set_ctx(sr, ctx, ngx_http_slice_filter_module);
252
+
253
+ slcf = ngx_http_get_module_loc_conf(r, ngx_http_slice_filter_module);
254
+
255
+ ctx->range.len = ngx_sprintf(ctx->range.data, "bytes=%O-%O", ctx->start,
256
+ ctx->start + (off_t) slcf->size - 1)
257
+ - ctx->range.data;
258
+
259
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
260
+ "http slice subrequest: \"%V\"", &ctx->range);
261
+
262
+ return rc;
263
+ }
264
+
265
+
266
+ static ngx_int_t
267
+ ngx_http_slice_parse_content_range(ngx_http_request_t *r,
268
+ ngx_http_slice_content_range_t *cr)
269
+ {
270
+ off_t start, end, complete_length, cutoff, cutlim;
271
+ u_char *p;
272
+ ngx_table_elt_t *h;
273
+
274
+ h = r->headers_out.content_range;
275
+
276
+ if (h == NULL
277
+ || h->value.len < 7
278
+ || ngx_strncmp(h->value.data, "bytes ", 6) != 0)
279
+ {
280
+ return NGX_ERROR;
281
+ }
282
+
283
+ p = h->value.data + 6;
284
+
285
+ cutoff = NGX_MAX_OFF_T_VALUE / 10;
286
+ cutlim = NGX_MAX_OFF_T_VALUE % 10;
287
+
288
+ start = 0;
289
+ end = 0;
290
+ complete_length = 0;
291
+
292
+ while (*p == ' ') { p++; }
293
+
294
+ if (*p < '0' || *p > '9') {
295
+ return NGX_ERROR;
296
+ }
297
+
298
+ while (*p >= '0' && *p <= '9') {
299
+ if (start >= cutoff && (start > cutoff || *p - '0' > cutlim)) {
300
+ return NGX_ERROR;
301
+ }
302
+
303
+ start = start * 10 + *p++ - '0';
304
+ }
305
+
306
+ while (*p == ' ') { p++; }
307
+
308
+ if (*p++ != '-') {
309
+ return NGX_ERROR;
310
+ }
311
+
312
+ while (*p == ' ') { p++; }
313
+
314
+ if (*p < '0' || *p > '9') {
315
+ return NGX_ERROR;
316
+ }
317
+
318
+ while (*p >= '0' && *p <= '9') {
319
+ if (end >= cutoff && (end > cutoff || *p - '0' > cutlim)) {
320
+ return NGX_ERROR;
321
+ }
322
+
323
+ end = end * 10 + *p++ - '0';
324
+ }
325
+
326
+ end++;
327
+
328
+ while (*p == ' ') { p++; }
329
+
330
+ if (*p++ != '/') {
331
+ return NGX_ERROR;
332
+ }
333
+
334
+ while (*p == ' ') { p++; }
335
+
336
+ if (*p != '*') {
337
+ if (*p < '0' || *p > '9') {
338
+ return NGX_ERROR;
339
+ }
340
+
341
+ while (*p >= '0' && *p <= '9') {
342
+ if (complete_length >= cutoff
343
+ && (complete_length > cutoff || *p - '0' > cutlim))
344
+ {
345
+ return NGX_ERROR;
346
+ }
347
+
348
+ complete_length = complete_length * 10 + *p++ - '0';
349
+ }
350
+
351
+ } else {
352
+ complete_length = -1;
353
+ p++;
354
+ }
355
+
356
+ while (*p == ' ') { p++; }
357
+
358
+ if (*p != '\0') {
359
+ return NGX_ERROR;
360
+ }
361
+
362
+ cr->start = start;
363
+ cr->end = end;
364
+ cr->complete_length = complete_length;
365
+
366
+ return NGX_OK;
367
+ }
368
+
369
+
370
+ static ngx_int_t
371
+ ngx_http_slice_range_variable(ngx_http_request_t *r,
372
+ ngx_http_variable_value_t *v, uintptr_t data)
373
+ {
374
+ u_char *p;
375
+ ngx_http_slice_ctx_t *ctx;
376
+ ngx_http_slice_loc_conf_t *slcf;
377
+
378
+ ctx = ngx_http_get_module_ctx(r, ngx_http_slice_filter_module);
379
+
380
+ if (ctx == NULL) {
381
+ if (r != r->main || r->headers_out.status) {
382
+ v->not_found = 1;
383
+ return NGX_OK;
384
+ }
385
+
386
+ slcf = ngx_http_get_module_loc_conf(r, ngx_http_slice_filter_module);
387
+
388
+ if (slcf->size == 0) {
389
+ v->not_found = 1;
390
+ return NGX_OK;
391
+ }
392
+
393
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_slice_ctx_t));
394
+ if (ctx == NULL) {
395
+ return NGX_ERROR;
396
+ }
397
+
398
+ ngx_http_set_ctx(r, ctx, ngx_http_slice_filter_module);
399
+
400
+ p = ngx_pnalloc(r->pool, sizeof("bytes=-") - 1 + 2 * NGX_OFF_T_LEN);
401
+ if (p == NULL) {
402
+ return NGX_ERROR;
403
+ }
404
+
405
+ ctx->start = slcf->size * (ngx_http_slice_get_start(r) / slcf->size);
406
+
407
+ ctx->range.data = p;
408
+ ctx->range.len = ngx_sprintf(p, "bytes=%O-%O", ctx->start,
409
+ ctx->start + (off_t) slcf->size - 1)
410
+ - p;
411
+ }
412
+
413
+ v->data = ctx->range.data;
414
+ v->valid = 1;
415
+ v->not_found = 0;
416
+ v->no_cacheable = 1;
417
+ v->len = ctx->range.len;
418
+
419
+ return NGX_OK;
420
+ }
421
+
422
+
423
+ static off_t
424
+ ngx_http_slice_get_start(ngx_http_request_t *r)
425
+ {
426
+ off_t start, cutoff, cutlim;
427
+ u_char *p;
428
+ ngx_table_elt_t *h;
429
+
430
+ if (r->headers_in.if_range) {
431
+ return 0;
432
+ }
433
+
434
+ h = r->headers_in.range;
435
+
436
+ if (h == NULL
437
+ || h->value.len < 7
438
+ || ngx_strncasecmp(h->value.data, (u_char *) "bytes=", 6) != 0)
439
+ {
440
+ return 0;
441
+ }
442
+
443
+ p = h->value.data + 6;
444
+
445
+ if (ngx_strchr(p, ',')) {
446
+ return 0;
447
+ }
448
+
449
+ while (*p == ' ') { p++; }
450
+
451
+ if (*p == '-') {
452
+ return 0;
453
+ }
454
+
455
+ cutoff = NGX_MAX_OFF_T_VALUE / 10;
456
+ cutlim = NGX_MAX_OFF_T_VALUE % 10;
457
+
458
+ start = 0;
459
+
460
+ while (*p >= '0' && *p <= '9') {
461
+ if (start >= cutoff && (start > cutoff || *p - '0' > cutlim)) {
462
+ return 0;
463
+ }
464
+
465
+ start = start * 10 + *p++ - '0';
466
+ }
467
+
468
+ return start;
469
+ }
470
+
471
+
472
+ static void *
473
+ ngx_http_slice_create_loc_conf(ngx_conf_t *cf)
474
+ {
475
+ ngx_http_slice_loc_conf_t *slcf;
476
+
477
+ slcf = ngx_palloc(cf->pool, sizeof(ngx_http_slice_loc_conf_t));
478
+ if (slcf == NULL) {
479
+ return NULL;
480
+ }
481
+
482
+ slcf->size = NGX_CONF_UNSET_SIZE;
483
+
484
+ return slcf;
485
+ }
486
+
487
+
488
+ static char *
489
+ ngx_http_slice_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
490
+ {
491
+ ngx_http_slice_loc_conf_t *prev = parent;
492
+ ngx_http_slice_loc_conf_t *conf = child;
493
+
494
+ ngx_conf_merge_size_value(conf->size, prev->size, 0);
495
+
496
+ return NGX_CONF_OK;
497
+ }
498
+
499
+
500
+ static ngx_int_t
501
+ ngx_http_slice_add_variables(ngx_conf_t *cf)
502
+ {
503
+ ngx_http_variable_t *var;
504
+
505
+ var = ngx_http_add_variable(cf, &ngx_http_slice_range_name, 0);
506
+ if (var == NULL) {
507
+ return NGX_ERROR;
508
+ }
509
+
510
+ var->get_handler = ngx_http_slice_range_variable;
511
+
512
+ return NGX_OK;
513
+ }
514
+
515
+
516
+ static ngx_int_t
517
+ ngx_http_slice_init(ngx_conf_t *cf)
518
+ {
519
+ ngx_http_next_header_filter = ngx_http_top_header_filter;
520
+ ngx_http_top_header_filter = ngx_http_slice_header_filter;
521
+
522
+ ngx_http_next_body_filter = ngx_http_top_body_filter;
523
+ ngx_http_top_body_filter = ngx_http_slice_body_filter;
524
+
525
+ return NGX_OK;
526
+ }