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
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
  #define NGX_HTTP_MAX_URI_CHANGES 10
13
- #define NGX_HTTP_MAX_SUBREQUESTS 200
13
+ #define NGX_HTTP_MAX_SUBREQUESTS 50
14
14
 
15
15
  /* must be 2^n */
16
16
  #define NGX_HTTP_LC_HEADER_LEN 32
@@ -23,6 +23,7 @@
23
23
  #define NGX_HTTP_VERSION_9 9
24
24
  #define NGX_HTTP_VERSION_10 1000
25
25
  #define NGX_HTTP_VERSION_11 1001
26
+ #define NGX_HTTP_VERSION_20 2000
26
27
 
27
28
  #define NGX_HTTP_UNKNOWN 0x0001
28
29
  #define NGX_HTTP_GET 0x0002
@@ -270,6 +271,7 @@ typedef struct {
270
271
  ngx_array_t cache_control;
271
272
 
272
273
  off_t content_length_n;
274
+ off_t content_offset;
273
275
  time_t date_time;
274
276
  time_t last_modified_time;
275
277
  } ngx_http_headers_out_t;
@@ -282,6 +284,9 @@ typedef struct {
282
284
  ngx_chain_t *bufs;
283
285
  ngx_buf_t *buf;
284
286
  off_t rest;
287
+ #if (NGX_HTTP_V2)
288
+ off_t received;
289
+ #endif
285
290
  ngx_chain_t *free;
286
291
  ngx_chain_t *busy;
287
292
  ngx_http_chunked_t *chunked;
@@ -431,16 +436,16 @@ struct ngx_http_request_s {
431
436
  ngx_uint_t err_status;
432
437
 
433
438
  ngx_http_connection_t *http_connection;
434
- #if (NGX_HTTP_SPDY)
435
- ngx_http_spdy_stream_t *spdy_stream;
439
+ #if (NGX_HTTP_V2)
440
+ ngx_http_v2_stream_t *stream;
436
441
  #endif
437
442
 
438
443
  ngx_http_log_handler_pt log_handler;
439
444
 
440
445
  ngx_http_cleanup_t *cleanup;
441
446
 
447
+ unsigned count:16;
442
448
  unsigned subrequests:8;
443
- unsigned count:8;
444
449
  unsigned blocked:8;
445
450
 
446
451
  unsigned aio:1;
@@ -529,6 +534,7 @@ struct ngx_http_request_s {
529
534
  unsigned filter_need_in_memory:1;
530
535
  unsigned filter_need_temporary:1;
531
536
  unsigned allow_ranges:1;
537
+ unsigned subrequest_ranges:1;
532
538
  unsigned single_range:1;
533
539
  unsigned disable_not_modified:1;
534
540
 
@@ -586,17 +592,6 @@ extern ngx_http_header_t ngx_http_headers_in[];
586
592
  extern ngx_http_header_out_t ngx_http_headers_out[];
587
593
 
588
594
 
589
- #define ngx_http_set_connection_log(c, l) \
590
- \
591
- c->log->file = l->file; \
592
- c->log->next = l->next; \
593
- c->log->writer = l->writer; \
594
- c->log->wdata = l->wdata; \
595
- if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { \
596
- c->log->log_level = l->log_level; \
597
- }
598
-
599
-
600
595
  #define ngx_http_set_log_request(log, r) \
601
596
  ((ngx_http_log_ctx_t *) log->data)->current_request = r
602
597
 
@@ -34,33 +34,28 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
34
34
  ssize_t size;
35
35
  ngx_int_t rc;
36
36
  ngx_buf_t *b;
37
- ngx_chain_t out, *cl;
37
+ ngx_chain_t out;
38
38
  ngx_http_request_body_t *rb;
39
39
  ngx_http_core_loc_conf_t *clcf;
40
40
 
41
41
  r->main->count++;
42
42
 
43
- #if (NGX_HTTP_SPDY)
44
- if (r->spdy_stream && r == r->main) {
45
- r->request_body_no_buffering = 0;
46
- rc = ngx_http_spdy_read_request_body(r, post_handler);
47
- goto done;
48
- }
49
- #endif
50
-
51
43
  if (r != r->main || r->request_body || r->discard_body) {
52
44
  r->request_body_no_buffering = 0;
53
45
  post_handler(r);
54
46
  return NGX_OK;
55
47
  }
56
48
 
57
- if (ngx_http_test_expect(r) != NGX_OK) {
58
- rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
49
+ #if (NGX_HTTP_V2)
50
+ if (r->stream) {
51
+ rc = ngx_http_v2_read_request_body(r, post_handler);
59
52
  goto done;
60
53
  }
54
+ #endif
61
55
 
62
- if (r->request_body_no_buffering) {
63
- r->request_body_in_file_only = 0;
56
+ if (ngx_http_test_expect(r) != NGX_OK) {
57
+ rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
58
+ goto done;
64
59
  }
65
60
 
66
61
  rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
@@ -148,40 +143,8 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
148
143
 
149
144
  if (rb->rest == 0) {
150
145
  /* the whole request body was pre-read */
151
-
152
- if (r->request_body_in_file_only) {
153
- if (ngx_http_write_request_body(r) != NGX_OK) {
154
- rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
155
- goto done;
156
- }
157
-
158
- if (rb->temp_file->file.offset != 0) {
159
-
160
- cl = ngx_chain_get_free_buf(r->pool, &rb->free);
161
- if (cl == NULL) {
162
- rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
163
- goto done;
164
- }
165
-
166
- b = cl->buf;
167
-
168
- ngx_memzero(b, sizeof(ngx_buf_t));
169
-
170
- b->in_file = 1;
171
- b->file_last = rb->temp_file->file.offset;
172
- b->file = &rb->temp_file->file;
173
-
174
- rb->bufs = cl;
175
-
176
- } else {
177
- rb->bufs = NULL;
178
- }
179
- }
180
-
181
146
  r->request_body_no_buffering = 0;
182
-
183
147
  post_handler(r);
184
-
185
148
  return NGX_OK;
186
149
  }
187
150
 
@@ -251,6 +214,18 @@ ngx_http_read_unbuffered_request_body(ngx_http_request_t *r)
251
214
  {
252
215
  ngx_int_t rc;
253
216
 
217
+ #if (NGX_HTTP_V2)
218
+ if (r->stream) {
219
+ rc = ngx_http_v2_read_unbuffered_request_body(r);
220
+
221
+ if (rc == NGX_OK) {
222
+ r->reading_body = 0;
223
+ }
224
+
225
+ return rc;
226
+ }
227
+ #endif
228
+
254
229
  if (r->connection->read->timedout) {
255
230
  r->connection->timedout = 1;
256
231
  return NGX_HTTP_REQUEST_TIME_OUT;
@@ -292,8 +267,7 @@ ngx_http_do_read_client_request_body(ngx_http_request_t *r)
292
267
  size_t size;
293
268
  ssize_t n;
294
269
  ngx_int_t rc;
295
- ngx_buf_t *b;
296
- ngx_chain_t *cl, out;
270
+ ngx_chain_t out;
297
271
  ngx_connection_t *c;
298
272
  ngx_http_request_body_t *rb;
299
273
  ngx_http_core_loc_conf_t *clcf;
@@ -442,36 +416,6 @@ ngx_http_do_read_client_request_body(ngx_http_request_t *r)
442
416
  ngx_del_timer(c->read);
443
417
  }
444
418
 
445
- if (rb->temp_file || r->request_body_in_file_only) {
446
-
447
- /* save the last part */
448
-
449
- if (ngx_http_write_request_body(r) != NGX_OK) {
450
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
451
- }
452
-
453
- if (rb->temp_file->file.offset != 0) {
454
-
455
- cl = ngx_chain_get_free_buf(r->pool, &rb->free);
456
- if (cl == NULL) {
457
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
458
- }
459
-
460
- b = cl->buf;
461
-
462
- ngx_memzero(b, sizeof(ngx_buf_t));
463
-
464
- b->in_file = 1;
465
- b->file_last = rb->temp_file->file.offset;
466
- b->file = &rb->temp_file->file;
467
-
468
- rb->bufs = cl;
469
-
470
- } else {
471
- rb->bufs = NULL;
472
- }
473
- }
474
-
475
419
  if (!r->request_body_no_buffering) {
476
420
  r->read_event_handler = ngx_http_block_reading;
477
421
  rb->post_handler(r);
@@ -570,16 +514,16 @@ ngx_http_discard_request_body(ngx_http_request_t *r)
570
514
  ngx_int_t rc;
571
515
  ngx_event_t *rev;
572
516
 
573
- #if (NGX_HTTP_SPDY)
574
- if (r->spdy_stream && r == r->main) {
575
- r->spdy_stream->skip_data = NGX_SPDY_DATA_DISCARD;
517
+ if (r != r->main || r->discard_body || r->request_body) {
576
518
  return NGX_OK;
577
519
  }
578
- #endif
579
520
 
580
- if (r != r->main || r->discard_body || r->request_body) {
521
+ #if (NGX_HTTP_V2)
522
+ if (r->stream) {
523
+ r->stream->skip_data = 1;
581
524
  return NGX_OK;
582
525
  }
526
+ #endif
583
527
 
584
528
  if (ngx_http_test_expect(r) != NGX_OK) {
585
529
  return NGX_HTTP_INTERNAL_SERVER_ERROR;
@@ -1133,9 +1077,8 @@ ngx_http_request_body_chunked_filter(ngx_http_request_t *r, ngx_chain_t *in)
1133
1077
  ngx_int_t
1134
1078
  ngx_http_request_body_save_filter(ngx_http_request_t *r, ngx_chain_t *in)
1135
1079
  {
1136
- #if (NGX_DEBUG)
1080
+ ngx_buf_t *b;
1137
1081
  ngx_chain_t *cl;
1138
- #endif
1139
1082
  ngx_http_request_body_t *rb;
1140
1083
 
1141
1084
  rb = r->request_body;
@@ -1172,13 +1115,46 @@ ngx_http_request_body_save_filter(ngx_http_request_t *r, ngx_chain_t *in)
1172
1115
  return NGX_HTTP_INTERNAL_SERVER_ERROR;
1173
1116
  }
1174
1117
 
1175
- if (rb->rest > 0
1176
- && rb->buf && rb->buf->last == rb->buf->end
1177
- && !r->request_body_no_buffering)
1178
- {
1118
+ if (r->request_body_no_buffering) {
1119
+ return NGX_OK;
1120
+ }
1121
+
1122
+ if (rb->rest > 0) {
1123
+
1124
+ if (rb->buf && rb->buf->last == rb->buf->end
1125
+ && ngx_http_write_request_body(r) != NGX_OK)
1126
+ {
1127
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
1128
+ }
1129
+
1130
+ return NGX_OK;
1131
+ }
1132
+
1133
+ /* rb->rest == 0 */
1134
+
1135
+ if (rb->temp_file || r->request_body_in_file_only) {
1136
+
1179
1137
  if (ngx_http_write_request_body(r) != NGX_OK) {
1180
1138
  return NGX_HTTP_INTERNAL_SERVER_ERROR;
1181
1139
  }
1140
+
1141
+ if (rb->temp_file->file.offset != 0) {
1142
+
1143
+ cl = ngx_chain_get_free_buf(r->pool, &rb->free);
1144
+ if (cl == NULL) {
1145
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
1146
+ }
1147
+
1148
+ b = cl->buf;
1149
+
1150
+ ngx_memzero(b, sizeof(ngx_buf_t));
1151
+
1152
+ b->in_file = 1;
1153
+ b->file_last = rb->temp_file->file.offset;
1154
+ b->file = &rb->temp_file->file;
1155
+
1156
+ rb->bufs = cl;
1157
+ }
1182
1158
  }
1183
1159
 
1184
1160
  return NGX_OK;
@@ -19,10 +19,10 @@ static ngx_int_t ngx_http_script_add_var_code(ngx_http_script_compile_t *sc,
19
19
  static ngx_int_t ngx_http_script_add_args_code(ngx_http_script_compile_t *sc);
20
20
  #if (NGX_PCRE)
21
21
  static ngx_int_t ngx_http_script_add_capture_code(ngx_http_script_compile_t *sc,
22
- ngx_uint_t n);
22
+ ngx_uint_t n);
23
23
  #endif
24
24
  static ngx_int_t
25
- ngx_http_script_add_full_name_code(ngx_http_script_compile_t *sc);
25
+ ngx_http_script_add_full_name_code(ngx_http_script_compile_t *sc);
26
26
  static size_t ngx_http_script_full_name_len_code(ngx_http_script_engine_t *e);
27
27
  static void ngx_http_script_full_name_code(ngx_http_script_engine_t *e);
28
28
 
@@ -1488,7 +1488,7 @@ ngx_http_script_file_code(ngx_http_script_engine_t *e)
1488
1488
  r = e->request;
1489
1489
 
1490
1490
  ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1491
- "http script file op %p \"%V\"", code->op, &path);
1491
+ "http script file op %p \"%V\"", (void *) code->op, &path);
1492
1492
 
1493
1493
  clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1494
1494
 
@@ -359,9 +359,6 @@ static ngx_str_t ngx_http_error_pages[] = {
359
359
  };
360
360
 
361
361
 
362
- static ngx_str_t ngx_http_get_name = { 3, (u_char *) "GET " };
363
-
364
-
365
362
  ngx_int_t
366
363
  ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
367
364
  {
@@ -564,7 +561,7 @@ ngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)
564
561
 
565
562
  if (r->method != NGX_HTTP_HEAD) {
566
563
  r->method = NGX_HTTP_GET;
567
- r->method_name = ngx_http_get_name;
564
+ r->method_name = ngx_http_core_get_method;
568
565
  }
569
566
 
570
567
  return ngx_http_internal_redirect(r, &uri, &args);
@@ -76,6 +76,13 @@ static void
76
76
  static ngx_int_t ngx_http_upstream_non_buffered_filter_init(void *data);
77
77
  static ngx_int_t ngx_http_upstream_non_buffered_filter(void *data,
78
78
  ssize_t bytes);
79
+ #if (NGX_THREADS)
80
+ static ngx_int_t ngx_http_upstream_thread_handler(ngx_thread_task_t *task,
81
+ ngx_file_t *file);
82
+ static void ngx_http_upstream_thread_event_handler(ngx_event_t *ev);
83
+ #endif
84
+ static ngx_int_t ngx_http_upstream_output_filter(void *data,
85
+ ngx_chain_t *chain);
79
86
  static void ngx_http_upstream_process_downstream(ngx_http_request_t *r);
80
87
  static void ngx_http_upstream_process_upstream(ngx_http_request_t *r,
81
88
  ngx_http_upstream_t *u);
@@ -250,6 +257,11 @@ ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = {
250
257
  ngx_http_upstream_copy_allow_ranges,
251
258
  offsetof(ngx_http_headers_out_t, accept_ranges), 1 },
252
259
 
260
+ { ngx_string("Content-Range"),
261
+ ngx_http_upstream_ignore_header_line, 0,
262
+ ngx_http_upstream_copy_header_line,
263
+ offsetof(ngx_http_headers_out_t, content_range), 0 },
264
+
253
265
  { ngx_string("Connection"),
254
266
  ngx_http_upstream_process_connection, 0,
255
267
  ngx_http_upstream_ignore_header_line, 0, 0 },
@@ -363,6 +375,10 @@ static ngx_http_variable_t ngx_http_upstream_vars[] = {
363
375
  ngx_http_upstream_status_variable, 0,
364
376
  NGX_HTTP_VAR_NOCACHEABLE, 0 },
365
377
 
378
+ { ngx_string("upstream_connect_time"), NULL,
379
+ ngx_http_upstream_response_time_variable, 2,
380
+ NGX_HTTP_VAR_NOCACHEABLE, 0 },
381
+
366
382
  { ngx_string("upstream_header_time"), NULL,
367
383
  ngx_http_upstream_response_time_variable, 1,
368
384
  NGX_HTTP_VAR_NOCACHEABLE, 0 },
@@ -407,10 +423,10 @@ static ngx_http_upstream_next_t ngx_http_upstream_next_errors[] = {
407
423
 
408
424
 
409
425
  ngx_conf_bitmask_t ngx_http_upstream_cache_method_mask[] = {
410
- { ngx_string("GET"), NGX_HTTP_GET},
411
- { ngx_string("HEAD"), NGX_HTTP_HEAD },
412
- { ngx_string("POST"), NGX_HTTP_POST },
413
- { ngx_null_string, 0 }
426
+ { ngx_string("GET"), NGX_HTTP_GET },
427
+ { ngx_string("HEAD"), NGX_HTTP_HEAD },
428
+ { ngx_string("POST"), NGX_HTTP_POST },
429
+ { ngx_null_string, 0 }
414
430
  };
415
431
 
416
432
 
@@ -471,8 +487,8 @@ ngx_http_upstream_init(ngx_http_request_t *r)
471
487
  ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
472
488
  "http init upstream, client timer: %d", c->read->timer_set);
473
489
 
474
- #if (NGX_HTTP_SPDY)
475
- if (r->spdy_stream) {
490
+ #if (NGX_HTTP_V2)
491
+ if (r->stream) {
476
492
  ngx_http_upstream_init_request(r);
477
493
  return;
478
494
  }
@@ -629,8 +645,20 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)
629
645
  u->ssl_name = u->resolved->host;
630
646
  #endif
631
647
 
648
+ host = &u->resolved->host;
649
+
632
650
  if (u->resolved->sockaddr) {
633
651
 
652
+ if (u->resolved->port == 0
653
+ && u->resolved->sockaddr->sa_family != AF_UNIX)
654
+ {
655
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
656
+ "no port in upstream \"%V\"", host);
657
+ ngx_http_upstream_finalize_request(r, u,
658
+ NGX_HTTP_INTERNAL_SERVER_ERROR);
659
+ return;
660
+ }
661
+
634
662
  if (ngx_http_upstream_create_round_robin_peer(r, u->resolved)
635
663
  != NGX_OK)
636
664
  {
@@ -644,8 +672,6 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)
644
672
  return;
645
673
  }
646
674
 
647
- host = &u->resolved->host;
648
-
649
675
  umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
650
676
 
651
677
  uscfp = umcf->upstreams.elts;
@@ -760,7 +786,7 @@ ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
760
786
  return rc;
761
787
  }
762
788
 
763
- if (r->method & NGX_HTTP_HEAD) {
789
+ if (r->method == NGX_HTTP_HEAD && u->conf->cache_convert_head) {
764
790
  u->method = ngx_http_core_get_method;
765
791
  }
766
792
 
@@ -1147,8 +1173,8 @@ ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
1147
1173
  return;
1148
1174
  }
1149
1175
 
1150
- #if (NGX_HTTP_SPDY)
1151
- if (r->spdy_stream) {
1176
+ #if (NGX_HTTP_V2)
1177
+ if (r->stream) {
1152
1178
  return;
1153
1179
  }
1154
1180
  #endif
@@ -1303,15 +1329,12 @@ static void
1303
1329
  ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
1304
1330
  {
1305
1331
  ngx_int_t rc;
1306
- ngx_time_t *tp;
1307
1332
  ngx_connection_t *c;
1308
1333
 
1309
1334
  r->connection->log->action = "connecting to upstream";
1310
1335
 
1311
- if (u->state && u->state->response_sec) {
1312
- tp = ngx_timeofday();
1313
- u->state->response_sec = tp->sec - u->state->response_sec;
1314
- u->state->response_msec = tp->msec - u->state->response_msec;
1336
+ if (u->state && u->state->response_time) {
1337
+ u->state->response_time = ngx_current_msec - u->state->response_time;
1315
1338
  }
1316
1339
 
1317
1340
  u->state = ngx_array_push(r->upstream_states);
@@ -1323,10 +1346,9 @@ ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
1323
1346
 
1324
1347
  ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
1325
1348
 
1326
- tp = ngx_timeofday();
1327
- u->state->response_sec = tp->sec;
1328
- u->state->response_msec = tp->msec;
1329
- u->state->header_sec = (time_t) NGX_ERROR;
1349
+ u->state->response_time = ngx_current_msec;
1350
+ u->state->connect_time = (ngx_msec_t) -1;
1351
+ u->state->header_time = (ngx_msec_t) -1;
1330
1352
 
1331
1353
  rc = ngx_event_connect_peer(&u->peer);
1332
1354
 
@@ -1426,6 +1448,7 @@ ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
1426
1448
  }
1427
1449
 
1428
1450
  u->request_sent = 0;
1451
+ u->request_body_sent = 0;
1429
1452
 
1430
1453
  if (rc == NGX_AGAIN) {
1431
1454
  ngx_add_timer(c->write, u->conf->connect_timeout);
@@ -1768,6 +1791,10 @@ ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u,
1768
1791
  ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
1769
1792
  "http upstream send request");
1770
1793
 
1794
+ if (u->state->connect_time == (ngx_msec_t) -1) {
1795
+ u->state->connect_time = ngx_current_msec - u->state->response_time;
1796
+ }
1797
+
1771
1798
  if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {
1772
1799
  ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
1773
1800
  return;
@@ -1806,6 +1833,8 @@ ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u,
1806
1833
 
1807
1834
  /* rc == NGX_OK */
1808
1835
 
1836
+ u->request_body_sent = 1;
1837
+
1809
1838
  if (c->write->timer_set) {
1810
1839
  ngx_del_timer(c->write);
1811
1840
  }
@@ -1854,17 +1883,17 @@ ngx_http_upstream_send_request_body(ngx_http_request_t *r,
1854
1883
 
1855
1884
  if (!r->request_body_no_buffering) {
1856
1885
 
1857
- /* buffered request body */
1886
+ /* buffered request body */
1858
1887
 
1859
- if (!u->request_sent) {
1860
- u->request_sent = 1;
1861
- out = u->request_bufs;
1888
+ if (!u->request_sent) {
1889
+ u->request_sent = 1;
1890
+ out = u->request_bufs;
1862
1891
 
1863
- } else {
1864
- out = NULL;
1865
- }
1892
+ } else {
1893
+ out = NULL;
1894
+ }
1866
1895
 
1867
- return ngx_output_chain(&u->output, out);
1896
+ return ngx_output_chain(&u->output, out);
1868
1897
  }
1869
1898
 
1870
1899
  if (!u->request_sent) {
@@ -2020,7 +2049,6 @@ ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u)
2020
2049
  {
2021
2050
  ssize_t n;
2022
2051
  ngx_int_t rc;
2023
- ngx_time_t *tp;
2024
2052
  ngx_connection_t *c;
2025
2053
 
2026
2054
  c = u->peer.connection;
@@ -2141,9 +2169,7 @@ ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u)
2141
2169
 
2142
2170
  /* rc == NGX_OK */
2143
2171
 
2144
- tp = ngx_timeofday();
2145
- u->state->header_sec = tp->sec - u->state->response_sec;
2146
- u->state->header_msec = tp->msec - u->state->response_msec;
2172
+ u->state->header_time = ngx_current_msec - u->state->response_time;
2147
2173
 
2148
2174
  if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) {
2149
2175
 
@@ -2480,6 +2506,7 @@ ngx_http_upstream_process_headers(ngx_http_request_t *r, ngx_http_upstream_t *u)
2480
2506
 
2481
2507
  if (r->method != NGX_HTTP_HEAD) {
2482
2508
  r->method = NGX_HTTP_GET;
2509
+ r->method_name = ngx_http_core_get_method;
2483
2510
  }
2484
2511
 
2485
2512
  ngx_http_internal_redirect(r, &uri, &args);
@@ -2841,11 +2868,16 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
2841
2868
  ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
2842
2869
  }
2843
2870
 
2871
+ if (r->header_only && !u->cacheable && !u->store) {
2872
+ ngx_http_upstream_finalize_request(r, u, 0);
2873
+ return;
2874
+ }
2875
+
2844
2876
  #endif
2845
2877
 
2846
2878
  p = u->pipe;
2847
2879
 
2848
- p->output_filter = (ngx_event_pipe_output_filter_pt) ngx_http_output_filter;
2880
+ p->output_filter = ngx_http_upstream_output_filter;
2849
2881
  p->output_ctx = r;
2850
2882
  p->tag = u->output.tag;
2851
2883
  p->bufs = u->conf->bufs;
@@ -2888,6 +2920,13 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
2888
2920
  p->max_temp_file_size = u->conf->max_temp_file_size;
2889
2921
  p->temp_file_write_size = u->conf->temp_file_write_size;
2890
2922
 
2923
+ #if (NGX_THREADS)
2924
+ if (clcf->aio == NGX_HTTP_AIO_THREADS && clcf->aio_write) {
2925
+ p->thread_handler = ngx_http_upstream_thread_handler;
2926
+ p->thread_ctx = r;
2927
+ }
2928
+ #endif
2929
+
2891
2930
  p->preread_bufs = ngx_alloc_chain_link(r->pool);
2892
2931
  if (p->preread_bufs == NULL) {
2893
2932
  ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
@@ -2914,7 +2953,7 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
2914
2953
  p->buf_to_file->temporary = 1;
2915
2954
  }
2916
2955
 
2917
- if (ngx_event_flags & NGX_USE_AIO_EVENT) {
2956
+ if (ngx_event_flags & NGX_USE_IOCP_EVENT) {
2918
2957
  /* the posted aio operation may corrupt a shadow buffer */
2919
2958
  p->single_buf = 1;
2920
2959
  }
@@ -3462,6 +3501,97 @@ ngx_http_upstream_non_buffered_filter(void *data, ssize_t bytes)
3462
3501
  }
3463
3502
 
3464
3503
 
3504
+ #if (NGX_THREADS)
3505
+
3506
+ static ngx_int_t
3507
+ ngx_http_upstream_thread_handler(ngx_thread_task_t *task, ngx_file_t *file)
3508
+ {
3509
+ ngx_str_t name;
3510
+ ngx_event_pipe_t *p;
3511
+ ngx_thread_pool_t *tp;
3512
+ ngx_http_request_t *r;
3513
+ ngx_http_core_loc_conf_t *clcf;
3514
+
3515
+ r = file->thread_ctx;
3516
+ p = r->upstream->pipe;
3517
+
3518
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
3519
+ tp = clcf->thread_pool;
3520
+
3521
+ if (tp == NULL) {
3522
+ if (ngx_http_complex_value(r, clcf->thread_pool_value, &name)
3523
+ != NGX_OK)
3524
+ {
3525
+ return NGX_ERROR;
3526
+ }
3527
+
3528
+ tp = ngx_thread_pool_get((ngx_cycle_t *) ngx_cycle, &name);
3529
+
3530
+ if (tp == NULL) {
3531
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
3532
+ "thread pool \"%V\" not found", &name);
3533
+ return NGX_ERROR;
3534
+ }
3535
+ }
3536
+
3537
+ task->event.data = r;
3538
+ task->event.handler = ngx_http_upstream_thread_event_handler;
3539
+
3540
+ if (ngx_thread_task_post(tp, task) != NGX_OK) {
3541
+ return NGX_ERROR;
3542
+ }
3543
+
3544
+ r->main->blocked++;
3545
+ r->aio = 1;
3546
+ p->aio = 1;
3547
+
3548
+ return NGX_OK;
3549
+ }
3550
+
3551
+
3552
+ static void
3553
+ ngx_http_upstream_thread_event_handler(ngx_event_t *ev)
3554
+ {
3555
+ ngx_connection_t *c;
3556
+ ngx_http_request_t *r;
3557
+
3558
+ r = ev->data;
3559
+ c = r->connection;
3560
+
3561
+ ngx_http_set_log_request(c->log, r);
3562
+
3563
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
3564
+ "http upstream thread: \"%V?%V\"", &r->uri, &r->args);
3565
+
3566
+ r->main->blocked--;
3567
+ r->aio = 0;
3568
+
3569
+ r->write_event_handler(r);
3570
+
3571
+ ngx_http_run_posted_requests(c);
3572
+ }
3573
+
3574
+ #endif
3575
+
3576
+
3577
+ static ngx_int_t
3578
+ ngx_http_upstream_output_filter(void *data, ngx_chain_t *chain)
3579
+ {
3580
+ ngx_int_t rc;
3581
+ ngx_event_pipe_t *p;
3582
+ ngx_http_request_t *r;
3583
+
3584
+ r = data;
3585
+ p = r->upstream->pipe;
3586
+
3587
+ rc = ngx_http_output_filter(r, chain);
3588
+
3589
+ p->aio = r->aio;
3590
+
3591
+ return rc;
3592
+ }
3593
+
3594
+
3465
3595
  static void
3466
3596
  ngx_http_upstream_process_downstream(ngx_http_request_t *r)
3467
3597
  {
@@ -3480,6 +3610,10 @@ ngx_http_upstream_process_downstream(ngx_http_request_t *r)
3480
3610
 
3481
3611
  c->log->action = "sending to client";
3482
3612
 
3613
+ #if (NGX_THREADS)
3614
+ p->aio = r->aio;
3615
+ #endif
3616
+
3483
3617
  if (wev->timedout) {
3484
3618
 
3485
3619
  if (wev->delayed) {
@@ -3609,6 +3743,12 @@ ngx_http_upstream_process_request(ngx_http_request_t *r,
3609
3743
 
3610
3744
  p = u->pipe;
3611
3745
 
3746
+ #if (NGX_THREADS)
3747
+ if (p->writing) {
3748
+ return;
3749
+ }
3750
+ #endif
3751
+
3612
3752
  if (u->peer.connection) {
3613
3753
 
3614
3754
  if (u->store) {
@@ -3733,7 +3873,7 @@ ngx_http_upstream_store(ngx_http_request_t *r, ngx_http_upstream_t *u)
3733
3873
 
3734
3874
  if (u->headers_in.last_modified) {
3735
3875
 
3736
- lm = ngx_http_parse_time(u->headers_in.last_modified->value.data,
3876
+ lm = ngx_parse_http_time(u->headers_in.last_modified->value.data,
3737
3877
  u->headers_in.last_modified->value.len);
3738
3878
 
3739
3879
  if (lm != NGX_ERROR) {
@@ -3807,42 +3947,36 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
3807
3947
  "upstream timed out");
3808
3948
  }
3809
3949
 
3810
- if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR
3811
- && (!u->request_sent || !r->request_body_no_buffering))
3812
- {
3813
- status = 0;
3814
-
3950
+ if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR) {
3815
3951
  /* TODO: inform balancer instead */
3816
-
3817
3952
  u->peer.tries++;
3953
+ }
3818
3954
 
3819
- } else {
3820
- switch (ft_type) {
3955
+ switch (ft_type) {
3821
3956
 
3822
- case NGX_HTTP_UPSTREAM_FT_TIMEOUT:
3823
- status = NGX_HTTP_GATEWAY_TIME_OUT;
3824
- break;
3957
+ case NGX_HTTP_UPSTREAM_FT_TIMEOUT:
3958
+ status = NGX_HTTP_GATEWAY_TIME_OUT;
3959
+ break;
3825
3960
 
3826
- case NGX_HTTP_UPSTREAM_FT_HTTP_500:
3827
- status = NGX_HTTP_INTERNAL_SERVER_ERROR;
3828
- break;
3961
+ case NGX_HTTP_UPSTREAM_FT_HTTP_500:
3962
+ status = NGX_HTTP_INTERNAL_SERVER_ERROR;
3963
+ break;
3829
3964
 
3830
- case NGX_HTTP_UPSTREAM_FT_HTTP_403:
3831
- status = NGX_HTTP_FORBIDDEN;
3832
- break;
3965
+ case NGX_HTTP_UPSTREAM_FT_HTTP_403:
3966
+ status = NGX_HTTP_FORBIDDEN;
3967
+ break;
3833
3968
 
3834
- case NGX_HTTP_UPSTREAM_FT_HTTP_404:
3835
- status = NGX_HTTP_NOT_FOUND;
3836
- break;
3969
+ case NGX_HTTP_UPSTREAM_FT_HTTP_404:
3970
+ status = NGX_HTTP_NOT_FOUND;
3971
+ break;
3837
3972
 
3838
- /*
3839
- * NGX_HTTP_UPSTREAM_FT_BUSY_LOCK and NGX_HTTP_UPSTREAM_FT_MAX_WAITING
3840
- * never reach here
3841
- */
3973
+ /*
3974
+ * NGX_HTTP_UPSTREAM_FT_BUSY_LOCK and NGX_HTTP_UPSTREAM_FT_MAX_WAITING
3975
+ * never reach here
3976
+ */
3842
3977
 
3843
- default:
3844
- status = NGX_HTTP_BAD_GATEWAY;
3845
- }
3978
+ default:
3979
+ status = NGX_HTTP_BAD_GATEWAY;
3846
3980
  }
3847
3981
 
3848
3982
  if (r->connection->error) {
@@ -3851,37 +3985,42 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
3851
3985
  return;
3852
3986
  }
3853
3987
 
3854
- if (status) {
3855
- u->state->status = status;
3856
- timeout = u->conf->next_upstream_timeout;
3988
+ u->state->status = status;
3857
3989
 
3858
- if (u->peer.tries == 0
3859
- || !(u->conf->next_upstream & ft_type)
3860
- || (u->request_sent && r->request_body_no_buffering)
3861
- || (timeout && ngx_current_msec - u->peer.start_time >= timeout))
3862
- {
3863
- #if (NGX_HTTP_CACHE)
3990
+ timeout = u->conf->next_upstream_timeout;
3864
3991
 
3865
- if (u->cache_status == NGX_HTTP_CACHE_EXPIRED
3866
- && (u->conf->cache_use_stale & ft_type))
3867
- {
3868
- ngx_int_t rc;
3992
+ if (u->request_sent
3993
+ && (r->method & (NGX_HTTP_POST|NGX_HTTP_LOCK|NGX_HTTP_PATCH)))
3994
+ {
3995
+ ft_type |= NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT;
3996
+ }
3869
3997
 
3870
- rc = u->reinit_request(r);
3998
+ if (u->peer.tries == 0
3999
+ || ((u->conf->next_upstream & ft_type) != ft_type)
4000
+ || (u->request_sent && r->request_body_no_buffering)
4001
+ || (timeout && ngx_current_msec - u->peer.start_time >= timeout))
4002
+ {
4003
+ #if (NGX_HTTP_CACHE)
3871
4004
 
3872
- if (rc == NGX_OK) {
3873
- u->cache_status = NGX_HTTP_CACHE_STALE;
3874
- rc = ngx_http_upstream_cache_send(r, u);
3875
- }
4005
+ if (u->cache_status == NGX_HTTP_CACHE_EXPIRED
4006
+ && (u->conf->cache_use_stale & ft_type))
4007
+ {
4008
+ ngx_int_t rc;
3876
4009
 
3877
- ngx_http_upstream_finalize_request(r, u, rc);
3878
- return;
4010
+ rc = u->reinit_request(r);
4011
+
4012
+ if (rc == NGX_OK) {
4013
+ u->cache_status = NGX_HTTP_CACHE_STALE;
4014
+ rc = ngx_http_upstream_cache_send(r, u);
3879
4015
  }
3880
- #endif
3881
4016
 
3882
- ngx_http_upstream_finalize_request(r, u, status);
4017
+ ngx_http_upstream_finalize_request(r, u, rc);
3883
4018
  return;
3884
4019
  }
4020
+ #endif
4021
+
4022
+ ngx_http_upstream_finalize_request(r, u, status);
4023
+ return;
3885
4024
  }
3886
4025
 
3887
4026
  if (u->peer.connection) {
@@ -3926,8 +4065,7 @@ static void
3926
4065
  ngx_http_upstream_finalize_request(ngx_http_request_t *r,
3927
4066
  ngx_http_upstream_t *u, ngx_int_t rc)
3928
4067
  {
3929
- ngx_uint_t flush;
3930
- ngx_time_t *tp;
4068
+ ngx_uint_t flush;
3931
4069
 
3932
4070
  ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3933
4071
  "finalize http upstream request: %i", rc);
@@ -3946,10 +4084,8 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r,
3946
4084
  u->resolved->ctx = NULL;
3947
4085
  }
3948
4086
 
3949
- if (u->state && u->state->response_sec) {
3950
- tp = ngx_timeofday();
3951
- u->state->response_sec = tp->sec - u->state->response_sec;
3952
- u->state->response_msec = tp->msec - u->state->response_msec;
4087
+ if (u->state && u->state->response_time) {
4088
+ u->state->response_time = ngx_current_msec - u->state->response_time;
3953
4089
 
3954
4090
  if (u->pipe && u->pipe->read_length) {
3955
4091
  u->state->response_length = u->pipe->read_length;
@@ -4051,7 +4187,8 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r,
4051
4187
 
4052
4188
  if (!u->header_sent
4053
4189
  || rc == NGX_HTTP_REQUEST_TIME_OUT
4054
- || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST)
4190
+ || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST
4191
+ || (u->pipe && u->pipe->downstream_error))
4055
4192
  {
4056
4193
  ngx_http_finalize_request(r, rc);
4057
4194
  return;
@@ -4133,7 +4270,7 @@ ngx_http_upstream_process_last_modified(ngx_http_request_t *r,
4133
4270
  #if (NGX_HTTP_CACHE)
4134
4271
 
4135
4272
  if (u->cacheable) {
4136
- u->headers_in.last_modified_time = ngx_http_parse_time(h->value.data,
4273
+ u->headers_in.last_modified_time = ngx_parse_http_time(h->value.data,
4137
4274
  h->value.len);
4138
4275
  }
4139
4276
 
@@ -4190,10 +4327,10 @@ ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
4190
4327
  pa = &u->headers_in.cache_control;
4191
4328
 
4192
4329
  if (pa->elts == NULL) {
4193
- if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK)
4194
- {
4195
- return NGX_ERROR;
4196
- }
4330
+ if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK)
4331
+ {
4332
+ return NGX_ERROR;
4333
+ }
4197
4334
  }
4198
4335
 
4199
4336
  ph = ngx_array_push(pa);
@@ -4297,7 +4434,7 @@ ngx_http_upstream_process_expires(ngx_http_request_t *r, ngx_table_elt_t *h,
4297
4434
  return NGX_OK;
4298
4435
  }
4299
4436
 
4300
- expires = ngx_http_parse_time(h->value.data, h->value.len);
4437
+ expires = ngx_parse_http_time(h->value.data, h->value.len);
4301
4438
 
4302
4439
  if (expires == NGX_ERROR || expires < ngx_time()) {
4303
4440
  u->cacheable = 0;
@@ -5023,15 +5160,14 @@ ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
5023
5160
  for ( ;; ) {
5024
5161
  if (state[i].status) {
5025
5162
 
5026
- if (data
5027
- && state[i].header_sec != (time_t) NGX_ERROR)
5028
- {
5029
- ms = (ngx_msec_int_t)
5030
- (state[i].header_sec * 1000 + state[i].header_msec);
5163
+ if (data == 1 && state[i].header_time != (ngx_msec_t) -1) {
5164
+ ms = state[i].header_time;
5165
+
5166
+ } else if (data == 2 && state[i].connect_time != (ngx_msec_t) -1) {
5167
+ ms = state[i].connect_time;
5031
5168
 
5032
5169
  } else {
5033
- ms = (ngx_msec_int_t)
5034
- (state[i].response_sec * 1000 + state[i].response_msec);
5170
+ ms = state[i].response_time;
5035
5171
  }
5036
5172
 
5037
5173
  ms = ngx_max(ms, 0);
@@ -5315,12 +5451,12 @@ ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
5315
5451
  return NGX_CONF_ERROR;
5316
5452
  }
5317
5453
 
5318
- for (m = 0; ngx_modules[m]; m++) {
5319
- if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
5454
+ for (m = 0; cf->cycle->modules[m]; m++) {
5455
+ if (cf->cycle->modules[m]->type != NGX_HTTP_MODULE) {
5320
5456
  continue;
5321
5457
  }
5322
5458
 
5323
- module = ngx_modules[m]->ctx;
5459
+ module = cf->cycle->modules[m]->ctx;
5324
5460
 
5325
5461
  if (module->create_srv_conf) {
5326
5462
  mconf = module->create_srv_conf(cf);
@@ -5328,7 +5464,7 @@ ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
5328
5464
  return NGX_CONF_ERROR;
5329
5465
  }
5330
5466
 
5331
- ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf;
5467
+ ctx->srv_conf[cf->cycle->modules[m]->ctx_index] = mconf;
5332
5468
  }
5333
5469
 
5334
5470
  if (module->create_loc_conf) {
@@ -5337,7 +5473,7 @@ ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
5337
5473
  return NGX_CONF_ERROR;
5338
5474
  }
5339
5475
 
5340
- ctx->loc_conf[ngx_modules[m]->ctx_index] = mconf;
5476
+ ctx->loc_conf[cf->cycle->modules[m]->ctx_index] = mconf;
5341
5477
  }
5342
5478
  }
5343
5479