nginxtra 1.0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (363) hide show
  1. data/VERSION +1 -0
  2. data/bin/nginxtra +5 -0
  3. data/lib/nginxtra.rb +12 -0
  4. data/lib/nginxtra/action.rb +36 -0
  5. data/lib/nginxtra/actions/compile.rb +60 -0
  6. data/lib/nginxtra/actions/install.rb +99 -0
  7. data/lib/nginxtra/actions/reload.rb +14 -0
  8. data/lib/nginxtra/actions/restart.rb +15 -0
  9. data/lib/nginxtra/actions/start.rb +53 -0
  10. data/lib/nginxtra/actions/status.rb +31 -0
  11. data/lib/nginxtra/actions/stop.rb +14 -0
  12. data/lib/nginxtra/cli.rb +77 -0
  13. data/lib/nginxtra/config.rb +339 -0
  14. data/lib/nginxtra/error.rb +13 -0
  15. data/lib/nginxtra/status.rb +57 -0
  16. data/src/nginx/CHANGES +5630 -0
  17. data/src/nginx/CHANGES.ru +5716 -0
  18. data/src/nginx/LICENSE +25 -0
  19. data/src/nginx/README +3 -0
  20. data/src/nginx/auto/cc/acc +15 -0
  21. data/src/nginx/auto/cc/bcc +72 -0
  22. data/src/nginx/auto/cc/ccc +46 -0
  23. data/src/nginx/auto/cc/conf +189 -0
  24. data/src/nginx/auto/cc/gcc +183 -0
  25. data/src/nginx/auto/cc/icc +121 -0
  26. data/src/nginx/auto/cc/msvc +138 -0
  27. data/src/nginx/auto/cc/name +101 -0
  28. data/src/nginx/auto/cc/owc +104 -0
  29. data/src/nginx/auto/cc/sunc +158 -0
  30. data/src/nginx/auto/define +12 -0
  31. data/src/nginx/auto/endianess +45 -0
  32. data/src/nginx/auto/feature +123 -0
  33. data/src/nginx/auto/have +12 -0
  34. data/src/nginx/auto/have_headers +12 -0
  35. data/src/nginx/auto/headers +13 -0
  36. data/src/nginx/auto/include +61 -0
  37. data/src/nginx/auto/init +51 -0
  38. data/src/nginx/auto/install +184 -0
  39. data/src/nginx/auto/lib/conf +83 -0
  40. data/src/nginx/auto/lib/geoip/conf +79 -0
  41. data/src/nginx/auto/lib/google-perftools/conf +45 -0
  42. data/src/nginx/auto/lib/libatomic/conf +43 -0
  43. data/src/nginx/auto/lib/libatomic/make +14 -0
  44. data/src/nginx/auto/lib/libgd/conf +83 -0
  45. data/src/nginx/auto/lib/libxslt/conf +156 -0
  46. data/src/nginx/auto/lib/make +32 -0
  47. data/src/nginx/auto/lib/md5/conf +103 -0
  48. data/src/nginx/auto/lib/md5/make +96 -0
  49. data/src/nginx/auto/lib/md5/makefile.bcc +22 -0
  50. data/src/nginx/auto/lib/md5/makefile.msvc +22 -0
  51. data/src/nginx/auto/lib/md5/makefile.owc +11 -0
  52. data/src/nginx/auto/lib/openssl/conf +74 -0
  53. data/src/nginx/auto/lib/openssl/make +67 -0
  54. data/src/nginx/auto/lib/openssl/makefile.bcc +18 -0
  55. data/src/nginx/auto/lib/openssl/makefile.msvc +14 -0
  56. data/src/nginx/auto/lib/pcre/conf +180 -0
  57. data/src/nginx/auto/lib/pcre/make +64 -0
  58. data/src/nginx/auto/lib/pcre/makefile.bcc +26 -0
  59. data/src/nginx/auto/lib/pcre/makefile.msvc +22 -0
  60. data/src/nginx/auto/lib/pcre/makefile.owc +24 -0
  61. data/src/nginx/auto/lib/perl/conf +60 -0
  62. data/src/nginx/auto/lib/perl/make +36 -0
  63. data/src/nginx/auto/lib/sha1/conf +79 -0
  64. data/src/nginx/auto/lib/sha1/make +96 -0
  65. data/src/nginx/auto/lib/sha1/makefile.bcc +22 -0
  66. data/src/nginx/auto/lib/sha1/makefile.msvc +22 -0
  67. data/src/nginx/auto/lib/sha1/makefile.owc +11 -0
  68. data/src/nginx/auto/lib/test +40 -0
  69. data/src/nginx/auto/lib/zlib/conf +76 -0
  70. data/src/nginx/auto/lib/zlib/make +114 -0
  71. data/src/nginx/auto/lib/zlib/makefile.bcc +15 -0
  72. data/src/nginx/auto/lib/zlib/makefile.msvc +14 -0
  73. data/src/nginx/auto/lib/zlib/makefile.owc +14 -0
  74. data/src/nginx/auto/lib/zlib/patch.zlib.h +10 -0
  75. data/src/nginx/auto/make +417 -0
  76. data/src/nginx/auto/modules +479 -0
  77. data/src/nginx/auto/nohave +12 -0
  78. data/src/nginx/auto/options +490 -0
  79. data/src/nginx/auto/os/conf +105 -0
  80. data/src/nginx/auto/os/darwin +116 -0
  81. data/src/nginx/auto/os/freebsd +136 -0
  82. data/src/nginx/auto/os/linux +152 -0
  83. data/src/nginx/auto/os/solaris +60 -0
  84. data/src/nginx/auto/os/win32 +29 -0
  85. data/src/nginx/auto/sources +518 -0
  86. data/src/nginx/auto/stubs +8 -0
  87. data/src/nginx/auto/summary +114 -0
  88. data/src/nginx/auto/types/sizeof +83 -0
  89. data/src/nginx/auto/types/typedef +77 -0
  90. data/src/nginx/auto/types/uintptr_t +42 -0
  91. data/src/nginx/auto/types/value +12 -0
  92. data/src/nginx/auto/unix +719 -0
  93. data/src/nginx/conf/fastcgi.conf +24 -0
  94. data/src/nginx/conf/fastcgi_params +23 -0
  95. data/src/nginx/conf/koi-utf +109 -0
  96. data/src/nginx/conf/koi-win +103 -0
  97. data/src/nginx/conf/mime.types +80 -0
  98. data/src/nginx/conf/nginx.conf +118 -0
  99. data/src/nginx/conf/scgi_params +15 -0
  100. data/src/nginx/conf/uwsgi_params +15 -0
  101. data/src/nginx/conf/win-utf +126 -0
  102. data/src/nginx/configure +108 -0
  103. data/src/nginx/contrib/README +15 -0
  104. data/src/nginx/contrib/geo2nginx.pl +58 -0
  105. data/src/nginx/contrib/unicode2nginx/koi-utf +131 -0
  106. data/src/nginx/contrib/unicode2nginx/unicode-to-nginx.pl +45 -0
  107. data/src/nginx/contrib/unicode2nginx/win-utf +130 -0
  108. data/src/nginx/html/50x.html +18 -0
  109. data/src/nginx/html/index.html +8 -0
  110. data/src/nginx/man/nginx.8 +202 -0
  111. data/src/nginx/src/core/nginx.c +1333 -0
  112. data/src/nginx/src/core/nginx.h +20 -0
  113. data/src/nginx/src/core/ngx_array.c +147 -0
  114. data/src/nginx/src/core/ngx_array.h +53 -0
  115. data/src/nginx/src/core/ngx_buf.c +218 -0
  116. data/src/nginx/src/core/ngx_buf.h +162 -0
  117. data/src/nginx/src/core/ngx_conf_file.c +1506 -0
  118. data/src/nginx/src/core/ngx_conf_file.h +348 -0
  119. data/src/nginx/src/core/ngx_config.h +134 -0
  120. data/src/nginx/src/core/ngx_connection.c +1074 -0
  121. data/src/nginx/src/core/ngx_connection.h +195 -0
  122. data/src/nginx/src/core/ngx_core.h +95 -0
  123. data/src/nginx/src/core/ngx_cpuinfo.c +139 -0
  124. data/src/nginx/src/core/ngx_crc.h +39 -0
  125. data/src/nginx/src/core/ngx_crc32.c +129 -0
  126. data/src/nginx/src/core/ngx_crc32.h +79 -0
  127. data/src/nginx/src/core/ngx_crypt.c +238 -0
  128. data/src/nginx/src/core/ngx_crypt.h +20 -0
  129. data/src/nginx/src/core/ngx_cycle.c +1379 -0
  130. data/src/nginx/src/core/ngx_cycle.h +142 -0
  131. data/src/nginx/src/core/ngx_file.c +993 -0
  132. data/src/nginx/src/core/ngx_file.h +151 -0
  133. data/src/nginx/src/core/ngx_hash.c +976 -0
  134. data/src/nginx/src/core/ngx_hash.h +122 -0
  135. data/src/nginx/src/core/ngx_inet.c +1008 -0
  136. data/src/nginx/src/core/ngx_inet.h +120 -0
  137. data/src/nginx/src/core/ngx_list.c +71 -0
  138. data/src/nginx/src/core/ngx_list.h +83 -0
  139. data/src/nginx/src/core/ngx_log.c +459 -0
  140. data/src/nginx/src/core/ngx_log.h +250 -0
  141. data/src/nginx/src/core/ngx_md5.c +289 -0
  142. data/src/nginx/src/core/ngx_md5.h +60 -0
  143. data/src/nginx/src/core/ngx_murmurhash.c +50 -0
  144. data/src/nginx/src/core/ngx_murmurhash.h +19 -0
  145. data/src/nginx/src/core/ngx_open_file_cache.c +882 -0
  146. data/src/nginx/src/core/ngx_open_file_cache.h +119 -0
  147. data/src/nginx/src/core/ngx_output_chain.c +673 -0
  148. data/src/nginx/src/core/ngx_palloc.c +433 -0
  149. data/src/nginx/src/core/ngx_palloc.h +95 -0
  150. data/src/nginx/src/core/ngx_parse.c +249 -0
  151. data/src/nginx/src/core/ngx_parse.h +24 -0
  152. data/src/nginx/src/core/ngx_queue.c +80 -0
  153. data/src/nginx/src/core/ngx_queue.h +112 -0
  154. data/src/nginx/src/core/ngx_radix_tree.c +291 -0
  155. data/src/nginx/src/core/ngx_radix_tree.h +46 -0
  156. data/src/nginx/src/core/ngx_rbtree.c +383 -0
  157. data/src/nginx/src/core/ngx_rbtree.h +84 -0
  158. data/src/nginx/src/core/ngx_regex.c +206 -0
  159. data/src/nginx/src/core/ngx_regex.h +56 -0
  160. data/src/nginx/src/core/ngx_resolver.c +2201 -0
  161. data/src/nginx/src/core/ngx_resolver.h +149 -0
  162. data/src/nginx/src/core/ngx_sha1.h +31 -0
  163. data/src/nginx/src/core/ngx_shmtx.c +284 -0
  164. data/src/nginx/src/core/ngx_shmtx.h +38 -0
  165. data/src/nginx/src/core/ngx_slab.c +701 -0
  166. data/src/nginx/src/core/ngx_slab.h +54 -0
  167. data/src/nginx/src/core/ngx_spinlock.c +53 -0
  168. data/src/nginx/src/core/ngx_string.c +1837 -0
  169. data/src/nginx/src/core/ngx_string.h +231 -0
  170. data/src/nginx/src/core/ngx_times.c +407 -0
  171. data/src/nginx/src/core/ngx_times.h +51 -0
  172. data/src/nginx/src/event/modules/ngx_aio_module.c +171 -0
  173. data/src/nginx/src/event/modules/ngx_devpoll_module.c +569 -0
  174. data/src/nginx/src/event/modules/ngx_epoll_module.c +833 -0
  175. data/src/nginx/src/event/modules/ngx_eventport_module.c +602 -0
  176. data/src/nginx/src/event/modules/ngx_kqueue_module.c +785 -0
  177. data/src/nginx/src/event/modules/ngx_poll_module.c +443 -0
  178. data/src/nginx/src/event/modules/ngx_rtsig_module.c +735 -0
  179. data/src/nginx/src/event/modules/ngx_select_module.c +435 -0
  180. data/src/nginx/src/event/modules/ngx_win32_select_module.c +400 -0
  181. data/src/nginx/src/event/ngx_event.c +1275 -0
  182. data/src/nginx/src/event/ngx_event.h +573 -0
  183. data/src/nginx/src/event/ngx_event_accept.c +428 -0
  184. data/src/nginx/src/event/ngx_event_busy_lock.c +286 -0
  185. data/src/nginx/src/event/ngx_event_busy_lock.h +65 -0
  186. data/src/nginx/src/event/ngx_event_connect.c +258 -0
  187. data/src/nginx/src/event/ngx_event_connect.h +76 -0
  188. data/src/nginx/src/event/ngx_event_mutex.c +70 -0
  189. data/src/nginx/src/event/ngx_event_openssl.c +2382 -0
  190. data/src/nginx/src/event/ngx_event_openssl.h +162 -0
  191. data/src/nginx/src/event/ngx_event_pipe.c +996 -0
  192. data/src/nginx/src/event/ngx_event_pipe.h +95 -0
  193. data/src/nginx/src/event/ngx_event_posted.c +173 -0
  194. data/src/nginx/src/event/ngx_event_posted.h +75 -0
  195. data/src/nginx/src/event/ngx_event_timer.c +159 -0
  196. data/src/nginx/src/event/ngx_event_timer.h +102 -0
  197. data/src/nginx/src/http/modules/ngx_http_access_module.c +384 -0
  198. data/src/nginx/src/http/modules/ngx_http_addition_filter_module.c +250 -0
  199. data/src/nginx/src/http/modules/ngx_http_auth_basic_module.c +478 -0
  200. data/src/nginx/src/http/modules/ngx_http_autoindex_module.c +701 -0
  201. data/src/nginx/src/http/modules/ngx_http_browser_module.c +713 -0
  202. data/src/nginx/src/http/modules/ngx_http_charset_filter_module.c +1681 -0
  203. data/src/nginx/src/http/modules/ngx_http_chunked_filter_module.c +242 -0
  204. data/src/nginx/src/http/modules/ngx_http_dav_module.c +1141 -0
  205. data/src/nginx/src/http/modules/ngx_http_degradation_module.c +243 -0
  206. data/src/nginx/src/http/modules/ngx_http_empty_gif_module.c +140 -0
  207. data/src/nginx/src/http/modules/ngx_http_fastcgi_module.c +2916 -0
  208. data/src/nginx/src/http/modules/ngx_http_flv_module.c +254 -0
  209. data/src/nginx/src/http/modules/ngx_http_geo_module.c +1441 -0
  210. data/src/nginx/src/http/modules/ngx_http_geoip_module.c +671 -0
  211. data/src/nginx/src/http/modules/ngx_http_gzip_filter_module.c +1206 -0
  212. data/src/nginx/src/http/modules/ngx_http_gzip_static_module.c +299 -0
  213. data/src/nginx/src/http/modules/ngx_http_headers_filter_module.c +616 -0
  214. data/src/nginx/src/http/modules/ngx_http_image_filter_module.c +1489 -0
  215. data/src/nginx/src/http/modules/ngx_http_index_module.c +516 -0
  216. data/src/nginx/src/http/modules/ngx_http_limit_req_module.c +809 -0
  217. data/src/nginx/src/http/modules/ngx_http_limit_zone_module.c +553 -0
  218. data/src/nginx/src/http/modules/ngx_http_log_module.c +1357 -0
  219. data/src/nginx/src/http/modules/ngx_http_map_module.c +575 -0
  220. data/src/nginx/src/http/modules/ngx_http_memcached_module.c +624 -0
  221. data/src/nginx/src/http/modules/ngx_http_mp4_module.c +3000 -0
  222. data/src/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +143 -0
  223. data/src/nginx/src/http/modules/ngx_http_proxy_module.c +2831 -0
  224. data/src/nginx/src/http/modules/ngx_http_random_index_module.c +317 -0
  225. data/src/nginx/src/http/modules/ngx_http_range_filter_module.c +855 -0
  226. data/src/nginx/src/http/modules/ngx_http_realip_module.c +476 -0
  227. data/src/nginx/src/http/modules/ngx_http_referer_module.c +613 -0
  228. data/src/nginx/src/http/modules/ngx_http_rewrite_module.c +1019 -0
  229. data/src/nginx/src/http/modules/ngx_http_scgi_module.c +1714 -0
  230. data/src/nginx/src/http/modules/ngx_http_secure_link_module.c +355 -0
  231. data/src/nginx/src/http/modules/ngx_http_split_clients_module.c +242 -0
  232. data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.c +2913 -0
  233. data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.h +114 -0
  234. data/src/nginx/src/http/modules/ngx_http_ssl_module.c +652 -0
  235. data/src/nginx/src/http/modules/ngx_http_ssl_module.h +52 -0
  236. data/src/nginx/src/http/modules/ngx_http_static_module.c +278 -0
  237. data/src/nginx/src/http/modules/ngx_http_stub_status_module.c +144 -0
  238. data/src/nginx/src/http/modules/ngx_http_sub_filter_module.c +716 -0
  239. data/src/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +237 -0
  240. data/src/nginx/src/http/modules/ngx_http_userid_filter_module.c +846 -0
  241. data/src/nginx/src/http/modules/ngx_http_uwsgi_module.c +1774 -0
  242. data/src/nginx/src/http/modules/ngx_http_xslt_filter_module.c +984 -0
  243. data/src/nginx/src/http/modules/perl/Makefile.PL +42 -0
  244. data/src/nginx/src/http/modules/perl/nginx.pm +137 -0
  245. data/src/nginx/src/http/modules/perl/nginx.xs +986 -0
  246. data/src/nginx/src/http/modules/perl/ngx_http_perl_module.c +1076 -0
  247. data/src/nginx/src/http/modules/perl/ngx_http_perl_module.h +67 -0
  248. data/src/nginx/src/http/modules/perl/typemap +3 -0
  249. data/src/nginx/src/http/ngx_http.c +2073 -0
  250. data/src/nginx/src/http/ngx_http.h +160 -0
  251. data/src/nginx/src/http/ngx_http_busy_lock.c +307 -0
  252. data/src/nginx/src/http/ngx_http_busy_lock.h +54 -0
  253. data/src/nginx/src/http/ngx_http_cache.h +148 -0
  254. data/src/nginx/src/http/ngx_http_config.h +75 -0
  255. data/src/nginx/src/http/ngx_http_copy_filter_module.c +300 -0
  256. data/src/nginx/src/http/ngx_http_core_module.c +4736 -0
  257. data/src/nginx/src/http/ngx_http_core_module.h +541 -0
  258. data/src/nginx/src/http/ngx_http_file_cache.c +1715 -0
  259. data/src/nginx/src/http/ngx_http_header_filter_module.c +623 -0
  260. data/src/nginx/src/http/ngx_http_parse.c +1734 -0
  261. data/src/nginx/src/http/ngx_http_parse_time.c +276 -0
  262. data/src/nginx/src/http/ngx_http_postpone_filter_module.c +178 -0
  263. data/src/nginx/src/http/ngx_http_request.c +3181 -0
  264. data/src/nginx/src/http/ngx_http_request.h +573 -0
  265. data/src/nginx/src/http/ngx_http_request_body.c +644 -0
  266. data/src/nginx/src/http/ngx_http_script.c +1752 -0
  267. data/src/nginx/src/http/ngx_http_script.h +257 -0
  268. data/src/nginx/src/http/ngx_http_special_response.c +789 -0
  269. data/src/nginx/src/http/ngx_http_upstream.c +4555 -0
  270. data/src/nginx/src/http/ngx_http_upstream.h +350 -0
  271. data/src/nginx/src/http/ngx_http_upstream_round_robin.c +791 -0
  272. data/src/nginx/src/http/ngx_http_upstream_round_robin.h +85 -0
  273. data/src/nginx/src/http/ngx_http_variables.c +2053 -0
  274. data/src/nginx/src/http/ngx_http_variables.h +115 -0
  275. data/src/nginx/src/http/ngx_http_write_filter_module.c +315 -0
  276. data/src/nginx/src/mail/ngx_mail.c +542 -0
  277. data/src/nginx/src/mail/ngx_mail.h +407 -0
  278. data/src/nginx/src/mail/ngx_mail_auth_http_module.c +1452 -0
  279. data/src/nginx/src/mail/ngx_mail_core_module.c +553 -0
  280. data/src/nginx/src/mail/ngx_mail_handler.c +773 -0
  281. data/src/nginx/src/mail/ngx_mail_imap_handler.c +457 -0
  282. data/src/nginx/src/mail/ngx_mail_imap_module.c +253 -0
  283. data/src/nginx/src/mail/ngx_mail_imap_module.h +39 -0
  284. data/src/nginx/src/mail/ngx_mail_parse.c +885 -0
  285. data/src/nginx/src/mail/ngx_mail_pop3_handler.c +500 -0
  286. data/src/nginx/src/mail/ngx_mail_pop3_module.c +264 -0
  287. data/src/nginx/src/mail/ngx_mail_pop3_module.h +38 -0
  288. data/src/nginx/src/mail/ngx_mail_proxy_module.c +1089 -0
  289. data/src/nginx/src/mail/ngx_mail_smtp_handler.c +872 -0
  290. data/src/nginx/src/mail/ngx_mail_smtp_module.c +308 -0
  291. data/src/nginx/src/mail/ngx_mail_smtp_module.h +45 -0
  292. data/src/nginx/src/mail/ngx_mail_ssl_module.c +491 -0
  293. data/src/nginx/src/mail/ngx_mail_ssl_module.h +52 -0
  294. data/src/nginx/src/misc/ngx_cpp_test_module.cpp +27 -0
  295. data/src/nginx/src/misc/ngx_google_perftools_module.c +126 -0
  296. data/src/nginx/src/os/unix/ngx_aio_read.c +109 -0
  297. data/src/nginx/src/os/unix/ngx_aio_read_chain.c +78 -0
  298. data/src/nginx/src/os/unix/ngx_aio_write.c +109 -0
  299. data/src/nginx/src/os/unix/ngx_aio_write_chain.c +100 -0
  300. data/src/nginx/src/os/unix/ngx_alloc.c +90 -0
  301. data/src/nginx/src/os/unix/ngx_alloc.h +45 -0
  302. data/src/nginx/src/os/unix/ngx_atomic.h +311 -0
  303. data/src/nginx/src/os/unix/ngx_channel.c +258 -0
  304. data/src/nginx/src/os/unix/ngx_channel.h +34 -0
  305. data/src/nginx/src/os/unix/ngx_daemon.c +69 -0
  306. data/src/nginx/src/os/unix/ngx_darwin.h +20 -0
  307. data/src/nginx/src/os/unix/ngx_darwin_config.h +96 -0
  308. data/src/nginx/src/os/unix/ngx_darwin_init.c +166 -0
  309. data/src/nginx/src/os/unix/ngx_darwin_sendfile_chain.c +366 -0
  310. data/src/nginx/src/os/unix/ngx_errno.c +87 -0
  311. data/src/nginx/src/os/unix/ngx_errno.h +68 -0
  312. data/src/nginx/src/os/unix/ngx_file_aio_read.c +208 -0
  313. data/src/nginx/src/os/unix/ngx_files.c +566 -0
  314. data/src/nginx/src/os/unix/ngx_files.h +343 -0
  315. data/src/nginx/src/os/unix/ngx_freebsd.h +24 -0
  316. data/src/nginx/src/os/unix/ngx_freebsd_config.h +119 -0
  317. data/src/nginx/src/os/unix/ngx_freebsd_init.c +259 -0
  318. data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.c +756 -0
  319. data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.h +122 -0
  320. data/src/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +436 -0
  321. data/src/nginx/src/os/unix/ngx_gcc_atomic_amd64.h +82 -0
  322. data/src/nginx/src/os/unix/ngx_gcc_atomic_ppc.h +155 -0
  323. data/src/nginx/src/os/unix/ngx_gcc_atomic_sparc64.h +82 -0
  324. data/src/nginx/src/os/unix/ngx_gcc_atomic_x86.h +127 -0
  325. data/src/nginx/src/os/unix/ngx_linux.h +18 -0
  326. data/src/nginx/src/os/unix/ngx_linux_aio_read.c +137 -0
  327. data/src/nginx/src/os/unix/ngx_linux_config.h +117 -0
  328. data/src/nginx/src/os/unix/ngx_linux_init.c +91 -0
  329. data/src/nginx/src/os/unix/ngx_linux_sendfile_chain.c +378 -0
  330. data/src/nginx/src/os/unix/ngx_os.h +84 -0
  331. data/src/nginx/src/os/unix/ngx_posix_config.h +153 -0
  332. data/src/nginx/src/os/unix/ngx_posix_init.c +124 -0
  333. data/src/nginx/src/os/unix/ngx_process.c +590 -0
  334. data/src/nginx/src/os/unix/ngx_process.h +87 -0
  335. data/src/nginx/src/os/unix/ngx_process_cycle.c +1390 -0
  336. data/src/nginx/src/os/unix/ngx_process_cycle.h +61 -0
  337. data/src/nginx/src/os/unix/ngx_pthread_thread.c +278 -0
  338. data/src/nginx/src/os/unix/ngx_readv_chain.c +258 -0
  339. data/src/nginx/src/os/unix/ngx_recv.c +180 -0
  340. data/src/nginx/src/os/unix/ngx_send.c +73 -0
  341. data/src/nginx/src/os/unix/ngx_setproctitle.c +135 -0
  342. data/src/nginx/src/os/unix/ngx_setproctitle.h +52 -0
  343. data/src/nginx/src/os/unix/ngx_shmem.c +126 -0
  344. data/src/nginx/src/os/unix/ngx_shmem.h +29 -0
  345. data/src/nginx/src/os/unix/ngx_socket.c +116 -0
  346. data/src/nginx/src/os/unix/ngx_socket.h +64 -0
  347. data/src/nginx/src/os/unix/ngx_solaris.h +16 -0
  348. data/src/nginx/src/os/unix/ngx_solaris_config.h +107 -0
  349. data/src/nginx/src/os/unix/ngx_solaris_init.c +75 -0
  350. data/src/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +251 -0
  351. data/src/nginx/src/os/unix/ngx_sunpro_amd64.il +43 -0
  352. data/src/nginx/src/os/unix/ngx_sunpro_atomic_sparc64.h +61 -0
  353. data/src/nginx/src/os/unix/ngx_sunpro_sparc64.il +36 -0
  354. data/src/nginx/src/os/unix/ngx_sunpro_x86.il +44 -0
  355. data/src/nginx/src/os/unix/ngx_thread.h +128 -0
  356. data/src/nginx/src/os/unix/ngx_time.c +104 -0
  357. data/src/nginx/src/os/unix/ngx_time.h +66 -0
  358. data/src/nginx/src/os/unix/ngx_udp_recv.c +115 -0
  359. data/src/nginx/src/os/unix/ngx_user.c +109 -0
  360. data/src/nginx/src/os/unix/ngx_user.h +24 -0
  361. data/src/nginx/src/os/unix/ngx_writev_chain.c +181 -0
  362. data/src/nginx/src/os/unix/rfork_thread.S +73 -0
  363. metadata +419 -0
@@ -0,0 +1,4736 @@
1
+
2
+ /*
3
+ * Copyright (C) Igor Sysoev
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
+ u_char *name;
15
+ uint32_t method;
16
+ } ngx_http_method_name_t;
17
+
18
+
19
+ #define NGX_HTTP_REQUEST_BODY_FILE_OFF 0
20
+ #define NGX_HTTP_REQUEST_BODY_FILE_ON 1
21
+ #define NGX_HTTP_REQUEST_BODY_FILE_CLEAN 2
22
+
23
+
24
+ static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r);
25
+ static ngx_int_t ngx_http_core_find_static_location(ngx_http_request_t *r,
26
+ ngx_http_location_tree_node_t *node);
27
+
28
+ static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf);
29
+ static void *ngx_http_core_create_main_conf(ngx_conf_t *cf);
30
+ static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
31
+ static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf);
32
+ static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
33
+ void *parent, void *child);
34
+ static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf);
35
+ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
36
+ void *parent, void *child);
37
+
38
+ static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
39
+ void *dummy);
40
+ static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
41
+ void *dummy);
42
+ static ngx_int_t ngx_http_core_regex_location(ngx_conf_t *cf,
43
+ ngx_http_core_loc_conf_t *clcf, ngx_str_t *regex, ngx_uint_t caseless);
44
+
45
+ static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
46
+ void *conf);
47
+ static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy,
48
+ void *conf);
49
+
50
+ static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
51
+ void *conf);
52
+ static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
53
+ void *conf);
54
+ static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
55
+ static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd,
56
+ void *conf);
57
+ static char *ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd,
58
+ void *conf);
59
+ static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
60
+ void *conf);
61
+ static char *ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd,
62
+ void *conf);
63
+ static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
64
+ void *conf);
65
+ static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
66
+ void *conf);
67
+ static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
68
+ void *conf);
69
+ static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
70
+ void *conf);
71
+ static char *ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
72
+ void *conf);
73
+ #if (NGX_HTTP_GZIP)
74
+ static ngx_int_t ngx_http_gzip_accept_encoding(ngx_str_t *ae);
75
+ static ngx_uint_t ngx_http_gzip_quantity(u_char *p, u_char *last);
76
+ static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd,
77
+ void *conf);
78
+ #endif
79
+
80
+ static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
81
+ static char *ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data);
82
+
83
+ static ngx_conf_post_t ngx_http_core_lowat_post =
84
+ { ngx_http_core_lowat_check };
85
+
86
+ static ngx_conf_post_handler_pt ngx_http_core_pool_size_p =
87
+ ngx_http_core_pool_size;
88
+
89
+ static ngx_conf_deprecated_t ngx_conf_deprecated_optimize_server_names = {
90
+ ngx_conf_deprecated, "optimize_server_names", "server_name_in_redirect"
91
+ };
92
+
93
+ static ngx_conf_deprecated_t ngx_conf_deprecated_open_file_cache_retest = {
94
+ ngx_conf_deprecated, "open_file_cache_retest", "open_file_cache_valid"
95
+ };
96
+
97
+ static ngx_conf_deprecated_t ngx_conf_deprecated_satisfy_any = {
98
+ ngx_conf_deprecated, "satisfy_any", "satisfy"
99
+ };
100
+
101
+
102
+ static ngx_conf_enum_t ngx_http_core_request_body_in_file[] = {
103
+ { ngx_string("off"), NGX_HTTP_REQUEST_BODY_FILE_OFF },
104
+ { ngx_string("on"), NGX_HTTP_REQUEST_BODY_FILE_ON },
105
+ { ngx_string("clean"), NGX_HTTP_REQUEST_BODY_FILE_CLEAN },
106
+ { ngx_null_string, 0 }
107
+ };
108
+
109
+
110
+ #if (NGX_HAVE_FILE_AIO)
111
+
112
+ static ngx_conf_enum_t ngx_http_core_aio[] = {
113
+ { ngx_string("off"), NGX_HTTP_AIO_OFF },
114
+ { ngx_string("on"), NGX_HTTP_AIO_ON },
115
+ #if (NGX_HAVE_AIO_SENDFILE)
116
+ { ngx_string("sendfile"), NGX_HTTP_AIO_SENDFILE },
117
+ #endif
118
+ { ngx_null_string, 0 }
119
+ };
120
+
121
+ #endif
122
+
123
+
124
+ static ngx_conf_enum_t ngx_http_core_satisfy[] = {
125
+ { ngx_string("all"), NGX_HTTP_SATISFY_ALL },
126
+ { ngx_string("any"), NGX_HTTP_SATISFY_ANY },
127
+ { ngx_null_string, 0 }
128
+ };
129
+
130
+
131
+ static ngx_conf_enum_t ngx_http_core_lingering_close[] = {
132
+ { ngx_string("off"), NGX_HTTP_LINGERING_OFF },
133
+ { ngx_string("on"), NGX_HTTP_LINGERING_ON },
134
+ { ngx_string("always"), NGX_HTTP_LINGERING_ALWAYS },
135
+ { ngx_null_string, 0 }
136
+ };
137
+
138
+
139
+ static ngx_conf_enum_t ngx_http_core_if_modified_since[] = {
140
+ { ngx_string("off"), NGX_HTTP_IMS_OFF },
141
+ { ngx_string("exact"), NGX_HTTP_IMS_EXACT },
142
+ { ngx_string("before"), NGX_HTTP_IMS_BEFORE },
143
+ { ngx_null_string, 0 }
144
+ };
145
+
146
+
147
+ static ngx_conf_bitmask_t ngx_http_core_keepalive_disable[] = {
148
+ { ngx_string("none"), NGX_HTTP_KEEPALIVE_DISABLE_NONE },
149
+ { ngx_string("msie6"), NGX_HTTP_KEEPALIVE_DISABLE_MSIE6 },
150
+ { ngx_string("safari"), NGX_HTTP_KEEPALIVE_DISABLE_SAFARI },
151
+ { ngx_null_string, 0 }
152
+ };
153
+
154
+
155
+ static ngx_path_init_t ngx_http_client_temp_path = {
156
+ ngx_string(NGX_HTTP_CLIENT_TEMP_PATH), { 0, 0, 0 }
157
+ };
158
+
159
+
160
+ #if (NGX_HTTP_GZIP)
161
+
162
+ static ngx_conf_enum_t ngx_http_gzip_http_version[] = {
163
+ { ngx_string("1.0"), NGX_HTTP_VERSION_10 },
164
+ { ngx_string("1.1"), NGX_HTTP_VERSION_11 },
165
+ { ngx_null_string, 0 }
166
+ };
167
+
168
+
169
+ static ngx_conf_bitmask_t ngx_http_gzip_proxied_mask[] = {
170
+ { ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF },
171
+ { ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED },
172
+ { ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE },
173
+ { ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE },
174
+ { ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE },
175
+ { ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM },
176
+ { ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG },
177
+ { ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH },
178
+ { ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY },
179
+ { ngx_null_string, 0 }
180
+ };
181
+
182
+
183
+ static ngx_str_t ngx_http_gzip_no_cache = ngx_string("no-cache");
184
+ static ngx_str_t ngx_http_gzip_no_store = ngx_string("no-store");
185
+ static ngx_str_t ngx_http_gzip_private = ngx_string("private");
186
+
187
+ #endif
188
+
189
+
190
+ static ngx_command_t ngx_http_core_commands[] = {
191
+
192
+ { ngx_string("variables_hash_max_size"),
193
+ NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
194
+ ngx_conf_set_num_slot,
195
+ NGX_HTTP_MAIN_CONF_OFFSET,
196
+ offsetof(ngx_http_core_main_conf_t, variables_hash_max_size),
197
+ NULL },
198
+
199
+ { ngx_string("variables_hash_bucket_size"),
200
+ NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
201
+ ngx_conf_set_num_slot,
202
+ NGX_HTTP_MAIN_CONF_OFFSET,
203
+ offsetof(ngx_http_core_main_conf_t, variables_hash_bucket_size),
204
+ NULL },
205
+
206
+ { ngx_string("server_names_hash_max_size"),
207
+ NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
208
+ ngx_conf_set_num_slot,
209
+ NGX_HTTP_MAIN_CONF_OFFSET,
210
+ offsetof(ngx_http_core_main_conf_t, server_names_hash_max_size),
211
+ NULL },
212
+
213
+ { ngx_string("server_names_hash_bucket_size"),
214
+ NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
215
+ ngx_conf_set_num_slot,
216
+ NGX_HTTP_MAIN_CONF_OFFSET,
217
+ offsetof(ngx_http_core_main_conf_t, server_names_hash_bucket_size),
218
+ NULL },
219
+
220
+ { ngx_string("server"),
221
+ NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_MULTI|NGX_CONF_NOARGS,
222
+ ngx_http_core_server,
223
+ 0,
224
+ 0,
225
+ NULL },
226
+
227
+ { ngx_string("connection_pool_size"),
228
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
229
+ ngx_conf_set_size_slot,
230
+ NGX_HTTP_SRV_CONF_OFFSET,
231
+ offsetof(ngx_http_core_srv_conf_t, connection_pool_size),
232
+ &ngx_http_core_pool_size_p },
233
+
234
+ { ngx_string("request_pool_size"),
235
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
236
+ ngx_conf_set_size_slot,
237
+ NGX_HTTP_SRV_CONF_OFFSET,
238
+ offsetof(ngx_http_core_srv_conf_t, request_pool_size),
239
+ &ngx_http_core_pool_size_p },
240
+
241
+ { ngx_string("client_header_timeout"),
242
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
243
+ ngx_conf_set_msec_slot,
244
+ NGX_HTTP_SRV_CONF_OFFSET,
245
+ offsetof(ngx_http_core_srv_conf_t, client_header_timeout),
246
+ NULL },
247
+
248
+ { ngx_string("client_header_buffer_size"),
249
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
250
+ ngx_conf_set_size_slot,
251
+ NGX_HTTP_SRV_CONF_OFFSET,
252
+ offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size),
253
+ NULL },
254
+
255
+ { ngx_string("large_client_header_buffers"),
256
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE2,
257
+ ngx_conf_set_bufs_slot,
258
+ NGX_HTTP_SRV_CONF_OFFSET,
259
+ offsetof(ngx_http_core_srv_conf_t, large_client_header_buffers),
260
+ NULL },
261
+
262
+ { ngx_string("optimize_server_names"),
263
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
264
+ ngx_conf_set_flag_slot,
265
+ NGX_HTTP_LOC_CONF_OFFSET,
266
+ offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
267
+ &ngx_conf_deprecated_optimize_server_names },
268
+
269
+ { ngx_string("ignore_invalid_headers"),
270
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
271
+ ngx_conf_set_flag_slot,
272
+ NGX_HTTP_SRV_CONF_OFFSET,
273
+ offsetof(ngx_http_core_srv_conf_t, ignore_invalid_headers),
274
+ NULL },
275
+
276
+ { ngx_string("merge_slashes"),
277
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
278
+ ngx_conf_set_flag_slot,
279
+ NGX_HTTP_SRV_CONF_OFFSET,
280
+ offsetof(ngx_http_core_srv_conf_t, merge_slashes),
281
+ NULL },
282
+
283
+ { ngx_string("underscores_in_headers"),
284
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
285
+ ngx_conf_set_flag_slot,
286
+ NGX_HTTP_SRV_CONF_OFFSET,
287
+ offsetof(ngx_http_core_srv_conf_t, underscores_in_headers),
288
+ NULL },
289
+
290
+ { ngx_string("location"),
291
+ NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
292
+ ngx_http_core_location,
293
+ NGX_HTTP_SRV_CONF_OFFSET,
294
+ 0,
295
+ NULL },
296
+
297
+ { ngx_string("listen"),
298
+ NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
299
+ ngx_http_core_listen,
300
+ NGX_HTTP_SRV_CONF_OFFSET,
301
+ 0,
302
+ NULL },
303
+
304
+ { ngx_string("server_name"),
305
+ NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
306
+ ngx_http_core_server_name,
307
+ NGX_HTTP_SRV_CONF_OFFSET,
308
+ 0,
309
+ NULL },
310
+
311
+ { ngx_string("types_hash_max_size"),
312
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
313
+ ngx_conf_set_num_slot,
314
+ NGX_HTTP_LOC_CONF_OFFSET,
315
+ offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
316
+ NULL },
317
+
318
+ { ngx_string("types_hash_bucket_size"),
319
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
320
+ ngx_conf_set_num_slot,
321
+ NGX_HTTP_LOC_CONF_OFFSET,
322
+ offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
323
+ NULL },
324
+
325
+ { ngx_string("types"),
326
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
327
+ |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
328
+ ngx_http_core_types,
329
+ NGX_HTTP_LOC_CONF_OFFSET,
330
+ 0,
331
+ NULL },
332
+
333
+ { ngx_string("default_type"),
334
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
335
+ ngx_conf_set_str_slot,
336
+ NGX_HTTP_LOC_CONF_OFFSET,
337
+ offsetof(ngx_http_core_loc_conf_t, default_type),
338
+ NULL },
339
+
340
+ { ngx_string("root"),
341
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
342
+ |NGX_CONF_TAKE1,
343
+ ngx_http_core_root,
344
+ NGX_HTTP_LOC_CONF_OFFSET,
345
+ 0,
346
+ NULL },
347
+
348
+ { ngx_string("alias"),
349
+ NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
350
+ ngx_http_core_root,
351
+ NGX_HTTP_LOC_CONF_OFFSET,
352
+ 0,
353
+ NULL },
354
+
355
+ { ngx_string("limit_except"),
356
+ NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_1MORE,
357
+ ngx_http_core_limit_except,
358
+ NGX_HTTP_LOC_CONF_OFFSET,
359
+ 0,
360
+ NULL },
361
+
362
+ { ngx_string("client_max_body_size"),
363
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
364
+ ngx_conf_set_off_slot,
365
+ NGX_HTTP_LOC_CONF_OFFSET,
366
+ offsetof(ngx_http_core_loc_conf_t, client_max_body_size),
367
+ NULL },
368
+
369
+ { ngx_string("client_body_buffer_size"),
370
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
371
+ ngx_conf_set_size_slot,
372
+ NGX_HTTP_LOC_CONF_OFFSET,
373
+ offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size),
374
+ NULL },
375
+
376
+ { ngx_string("client_body_timeout"),
377
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
378
+ ngx_conf_set_msec_slot,
379
+ NGX_HTTP_LOC_CONF_OFFSET,
380
+ offsetof(ngx_http_core_loc_conf_t, client_body_timeout),
381
+ NULL },
382
+
383
+ { ngx_string("client_body_temp_path"),
384
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
385
+ ngx_conf_set_path_slot,
386
+ NGX_HTTP_LOC_CONF_OFFSET,
387
+ offsetof(ngx_http_core_loc_conf_t, client_body_temp_path),
388
+ NULL },
389
+
390
+ { ngx_string("client_body_in_file_only"),
391
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
392
+ ngx_conf_set_enum_slot,
393
+ NGX_HTTP_LOC_CONF_OFFSET,
394
+ offsetof(ngx_http_core_loc_conf_t, client_body_in_file_only),
395
+ &ngx_http_core_request_body_in_file },
396
+
397
+ { ngx_string("client_body_in_single_buffer"),
398
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
399
+ ngx_conf_set_flag_slot,
400
+ NGX_HTTP_LOC_CONF_OFFSET,
401
+ offsetof(ngx_http_core_loc_conf_t, client_body_in_single_buffer),
402
+ NULL },
403
+
404
+ { ngx_string("sendfile"),
405
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
406
+ |NGX_CONF_FLAG,
407
+ ngx_conf_set_flag_slot,
408
+ NGX_HTTP_LOC_CONF_OFFSET,
409
+ offsetof(ngx_http_core_loc_conf_t, sendfile),
410
+ NULL },
411
+
412
+ { ngx_string("sendfile_max_chunk"),
413
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
414
+ ngx_conf_set_size_slot,
415
+ NGX_HTTP_LOC_CONF_OFFSET,
416
+ offsetof(ngx_http_core_loc_conf_t, sendfile_max_chunk),
417
+ NULL },
418
+
419
+ #if (NGX_HAVE_FILE_AIO)
420
+
421
+ { ngx_string("aio"),
422
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
423
+ ngx_conf_set_enum_slot,
424
+ NGX_HTTP_LOC_CONF_OFFSET,
425
+ offsetof(ngx_http_core_loc_conf_t, aio),
426
+ &ngx_http_core_aio },
427
+
428
+ #endif
429
+
430
+ { ngx_string("read_ahead"),
431
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
432
+ ngx_conf_set_size_slot,
433
+ NGX_HTTP_LOC_CONF_OFFSET,
434
+ offsetof(ngx_http_core_loc_conf_t, read_ahead),
435
+ NULL },
436
+
437
+ { ngx_string("directio"),
438
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
439
+ ngx_http_core_directio,
440
+ NGX_HTTP_LOC_CONF_OFFSET,
441
+ 0,
442
+ NULL },
443
+
444
+ { ngx_string("directio_alignment"),
445
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
446
+ ngx_conf_set_off_slot,
447
+ NGX_HTTP_LOC_CONF_OFFSET,
448
+ offsetof(ngx_http_core_loc_conf_t, directio_alignment),
449
+ NULL },
450
+
451
+ { ngx_string("tcp_nopush"),
452
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
453
+ ngx_conf_set_flag_slot,
454
+ NGX_HTTP_LOC_CONF_OFFSET,
455
+ offsetof(ngx_http_core_loc_conf_t, tcp_nopush),
456
+ NULL },
457
+
458
+ { ngx_string("tcp_nodelay"),
459
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
460
+ ngx_conf_set_flag_slot,
461
+ NGX_HTTP_LOC_CONF_OFFSET,
462
+ offsetof(ngx_http_core_loc_conf_t, tcp_nodelay),
463
+ NULL },
464
+
465
+ { ngx_string("send_timeout"),
466
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
467
+ ngx_conf_set_msec_slot,
468
+ NGX_HTTP_LOC_CONF_OFFSET,
469
+ offsetof(ngx_http_core_loc_conf_t, send_timeout),
470
+ NULL },
471
+
472
+ { ngx_string("send_lowat"),
473
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
474
+ ngx_conf_set_size_slot,
475
+ NGX_HTTP_LOC_CONF_OFFSET,
476
+ offsetof(ngx_http_core_loc_conf_t, send_lowat),
477
+ &ngx_http_core_lowat_post },
478
+
479
+ { ngx_string("postpone_output"),
480
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
481
+ ngx_conf_set_size_slot,
482
+ NGX_HTTP_LOC_CONF_OFFSET,
483
+ offsetof(ngx_http_core_loc_conf_t, postpone_output),
484
+ NULL },
485
+
486
+ { ngx_string("limit_rate"),
487
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
488
+ |NGX_CONF_TAKE1,
489
+ ngx_conf_set_size_slot,
490
+ NGX_HTTP_LOC_CONF_OFFSET,
491
+ offsetof(ngx_http_core_loc_conf_t, limit_rate),
492
+ NULL },
493
+
494
+ { ngx_string("limit_rate_after"),
495
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
496
+ |NGX_CONF_TAKE1,
497
+ ngx_conf_set_size_slot,
498
+ NGX_HTTP_LOC_CONF_OFFSET,
499
+ offsetof(ngx_http_core_loc_conf_t, limit_rate_after),
500
+ NULL },
501
+
502
+ { ngx_string("keepalive_timeout"),
503
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
504
+ ngx_http_core_keepalive,
505
+ NGX_HTTP_LOC_CONF_OFFSET,
506
+ 0,
507
+ NULL },
508
+
509
+ { ngx_string("keepalive_requests"),
510
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
511
+ ngx_conf_set_num_slot,
512
+ NGX_HTTP_LOC_CONF_OFFSET,
513
+ offsetof(ngx_http_core_loc_conf_t, keepalive_requests),
514
+ NULL },
515
+
516
+ { ngx_string("keepalive_disable"),
517
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
518
+ ngx_conf_set_bitmask_slot,
519
+ NGX_HTTP_LOC_CONF_OFFSET,
520
+ offsetof(ngx_http_core_loc_conf_t, keepalive_disable),
521
+ &ngx_http_core_keepalive_disable },
522
+
523
+ { ngx_string("satisfy"),
524
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
525
+ ngx_conf_set_enum_slot,
526
+ NGX_HTTP_LOC_CONF_OFFSET,
527
+ offsetof(ngx_http_core_loc_conf_t, satisfy),
528
+ &ngx_http_core_satisfy },
529
+
530
+ { ngx_string("satisfy_any"),
531
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
532
+ ngx_conf_set_flag_slot,
533
+ NGX_HTTP_LOC_CONF_OFFSET,
534
+ offsetof(ngx_http_core_loc_conf_t, satisfy),
535
+ &ngx_conf_deprecated_satisfy_any },
536
+
537
+ { ngx_string("internal"),
538
+ NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
539
+ ngx_http_core_internal,
540
+ NGX_HTTP_LOC_CONF_OFFSET,
541
+ 0,
542
+ NULL },
543
+
544
+ { ngx_string("lingering_close"),
545
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
546
+ ngx_conf_set_enum_slot,
547
+ NGX_HTTP_LOC_CONF_OFFSET,
548
+ offsetof(ngx_http_core_loc_conf_t, lingering_close),
549
+ &ngx_http_core_lingering_close },
550
+
551
+ { ngx_string("lingering_time"),
552
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
553
+ ngx_conf_set_msec_slot,
554
+ NGX_HTTP_LOC_CONF_OFFSET,
555
+ offsetof(ngx_http_core_loc_conf_t, lingering_time),
556
+ NULL },
557
+
558
+ { ngx_string("lingering_timeout"),
559
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
560
+ ngx_conf_set_msec_slot,
561
+ NGX_HTTP_LOC_CONF_OFFSET,
562
+ offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
563
+ NULL },
564
+
565
+ { ngx_string("reset_timedout_connection"),
566
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
567
+ ngx_conf_set_flag_slot,
568
+ NGX_HTTP_LOC_CONF_OFFSET,
569
+ offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
570
+ NULL },
571
+
572
+ { ngx_string("server_name_in_redirect"),
573
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
574
+ ngx_conf_set_flag_slot,
575
+ NGX_HTTP_LOC_CONF_OFFSET,
576
+ offsetof(ngx_http_core_loc_conf_t, server_name_in_redirect),
577
+ NULL },
578
+
579
+ { ngx_string("port_in_redirect"),
580
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
581
+ ngx_conf_set_flag_slot,
582
+ NGX_HTTP_LOC_CONF_OFFSET,
583
+ offsetof(ngx_http_core_loc_conf_t, port_in_redirect),
584
+ NULL },
585
+
586
+ { ngx_string("msie_padding"),
587
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
588
+ ngx_conf_set_flag_slot,
589
+ NGX_HTTP_LOC_CONF_OFFSET,
590
+ offsetof(ngx_http_core_loc_conf_t, msie_padding),
591
+ NULL },
592
+
593
+ { ngx_string("msie_refresh"),
594
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
595
+ ngx_conf_set_flag_slot,
596
+ NGX_HTTP_LOC_CONF_OFFSET,
597
+ offsetof(ngx_http_core_loc_conf_t, msie_refresh),
598
+ NULL },
599
+
600
+ { ngx_string("log_not_found"),
601
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
602
+ ngx_conf_set_flag_slot,
603
+ NGX_HTTP_LOC_CONF_OFFSET,
604
+ offsetof(ngx_http_core_loc_conf_t, log_not_found),
605
+ NULL },
606
+
607
+ { ngx_string("log_subrequest"),
608
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
609
+ ngx_conf_set_flag_slot,
610
+ NGX_HTTP_LOC_CONF_OFFSET,
611
+ offsetof(ngx_http_core_loc_conf_t, log_subrequest),
612
+ NULL },
613
+
614
+ { ngx_string("recursive_error_pages"),
615
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
616
+ ngx_conf_set_flag_slot,
617
+ NGX_HTTP_LOC_CONF_OFFSET,
618
+ offsetof(ngx_http_core_loc_conf_t, recursive_error_pages),
619
+ NULL },
620
+
621
+ { ngx_string("server_tokens"),
622
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
623
+ ngx_conf_set_flag_slot,
624
+ NGX_HTTP_LOC_CONF_OFFSET,
625
+ offsetof(ngx_http_core_loc_conf_t, server_tokens),
626
+ NULL },
627
+
628
+ { ngx_string("if_modified_since"),
629
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
630
+ ngx_conf_set_enum_slot,
631
+ NGX_HTTP_LOC_CONF_OFFSET,
632
+ offsetof(ngx_http_core_loc_conf_t, if_modified_since),
633
+ &ngx_http_core_if_modified_since },
634
+
635
+ { ngx_string("max_ranges"),
636
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
637
+ ngx_conf_set_num_slot,
638
+ NGX_HTTP_LOC_CONF_OFFSET,
639
+ offsetof(ngx_http_core_loc_conf_t, max_ranges),
640
+ NULL },
641
+
642
+ { ngx_string("chunked_transfer_encoding"),
643
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
644
+ ngx_conf_set_flag_slot,
645
+ NGX_HTTP_LOC_CONF_OFFSET,
646
+ offsetof(ngx_http_core_loc_conf_t, chunked_transfer_encoding),
647
+ NULL },
648
+
649
+ { ngx_string("error_page"),
650
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
651
+ |NGX_CONF_2MORE,
652
+ ngx_http_core_error_page,
653
+ NGX_HTTP_LOC_CONF_OFFSET,
654
+ 0,
655
+ NULL },
656
+
657
+ { ngx_string("try_files"),
658
+ NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE,
659
+ ngx_http_core_try_files,
660
+ NGX_HTTP_LOC_CONF_OFFSET,
661
+ 0,
662
+ NULL },
663
+
664
+ { ngx_string("post_action"),
665
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
666
+ |NGX_CONF_TAKE1,
667
+ ngx_conf_set_str_slot,
668
+ NGX_HTTP_LOC_CONF_OFFSET,
669
+ offsetof(ngx_http_core_loc_conf_t, post_action),
670
+ NULL },
671
+
672
+ { ngx_string("error_log"),
673
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
674
+ ngx_http_core_error_log,
675
+ NGX_HTTP_LOC_CONF_OFFSET,
676
+ 0,
677
+ NULL },
678
+
679
+ { ngx_string("open_file_cache"),
680
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
681
+ ngx_http_core_open_file_cache,
682
+ NGX_HTTP_LOC_CONF_OFFSET,
683
+ offsetof(ngx_http_core_loc_conf_t, open_file_cache),
684
+ NULL },
685
+
686
+ { ngx_string("open_file_cache_valid"),
687
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
688
+ ngx_conf_set_sec_slot,
689
+ NGX_HTTP_LOC_CONF_OFFSET,
690
+ offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
691
+ NULL },
692
+
693
+ { ngx_string("open_file_cache_retest"),
694
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
695
+ ngx_conf_set_sec_slot,
696
+ NGX_HTTP_LOC_CONF_OFFSET,
697
+ offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),
698
+ &ngx_conf_deprecated_open_file_cache_retest },
699
+
700
+ { ngx_string("open_file_cache_min_uses"),
701
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
702
+ ngx_conf_set_num_slot,
703
+ NGX_HTTP_LOC_CONF_OFFSET,
704
+ offsetof(ngx_http_core_loc_conf_t, open_file_cache_min_uses),
705
+ NULL },
706
+
707
+ { ngx_string("open_file_cache_errors"),
708
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
709
+ ngx_conf_set_flag_slot,
710
+ NGX_HTTP_LOC_CONF_OFFSET,
711
+ offsetof(ngx_http_core_loc_conf_t, open_file_cache_errors),
712
+ NULL },
713
+
714
+ { ngx_string("open_file_cache_events"),
715
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
716
+ ngx_conf_set_flag_slot,
717
+ NGX_HTTP_LOC_CONF_OFFSET,
718
+ offsetof(ngx_http_core_loc_conf_t, open_file_cache_events),
719
+ NULL },
720
+
721
+ { ngx_string("resolver"),
722
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
723
+ ngx_http_core_resolver,
724
+ NGX_HTTP_LOC_CONF_OFFSET,
725
+ 0,
726
+ NULL },
727
+
728
+ { ngx_string("resolver_timeout"),
729
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
730
+ ngx_conf_set_msec_slot,
731
+ NGX_HTTP_LOC_CONF_OFFSET,
732
+ offsetof(ngx_http_core_loc_conf_t, resolver_timeout),
733
+ NULL },
734
+
735
+ #if (NGX_HTTP_GZIP)
736
+
737
+ { ngx_string("gzip_vary"),
738
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
739
+ ngx_conf_set_flag_slot,
740
+ NGX_HTTP_LOC_CONF_OFFSET,
741
+ offsetof(ngx_http_core_loc_conf_t, gzip_vary),
742
+ NULL },
743
+
744
+ { ngx_string("gzip_http_version"),
745
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
746
+ ngx_conf_set_enum_slot,
747
+ NGX_HTTP_LOC_CONF_OFFSET,
748
+ offsetof(ngx_http_core_loc_conf_t, gzip_http_version),
749
+ &ngx_http_gzip_http_version },
750
+
751
+ { ngx_string("gzip_proxied"),
752
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
753
+ ngx_conf_set_bitmask_slot,
754
+ NGX_HTTP_LOC_CONF_OFFSET,
755
+ offsetof(ngx_http_core_loc_conf_t, gzip_proxied),
756
+ &ngx_http_gzip_proxied_mask },
757
+
758
+ { ngx_string("gzip_disable"),
759
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
760
+ ngx_http_gzip_disable,
761
+ NGX_HTTP_LOC_CONF_OFFSET,
762
+ 0,
763
+ NULL },
764
+
765
+ #endif
766
+
767
+ ngx_null_command
768
+ };
769
+
770
+
771
+ static ngx_http_module_t ngx_http_core_module_ctx = {
772
+ ngx_http_core_preconfiguration, /* preconfiguration */
773
+ NULL, /* postconfiguration */
774
+
775
+ ngx_http_core_create_main_conf, /* create main configuration */
776
+ ngx_http_core_init_main_conf, /* init main configuration */
777
+
778
+ ngx_http_core_create_srv_conf, /* create server configuration */
779
+ ngx_http_core_merge_srv_conf, /* merge server configuration */
780
+
781
+ ngx_http_core_create_loc_conf, /* create location configuration */
782
+ ngx_http_core_merge_loc_conf /* merge location configuration */
783
+ };
784
+
785
+
786
+ ngx_module_t ngx_http_core_module = {
787
+ NGX_MODULE_V1,
788
+ &ngx_http_core_module_ctx, /* module context */
789
+ ngx_http_core_commands, /* module directives */
790
+ NGX_HTTP_MODULE, /* module type */
791
+ NULL, /* init master */
792
+ NULL, /* init module */
793
+ NULL, /* init process */
794
+ NULL, /* init thread */
795
+ NULL, /* exit thread */
796
+ NULL, /* exit process */
797
+ NULL, /* exit master */
798
+ NGX_MODULE_V1_PADDING
799
+ };
800
+
801
+
802
+ ngx_str_t ngx_http_core_get_method = { 3, (u_char *) "GET " };
803
+
804
+
805
+ void
806
+ ngx_http_handler(ngx_http_request_t *r)
807
+ {
808
+ ngx_http_core_main_conf_t *cmcf;
809
+
810
+ r->connection->log->action = NULL;
811
+
812
+ r->connection->unexpected_eof = 0;
813
+
814
+ if (!r->internal) {
815
+ switch (r->headers_in.connection_type) {
816
+ case 0:
817
+ r->keepalive = (r->http_version > NGX_HTTP_VERSION_10);
818
+ break;
819
+
820
+ case NGX_HTTP_CONNECTION_CLOSE:
821
+ r->keepalive = 0;
822
+ break;
823
+
824
+ case NGX_HTTP_CONNECTION_KEEP_ALIVE:
825
+ r->keepalive = 1;
826
+ break;
827
+ }
828
+
829
+ r->lingering_close = (r->headers_in.content_length_n > 0);
830
+ r->phase_handler = 0;
831
+
832
+ } else {
833
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
834
+ r->phase_handler = cmcf->phase_engine.server_rewrite_index;
835
+ }
836
+
837
+ r->valid_location = 1;
838
+ #if (NGX_HTTP_GZIP)
839
+ r->gzip_tested = 0;
840
+ r->gzip_ok = 0;
841
+ r->gzip_vary = 0;
842
+ #endif
843
+
844
+ r->write_event_handler = ngx_http_core_run_phases;
845
+ ngx_http_core_run_phases(r);
846
+ }
847
+
848
+
849
+ void
850
+ ngx_http_core_run_phases(ngx_http_request_t *r)
851
+ {
852
+ ngx_int_t rc;
853
+ ngx_http_phase_handler_t *ph;
854
+ ngx_http_core_main_conf_t *cmcf;
855
+
856
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
857
+
858
+ ph = cmcf->phase_engine.handlers;
859
+
860
+ while (ph[r->phase_handler].checker) {
861
+
862
+ rc = ph[r->phase_handler].checker(r, &ph[r->phase_handler]);
863
+
864
+ if (rc == NGX_OK) {
865
+ return;
866
+ }
867
+ }
868
+ }
869
+
870
+
871
+ ngx_int_t
872
+ ngx_http_core_generic_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
873
+ {
874
+ ngx_int_t rc;
875
+
876
+ /*
877
+ * generic phase checker,
878
+ * used by the post read and pre-access phases
879
+ */
880
+
881
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
882
+ "generic phase: %ui", r->phase_handler);
883
+
884
+ rc = ph->handler(r);
885
+
886
+ if (rc == NGX_OK) {
887
+ r->phase_handler = ph->next;
888
+ return NGX_AGAIN;
889
+ }
890
+
891
+ if (rc == NGX_DECLINED) {
892
+ r->phase_handler++;
893
+ return NGX_AGAIN;
894
+ }
895
+
896
+ if (rc == NGX_AGAIN || rc == NGX_DONE) {
897
+ return NGX_OK;
898
+ }
899
+
900
+ /* rc == NGX_ERROR || rc == NGX_HTTP_... */
901
+
902
+ ngx_http_finalize_request(r, rc);
903
+
904
+ return NGX_OK;
905
+ }
906
+
907
+
908
+ ngx_int_t
909
+ ngx_http_core_rewrite_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
910
+ {
911
+ ngx_int_t rc;
912
+
913
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
914
+ "rewrite phase: %ui", r->phase_handler);
915
+
916
+ rc = ph->handler(r);
917
+
918
+ if (rc == NGX_DECLINED) {
919
+ r->phase_handler++;
920
+ return NGX_AGAIN;
921
+ }
922
+
923
+ if (rc == NGX_DONE) {
924
+ return NGX_OK;
925
+ }
926
+
927
+ /* NGX_OK, NGX_AGAIN, NGX_ERROR, NGX_HTTP_... */
928
+
929
+ ngx_http_finalize_request(r, rc);
930
+
931
+ return NGX_OK;
932
+ }
933
+
934
+
935
+ ngx_int_t
936
+ ngx_http_core_find_config_phase(ngx_http_request_t *r,
937
+ ngx_http_phase_handler_t *ph)
938
+ {
939
+ u_char *p;
940
+ size_t len;
941
+ ngx_int_t rc;
942
+ ngx_http_core_loc_conf_t *clcf;
943
+
944
+ r->content_handler = NULL;
945
+ r->uri_changed = 0;
946
+
947
+ rc = ngx_http_core_find_location(r);
948
+
949
+ if (rc == NGX_ERROR) {
950
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
951
+ return NGX_OK;
952
+ }
953
+
954
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
955
+
956
+ if (!r->internal && clcf->internal) {
957
+ ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
958
+ return NGX_OK;
959
+ }
960
+
961
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
962
+ "using configuration \"%s%V\"",
963
+ (clcf->noname ? "*" : (clcf->exact_match ? "=" : "")),
964
+ &clcf->name);
965
+
966
+ ngx_http_update_location_config(r);
967
+
968
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
969
+ "http cl:%O max:%O",
970
+ r->headers_in.content_length_n, clcf->client_max_body_size);
971
+
972
+ if (r->headers_in.content_length_n != -1
973
+ && !r->discard_body
974
+ && clcf->client_max_body_size
975
+ && clcf->client_max_body_size < r->headers_in.content_length_n)
976
+ {
977
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
978
+ "client intended to send too large body: %O bytes",
979
+ r->headers_in.content_length_n);
980
+
981
+ (void) ngx_http_discard_request_body(r);
982
+ ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE);
983
+ return NGX_OK;
984
+ }
985
+
986
+ if (rc == NGX_DONE) {
987
+ ngx_http_clear_location(r);
988
+
989
+ r->headers_out.location = ngx_list_push(&r->headers_out.headers);
990
+ if (r->headers_out.location == NULL) {
991
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
992
+ return NGX_OK;
993
+ }
994
+
995
+ /*
996
+ * we do not need to set the r->headers_out.location->hash and
997
+ * r->headers_out.location->key fields
998
+ */
999
+
1000
+ if (r->args.len == 0) {
1001
+ r->headers_out.location->value = clcf->name;
1002
+
1003
+ } else {
1004
+ len = clcf->name.len + 1 + r->args.len;
1005
+ p = ngx_pnalloc(r->pool, len);
1006
+
1007
+ if (p == NULL) {
1008
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1009
+ return NGX_OK;
1010
+ }
1011
+
1012
+ r->headers_out.location->value.len = len;
1013
+ r->headers_out.location->value.data = p;
1014
+
1015
+ p = ngx_cpymem(p, clcf->name.data, clcf->name.len);
1016
+ *p++ = '?';
1017
+ ngx_memcpy(p, r->args.data, r->args.len);
1018
+ }
1019
+
1020
+ ngx_http_finalize_request(r, NGX_HTTP_MOVED_PERMANENTLY);
1021
+ return NGX_OK;
1022
+ }
1023
+
1024
+ r->phase_handler++;
1025
+ return NGX_AGAIN;
1026
+ }
1027
+
1028
+
1029
+ ngx_int_t
1030
+ ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
1031
+ ngx_http_phase_handler_t *ph)
1032
+ {
1033
+ ngx_http_core_srv_conf_t *cscf;
1034
+
1035
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1036
+ "post rewrite phase: %ui", r->phase_handler);
1037
+
1038
+ if (!r->uri_changed) {
1039
+ r->phase_handler++;
1040
+ return NGX_AGAIN;
1041
+ }
1042
+
1043
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1044
+ "uri changes: %d", r->uri_changes);
1045
+
1046
+ /*
1047
+ * gcc before 3.3 compiles the broken code for
1048
+ * if (r->uri_changes-- == 0)
1049
+ * if the r->uri_changes is defined as
1050
+ * unsigned uri_changes:4
1051
+ */
1052
+
1053
+ r->uri_changes--;
1054
+
1055
+ if (r->uri_changes == 0) {
1056
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1057
+ "rewrite or internal redirection cycle "
1058
+ "while processing \"%V\"", &r->uri);
1059
+
1060
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1061
+ return NGX_OK;
1062
+ }
1063
+
1064
+ r->phase_handler = ph->next;
1065
+
1066
+ cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1067
+ r->loc_conf = cscf->ctx->loc_conf;
1068
+
1069
+ return NGX_AGAIN;
1070
+ }
1071
+
1072
+
1073
+ ngx_int_t
1074
+ ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
1075
+ {
1076
+ ngx_int_t rc;
1077
+ ngx_http_core_loc_conf_t *clcf;
1078
+
1079
+ if (r != r->main) {
1080
+ r->phase_handler = ph->next;
1081
+ return NGX_AGAIN;
1082
+ }
1083
+
1084
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1085
+ "access phase: %ui", r->phase_handler);
1086
+
1087
+ rc = ph->handler(r);
1088
+
1089
+ if (rc == NGX_DECLINED) {
1090
+ r->phase_handler++;
1091
+ return NGX_AGAIN;
1092
+ }
1093
+
1094
+ if (rc == NGX_AGAIN || rc == NGX_DONE) {
1095
+ return NGX_OK;
1096
+ }
1097
+
1098
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1099
+
1100
+ if (clcf->satisfy == NGX_HTTP_SATISFY_ALL) {
1101
+
1102
+ if (rc == NGX_OK) {
1103
+ r->phase_handler++;
1104
+ return NGX_AGAIN;
1105
+ }
1106
+
1107
+ } else {
1108
+ if (rc == NGX_OK) {
1109
+ r->access_code = 0;
1110
+
1111
+ if (r->headers_out.www_authenticate) {
1112
+ r->headers_out.www_authenticate->hash = 0;
1113
+ }
1114
+
1115
+ r->phase_handler = ph->next;
1116
+ return NGX_AGAIN;
1117
+ }
1118
+
1119
+ if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED) {
1120
+ r->access_code = rc;
1121
+
1122
+ r->phase_handler++;
1123
+ return NGX_AGAIN;
1124
+ }
1125
+ }
1126
+
1127
+ /* rc == NGX_ERROR || rc == NGX_HTTP_... */
1128
+
1129
+ ngx_http_finalize_request(r, rc);
1130
+ return NGX_OK;
1131
+ }
1132
+
1133
+
1134
+ ngx_int_t
1135
+ ngx_http_core_post_access_phase(ngx_http_request_t *r,
1136
+ ngx_http_phase_handler_t *ph)
1137
+ {
1138
+ ngx_int_t access_code;
1139
+
1140
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1141
+ "post access phase: %ui", r->phase_handler);
1142
+
1143
+ access_code = r->access_code;
1144
+
1145
+ if (access_code) {
1146
+ if (access_code == NGX_HTTP_FORBIDDEN) {
1147
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1148
+ "access forbidden by rule");
1149
+ }
1150
+
1151
+ r->access_code = 0;
1152
+ ngx_http_finalize_request(r, access_code);
1153
+ return NGX_OK;
1154
+ }
1155
+
1156
+ r->phase_handler++;
1157
+ return NGX_AGAIN;
1158
+ }
1159
+
1160
+
1161
+ ngx_int_t
1162
+ ngx_http_core_try_files_phase(ngx_http_request_t *r,
1163
+ ngx_http_phase_handler_t *ph)
1164
+ {
1165
+ size_t len, root, alias, reserve, allocated;
1166
+ u_char *p, *name;
1167
+ ngx_str_t path, args;
1168
+ ngx_uint_t test_dir;
1169
+ ngx_http_try_file_t *tf;
1170
+ ngx_open_file_info_t of;
1171
+ ngx_http_script_code_pt code;
1172
+ ngx_http_script_engine_t e;
1173
+ ngx_http_core_loc_conf_t *clcf;
1174
+ ngx_http_script_len_code_pt lcode;
1175
+
1176
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1177
+ "try files phase: %ui", r->phase_handler);
1178
+
1179
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1180
+
1181
+ if (clcf->try_files == NULL) {
1182
+ r->phase_handler++;
1183
+ return NGX_AGAIN;
1184
+ }
1185
+
1186
+ allocated = 0;
1187
+ root = 0;
1188
+ name = NULL;
1189
+ /* suppress MSVC warning */
1190
+ path.data = NULL;
1191
+
1192
+ tf = clcf->try_files;
1193
+
1194
+ alias = clcf->alias;
1195
+
1196
+ for ( ;; ) {
1197
+
1198
+ if (tf->lengths) {
1199
+ ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
1200
+
1201
+ e.ip = tf->lengths->elts;
1202
+ e.request = r;
1203
+
1204
+ /* 1 is for terminating '\0' as in static names */
1205
+ len = 1;
1206
+
1207
+ while (*(uintptr_t *) e.ip) {
1208
+ lcode = *(ngx_http_script_len_code_pt *) e.ip;
1209
+ len += lcode(&e);
1210
+ }
1211
+
1212
+ } else {
1213
+ len = tf->name.len;
1214
+ }
1215
+
1216
+ /* 16 bytes are preallocation */
1217
+ reserve = ngx_abs((ssize_t) (len - r->uri.len)) + alias + 16;
1218
+
1219
+ if (reserve > allocated) {
1220
+
1221
+ /* we just need to allocate path and to copy a root */
1222
+
1223
+ if (ngx_http_map_uri_to_path(r, &path, &root, reserve) == NULL) {
1224
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1225
+ return NGX_OK;
1226
+ }
1227
+
1228
+ name = path.data + root;
1229
+ allocated = path.len - root - (r->uri.len - alias);
1230
+ }
1231
+
1232
+ if (tf->values == NULL) {
1233
+
1234
+ /* tf->name.len includes the terminating '\0' */
1235
+
1236
+ ngx_memcpy(name, tf->name.data, tf->name.len);
1237
+
1238
+ path.len = (name + tf->name.len - 1) - path.data;
1239
+
1240
+ } else {
1241
+ e.ip = tf->values->elts;
1242
+ e.pos = name;
1243
+ e.flushed = 1;
1244
+
1245
+ while (*(uintptr_t *) e.ip) {
1246
+ code = *(ngx_http_script_code_pt *) e.ip;
1247
+ code((ngx_http_script_engine_t *) &e);
1248
+ }
1249
+
1250
+ path.len = e.pos - path.data;
1251
+
1252
+ *e.pos = '\0';
1253
+
1254
+ if (alias && ngx_strncmp(name, clcf->name.data, alias) == 0) {
1255
+ ngx_memmove(name, name + alias, len - alias);
1256
+ path.len -= alias;
1257
+ }
1258
+ }
1259
+
1260
+ test_dir = tf->test_dir;
1261
+
1262
+ tf++;
1263
+
1264
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1265
+ "trying to use %s: \"%s\" \"%s\"",
1266
+ test_dir ? "dir" : "file", name, path.data);
1267
+
1268
+ if (tf->lengths == NULL && tf->name.len == 0) {
1269
+
1270
+ if (tf->code) {
1271
+ ngx_http_finalize_request(r, tf->code);
1272
+ return NGX_OK;
1273
+ }
1274
+
1275
+ path.len -= root;
1276
+ path.data += root;
1277
+
1278
+ if (path.data[0] == '@') {
1279
+ (void) ngx_http_named_location(r, &path);
1280
+
1281
+ } else {
1282
+ ngx_http_split_args(r, &path, &args);
1283
+
1284
+ (void) ngx_http_internal_redirect(r, &path, &args);
1285
+ }
1286
+
1287
+ ngx_http_finalize_request(r, NGX_DONE);
1288
+ return NGX_OK;
1289
+ }
1290
+
1291
+ ngx_memzero(&of, sizeof(ngx_open_file_info_t));
1292
+
1293
+ of.read_ahead = clcf->read_ahead;
1294
+ of.directio = clcf->directio;
1295
+ of.valid = clcf->open_file_cache_valid;
1296
+ of.min_uses = clcf->open_file_cache_min_uses;
1297
+ of.test_only = 1;
1298
+ of.errors = clcf->open_file_cache_errors;
1299
+ of.events = clcf->open_file_cache_events;
1300
+
1301
+ if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
1302
+ != NGX_OK)
1303
+ {
1304
+ if (of.err != NGX_ENOENT
1305
+ && of.err != NGX_ENOTDIR
1306
+ && of.err != NGX_ENAMETOOLONG)
1307
+ {
1308
+ ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
1309
+ "%s \"%s\" failed", of.failed, path.data);
1310
+ }
1311
+
1312
+ continue;
1313
+ }
1314
+
1315
+ if (of.is_dir && !test_dir) {
1316
+ continue;
1317
+ }
1318
+
1319
+ path.len -= root;
1320
+ path.data += root;
1321
+
1322
+ if (!alias) {
1323
+ r->uri = path;
1324
+
1325
+ #if (NGX_PCRE)
1326
+ } else if (clcf->regex) {
1327
+ if (!test_dir) {
1328
+ r->uri = path;
1329
+ r->add_uri_to_alias = 1;
1330
+ }
1331
+ #endif
1332
+ } else {
1333
+ r->uri.len = alias + path.len;
1334
+ r->uri.data = ngx_pnalloc(r->pool, r->uri.len);
1335
+ if (r->uri.data == NULL) {
1336
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1337
+ return NGX_OK;
1338
+ }
1339
+
1340
+ p = ngx_copy(r->uri.data, clcf->name.data, alias);
1341
+ ngx_memcpy(p, name, path.len);
1342
+ }
1343
+
1344
+ ngx_http_set_exten(r);
1345
+
1346
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1347
+ "try file uri: \"%V\"", &r->uri);
1348
+
1349
+ r->phase_handler++;
1350
+ return NGX_AGAIN;
1351
+ }
1352
+
1353
+ /* not reached */
1354
+ }
1355
+
1356
+
1357
+ ngx_int_t
1358
+ ngx_http_core_content_phase(ngx_http_request_t *r,
1359
+ ngx_http_phase_handler_t *ph)
1360
+ {
1361
+ size_t root;
1362
+ ngx_int_t rc;
1363
+ ngx_str_t path;
1364
+
1365
+ if (r->content_handler) {
1366
+ r->write_event_handler = ngx_http_request_empty_handler;
1367
+ ngx_http_finalize_request(r, r->content_handler(r));
1368
+ return NGX_OK;
1369
+ }
1370
+
1371
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1372
+ "content phase: %ui", r->phase_handler);
1373
+
1374
+ rc = ph->handler(r);
1375
+
1376
+ if (rc != NGX_DECLINED) {
1377
+ ngx_http_finalize_request(r, rc);
1378
+ return NGX_OK;
1379
+ }
1380
+
1381
+ /* rc == NGX_DECLINED */
1382
+
1383
+ ph++;
1384
+
1385
+ if (ph->checker) {
1386
+ r->phase_handler++;
1387
+ return NGX_AGAIN;
1388
+ }
1389
+
1390
+ /* no content handler was found */
1391
+
1392
+ if (r->uri.data[r->uri.len - 1] == '/') {
1393
+
1394
+ if (ngx_http_map_uri_to_path(r, &path, &root, 0) != NULL) {
1395
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1396
+ "directory index of \"%s\" is forbidden", path.data);
1397
+ }
1398
+
1399
+ ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN);
1400
+ return NGX_OK;
1401
+ }
1402
+
1403
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found");
1404
+
1405
+ ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
1406
+ return NGX_OK;
1407
+ }
1408
+
1409
+
1410
+ void
1411
+ ngx_http_update_location_config(ngx_http_request_t *r)
1412
+ {
1413
+ ngx_http_core_loc_conf_t *clcf;
1414
+
1415
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1416
+
1417
+ if (r->method & clcf->limit_except) {
1418
+ r->loc_conf = clcf->limit_except_loc_conf;
1419
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1420
+ }
1421
+
1422
+ if (r == r->main) {
1423
+ r->connection->log->file = clcf->error_log->file;
1424
+
1425
+ if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
1426
+ r->connection->log->log_level = clcf->error_log->log_level;
1427
+ }
1428
+ }
1429
+
1430
+ if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
1431
+ r->connection->sendfile = 1;
1432
+
1433
+ } else {
1434
+ r->connection->sendfile = 0;
1435
+ }
1436
+
1437
+ if (clcf->client_body_in_file_only) {
1438
+ r->request_body_in_file_only = 1;
1439
+ r->request_body_in_persistent_file = 1;
1440
+ r->request_body_in_clean_file =
1441
+ clcf->client_body_in_file_only == NGX_HTTP_REQUEST_BODY_FILE_CLEAN;
1442
+ r->request_body_file_log_level = NGX_LOG_NOTICE;
1443
+
1444
+ } else {
1445
+ r->request_body_file_log_level = NGX_LOG_WARN;
1446
+ }
1447
+
1448
+ r->request_body_in_single_buf = clcf->client_body_in_single_buffer;
1449
+
1450
+ if (r->keepalive) {
1451
+ if (clcf->keepalive_timeout == 0) {
1452
+ r->keepalive = 0;
1453
+
1454
+ } else if (r->connection->requests >= clcf->keepalive_requests) {
1455
+ r->keepalive = 0;
1456
+
1457
+ } else if (r->headers_in.msie6
1458
+ && r->method == NGX_HTTP_POST
1459
+ && (clcf->keepalive_disable
1460
+ & NGX_HTTP_KEEPALIVE_DISABLE_MSIE6))
1461
+ {
1462
+ /*
1463
+ * MSIE may wait for some time if an response for
1464
+ * a POST request was sent over a keepalive connection
1465
+ */
1466
+ r->keepalive = 0;
1467
+
1468
+ } else if (r->headers_in.safari
1469
+ && (clcf->keepalive_disable
1470
+ & NGX_HTTP_KEEPALIVE_DISABLE_SAFARI))
1471
+ {
1472
+ /*
1473
+ * Safari may send a POST request to a closed keepalive
1474
+ * connection and may stall for some time, see
1475
+ * https://bugs.webkit.org/show_bug.cgi?id=5760
1476
+ */
1477
+ r->keepalive = 0;
1478
+ }
1479
+ }
1480
+
1481
+ if (!clcf->tcp_nopush) {
1482
+ /* disable TCP_NOPUSH/TCP_CORK use */
1483
+ r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
1484
+ }
1485
+
1486
+ if (r->limit_rate == 0) {
1487
+ r->limit_rate = clcf->limit_rate;
1488
+ }
1489
+
1490
+ if (clcf->handler) {
1491
+ r->content_handler = clcf->handler;
1492
+ }
1493
+ }
1494
+
1495
+
1496
+ /*
1497
+ * NGX_OK - exact or regex match
1498
+ * NGX_DONE - auto redirect
1499
+ * NGX_AGAIN - inclusive match
1500
+ * NGX_ERROR - regex error
1501
+ * NGX_DECLINED - no match
1502
+ */
1503
+
1504
+ static ngx_int_t
1505
+ ngx_http_core_find_location(ngx_http_request_t *r)
1506
+ {
1507
+ ngx_int_t rc;
1508
+ ngx_http_core_loc_conf_t *pclcf;
1509
+ #if (NGX_PCRE)
1510
+ ngx_int_t n;
1511
+ ngx_uint_t noregex;
1512
+ ngx_http_core_loc_conf_t *clcf, **clcfp;
1513
+
1514
+ noregex = 0;
1515
+ #endif
1516
+
1517
+ pclcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1518
+
1519
+ rc = ngx_http_core_find_static_location(r, pclcf->static_locations);
1520
+
1521
+ if (rc == NGX_AGAIN) {
1522
+
1523
+ #if (NGX_PCRE)
1524
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1525
+
1526
+ noregex = clcf->noregex;
1527
+ #endif
1528
+
1529
+ /* look up nested locations */
1530
+
1531
+ rc = ngx_http_core_find_location(r);
1532
+ }
1533
+
1534
+ if (rc == NGX_OK || rc == NGX_DONE) {
1535
+ return rc;
1536
+ }
1537
+
1538
+ /* rc == NGX_DECLINED or rc == NGX_AGAIN in nested location */
1539
+
1540
+ #if (NGX_PCRE)
1541
+
1542
+ if (noregex == 0 && pclcf->regex_locations) {
1543
+
1544
+ for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) {
1545
+
1546
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1547
+ "test location: ~ \"%V\"", &(*clcfp)->name);
1548
+
1549
+ n = ngx_http_regex_exec(r, (*clcfp)->regex, &r->uri);
1550
+
1551
+ if (n == NGX_OK) {
1552
+ r->loc_conf = (*clcfp)->loc_conf;
1553
+
1554
+ /* look up nested locations */
1555
+
1556
+ rc = ngx_http_core_find_location(r);
1557
+
1558
+ return (rc == NGX_ERROR) ? rc : NGX_OK;
1559
+ }
1560
+
1561
+ if (n == NGX_DECLINED) {
1562
+ continue;
1563
+ }
1564
+
1565
+ return NGX_ERROR;
1566
+ }
1567
+ }
1568
+ #endif
1569
+
1570
+ return rc;
1571
+ }
1572
+
1573
+
1574
+ /*
1575
+ * NGX_OK - exact match
1576
+ * NGX_DONE - auto redirect
1577
+ * NGX_AGAIN - inclusive match
1578
+ * NGX_DECLINED - no match
1579
+ */
1580
+
1581
+ static ngx_int_t
1582
+ ngx_http_core_find_static_location(ngx_http_request_t *r,
1583
+ ngx_http_location_tree_node_t *node)
1584
+ {
1585
+ u_char *uri;
1586
+ size_t len, n;
1587
+ ngx_int_t rc, rv;
1588
+
1589
+ len = r->uri.len;
1590
+ uri = r->uri.data;
1591
+
1592
+ rv = NGX_DECLINED;
1593
+
1594
+ for ( ;; ) {
1595
+
1596
+ if (node == NULL) {
1597
+ return rv;
1598
+ }
1599
+
1600
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1601
+ "test location: \"%*s\"", node->len, node->name);
1602
+
1603
+ n = (len <= (size_t) node->len) ? len : node->len;
1604
+
1605
+ rc = ngx_filename_cmp(uri, node->name, n);
1606
+
1607
+ if (rc != 0) {
1608
+ node = (rc < 0) ? node->left : node->right;
1609
+
1610
+ continue;
1611
+ }
1612
+
1613
+ if (len > (size_t) node->len) {
1614
+
1615
+ if (node->inclusive) {
1616
+
1617
+ r->loc_conf = node->inclusive->loc_conf;
1618
+ rv = NGX_AGAIN;
1619
+
1620
+ node = node->tree;
1621
+ uri += n;
1622
+ len -= n;
1623
+
1624
+ continue;
1625
+ }
1626
+
1627
+ /* exact only */
1628
+
1629
+ node = node->right;
1630
+
1631
+ continue;
1632
+ }
1633
+
1634
+ if (len == (size_t) node->len) {
1635
+
1636
+ if (node->exact) {
1637
+ r->loc_conf = node->exact->loc_conf;
1638
+ return NGX_OK;
1639
+
1640
+ } else {
1641
+ r->loc_conf = node->inclusive->loc_conf;
1642
+ return NGX_AGAIN;
1643
+ }
1644
+ }
1645
+
1646
+ /* len < node->len */
1647
+
1648
+ if (len + 1 == (size_t) node->len && node->auto_redirect) {
1649
+
1650
+ r->loc_conf = (node->exact) ? node->exact->loc_conf:
1651
+ node->inclusive->loc_conf;
1652
+ rv = NGX_DONE;
1653
+ }
1654
+
1655
+ node = node->left;
1656
+ }
1657
+ }
1658
+
1659
+
1660
+ void *
1661
+ ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash)
1662
+ {
1663
+ u_char c, *lowcase;
1664
+ size_t len;
1665
+ ngx_uint_t i, hash;
1666
+
1667
+ if (types_hash->size == 0) {
1668
+ return (void *) 4;
1669
+ }
1670
+
1671
+ if (r->headers_out.content_type.len == 0) {
1672
+ return NULL;
1673
+ }
1674
+
1675
+ len = r->headers_out.content_type_len;
1676
+
1677
+ if (r->headers_out.content_type_lowcase == NULL) {
1678
+
1679
+ lowcase = ngx_pnalloc(r->pool, len);
1680
+ if (lowcase == NULL) {
1681
+ return NULL;
1682
+ }
1683
+
1684
+ r->headers_out.content_type_lowcase = lowcase;
1685
+
1686
+ hash = 0;
1687
+
1688
+ for (i = 0; i < len; i++) {
1689
+ c = ngx_tolower(r->headers_out.content_type.data[i]);
1690
+ hash = ngx_hash(hash, c);
1691
+ lowcase[i] = c;
1692
+ }
1693
+
1694
+ r->headers_out.content_type_hash = hash;
1695
+ }
1696
+
1697
+ return ngx_hash_find(types_hash, r->headers_out.content_type_hash,
1698
+ r->headers_out.content_type_lowcase, len);
1699
+ }
1700
+
1701
+
1702
+ ngx_int_t
1703
+ ngx_http_set_content_type(ngx_http_request_t *r)
1704
+ {
1705
+ u_char c, *exten;
1706
+ ngx_str_t *type;
1707
+ ngx_uint_t i, hash;
1708
+ ngx_http_core_loc_conf_t *clcf;
1709
+
1710
+ if (r->headers_out.content_type.len) {
1711
+ return NGX_OK;
1712
+ }
1713
+
1714
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1715
+
1716
+ if (r->exten.len) {
1717
+
1718
+ hash = 0;
1719
+
1720
+ for (i = 0; i < r->exten.len; i++) {
1721
+ c = r->exten.data[i];
1722
+
1723
+ if (c >= 'A' && c <= 'Z') {
1724
+
1725
+ exten = ngx_pnalloc(r->pool, r->exten.len);
1726
+ if (exten == NULL) {
1727
+ return NGX_ERROR;
1728
+ }
1729
+
1730
+ hash = ngx_hash_strlow(exten, r->exten.data, r->exten.len);
1731
+
1732
+ r->exten.data = exten;
1733
+
1734
+ break;
1735
+ }
1736
+
1737
+ hash = ngx_hash(hash, c);
1738
+ }
1739
+
1740
+ type = ngx_hash_find(&clcf->types_hash, hash,
1741
+ r->exten.data, r->exten.len);
1742
+
1743
+ if (type) {
1744
+ r->headers_out.content_type_len = type->len;
1745
+ r->headers_out.content_type = *type;
1746
+
1747
+ return NGX_OK;
1748
+ }
1749
+ }
1750
+
1751
+ r->headers_out.content_type_len = clcf->default_type.len;
1752
+ r->headers_out.content_type = clcf->default_type;
1753
+
1754
+ return NGX_OK;
1755
+ }
1756
+
1757
+
1758
+ void
1759
+ ngx_http_set_exten(ngx_http_request_t *r)
1760
+ {
1761
+ ngx_int_t i;
1762
+
1763
+ ngx_str_null(&r->exten);
1764
+
1765
+ for (i = r->uri.len - 1; i > 1; i--) {
1766
+ if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
1767
+
1768
+ r->exten.len = r->uri.len - i - 1;
1769
+ r->exten.data = &r->uri.data[i + 1];
1770
+
1771
+ return;
1772
+
1773
+ } else if (r->uri.data[i] == '/') {
1774
+ return;
1775
+ }
1776
+ }
1777
+
1778
+ return;
1779
+ }
1780
+
1781
+
1782
+ ngx_int_t
1783
+ ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status,
1784
+ ngx_str_t *ct, ngx_http_complex_value_t *cv)
1785
+ {
1786
+ ngx_int_t rc;
1787
+ ngx_str_t val;
1788
+ ngx_buf_t *b;
1789
+ ngx_chain_t out;
1790
+
1791
+ if (ngx_http_discard_request_body(r) != NGX_OK) {
1792
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
1793
+ }
1794
+
1795
+ r->headers_out.status = status;
1796
+
1797
+ if (ngx_http_complex_value(r, cv, &val) != NGX_OK) {
1798
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
1799
+ }
1800
+
1801
+ if (status == NGX_HTTP_MOVED_PERMANENTLY
1802
+ || status == NGX_HTTP_MOVED_TEMPORARILY
1803
+ || status == NGX_HTTP_SEE_OTHER
1804
+ || status == NGX_HTTP_TEMPORARY_REDIRECT)
1805
+ {
1806
+ ngx_http_clear_location(r);
1807
+
1808
+ r->headers_out.location = ngx_list_push(&r->headers_out.headers);
1809
+ if (r->headers_out.location == NULL) {
1810
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
1811
+ }
1812
+
1813
+ r->headers_out.location->hash = 1;
1814
+ ngx_str_set(&r->headers_out.location->key, "Location");
1815
+ r->headers_out.location->value = val;
1816
+
1817
+ return status;
1818
+ }
1819
+
1820
+ r->headers_out.content_length_n = val.len;
1821
+
1822
+ if (ct) {
1823
+ r->headers_out.content_type_len = ct->len;
1824
+ r->headers_out.content_type = *ct;
1825
+
1826
+ } else {
1827
+ if (ngx_http_set_content_type(r) != NGX_OK) {
1828
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
1829
+ }
1830
+ }
1831
+
1832
+ if (r->method == NGX_HTTP_HEAD || (r != r->main && val.len == 0)) {
1833
+ return ngx_http_send_header(r);
1834
+ }
1835
+
1836
+ b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
1837
+ if (b == NULL) {
1838
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
1839
+ }
1840
+
1841
+ b->pos = val.data;
1842
+ b->last = val.data + val.len;
1843
+ b->memory = val.len ? 1 : 0;
1844
+ b->last_buf = (r == r->main) ? 1 : 0;
1845
+ b->last_in_chain = 1;
1846
+
1847
+ out.buf = b;
1848
+ out.next = NULL;
1849
+
1850
+ rc = ngx_http_send_header(r);
1851
+
1852
+ if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
1853
+ return rc;
1854
+ }
1855
+
1856
+ return ngx_http_output_filter(r, &out);
1857
+ }
1858
+
1859
+
1860
+ ngx_int_t
1861
+ ngx_http_send_header(ngx_http_request_t *r)
1862
+ {
1863
+ if (r->err_status) {
1864
+ r->headers_out.status = r->err_status;
1865
+ r->headers_out.status_line.len = 0;
1866
+ }
1867
+
1868
+ return ngx_http_top_header_filter(r);
1869
+ }
1870
+
1871
+
1872
+ ngx_int_t
1873
+ ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
1874
+ {
1875
+ ngx_int_t rc;
1876
+ ngx_connection_t *c;
1877
+
1878
+ c = r->connection;
1879
+
1880
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
1881
+ "http output filter \"%V?%V\"", &r->uri, &r->args);
1882
+
1883
+ rc = ngx_http_top_body_filter(r, in);
1884
+
1885
+ if (rc == NGX_ERROR) {
1886
+ /* NGX_ERROR may be returned by any filter */
1887
+ c->error = 1;
1888
+ }
1889
+
1890
+ return rc;
1891
+ }
1892
+
1893
+
1894
+ u_char *
1895
+ ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
1896
+ size_t *root_length, size_t reserved)
1897
+ {
1898
+ u_char *last;
1899
+ size_t alias;
1900
+ ngx_http_core_loc_conf_t *clcf;
1901
+
1902
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1903
+
1904
+ alias = clcf->alias;
1905
+
1906
+ if (alias && !r->valid_location) {
1907
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1908
+ "\"alias\" cannot be used in location \"%V\" "
1909
+ "where URI was rewritten", &clcf->name);
1910
+ return NULL;
1911
+ }
1912
+
1913
+ if (clcf->root_lengths == NULL) {
1914
+
1915
+ *root_length = clcf->root.len;
1916
+
1917
+ path->len = clcf->root.len + reserved + r->uri.len - alias + 1;
1918
+
1919
+ path->data = ngx_pnalloc(r->pool, path->len);
1920
+ if (path->data == NULL) {
1921
+ return NULL;
1922
+ }
1923
+
1924
+ last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
1925
+
1926
+ } else {
1927
+
1928
+ #if (NGX_PCRE)
1929
+ ngx_uint_t captures;
1930
+
1931
+ captures = alias && clcf->regex;
1932
+
1933
+ reserved += captures ? r->add_uri_to_alias ? r->uri.len + 1 : 1
1934
+ : r->uri.len - alias + 1;
1935
+ #else
1936
+ reserved += r->uri.len - alias + 1;
1937
+ #endif
1938
+
1939
+ if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
1940
+ clcf->root_values->elts)
1941
+ == NULL)
1942
+ {
1943
+ return NULL;
1944
+ }
1945
+
1946
+ if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path, 0) != NGX_OK) {
1947
+ return NULL;
1948
+ }
1949
+
1950
+ *root_length = path->len - reserved;
1951
+ last = path->data + *root_length;
1952
+
1953
+ #if (NGX_PCRE)
1954
+ if (captures) {
1955
+ if (!r->add_uri_to_alias) {
1956
+ *last = '\0';
1957
+ return last;
1958
+ }
1959
+
1960
+ alias = 0;
1961
+ }
1962
+ #endif
1963
+ }
1964
+
1965
+ last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
1966
+
1967
+ return last;
1968
+ }
1969
+
1970
+
1971
+ ngx_int_t
1972
+ ngx_http_auth_basic_user(ngx_http_request_t *r)
1973
+ {
1974
+ ngx_str_t auth, encoded;
1975
+ ngx_uint_t len;
1976
+
1977
+ if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
1978
+ return NGX_DECLINED;
1979
+ }
1980
+
1981
+ if (r->headers_in.authorization == NULL) {
1982
+ r->headers_in.user.data = (u_char *) "";
1983
+ return NGX_DECLINED;
1984
+ }
1985
+
1986
+ encoded = r->headers_in.authorization->value;
1987
+
1988
+ if (encoded.len < sizeof("Basic ") - 1
1989
+ || ngx_strncasecmp(encoded.data, (u_char *) "Basic ",
1990
+ sizeof("Basic ") - 1)
1991
+ != 0)
1992
+ {
1993
+ r->headers_in.user.data = (u_char *) "";
1994
+ return NGX_DECLINED;
1995
+ }
1996
+
1997
+ encoded.len -= sizeof("Basic ") - 1;
1998
+ encoded.data += sizeof("Basic ") - 1;
1999
+
2000
+ while (encoded.len && encoded.data[0] == ' ') {
2001
+ encoded.len--;
2002
+ encoded.data++;
2003
+ }
2004
+
2005
+ if (encoded.len == 0) {
2006
+ r->headers_in.user.data = (u_char *) "";
2007
+ return NGX_DECLINED;
2008
+ }
2009
+
2010
+ auth.len = ngx_base64_decoded_length(encoded.len);
2011
+ auth.data = ngx_pnalloc(r->pool, auth.len + 1);
2012
+ if (auth.data == NULL) {
2013
+ return NGX_ERROR;
2014
+ }
2015
+
2016
+ if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
2017
+ r->headers_in.user.data = (u_char *) "";
2018
+ return NGX_DECLINED;
2019
+ }
2020
+
2021
+ auth.data[auth.len] = '\0';
2022
+
2023
+ for (len = 0; len < auth.len; len++) {
2024
+ if (auth.data[len] == ':') {
2025
+ break;
2026
+ }
2027
+ }
2028
+
2029
+ if (len == 0 || len == auth.len) {
2030
+ r->headers_in.user.data = (u_char *) "";
2031
+ return NGX_DECLINED;
2032
+ }
2033
+
2034
+ r->headers_in.user.len = len;
2035
+ r->headers_in.user.data = auth.data;
2036
+ r->headers_in.passwd.len = auth.len - len - 1;
2037
+ r->headers_in.passwd.data = &auth.data[len + 1];
2038
+
2039
+ return NGX_OK;
2040
+ }
2041
+
2042
+
2043
+ #if (NGX_HTTP_GZIP)
2044
+
2045
+ ngx_int_t
2046
+ ngx_http_gzip_ok(ngx_http_request_t *r)
2047
+ {
2048
+ time_t date, expires;
2049
+ ngx_uint_t p;
2050
+ ngx_array_t *cc;
2051
+ ngx_table_elt_t *e, *d, *ae;
2052
+ ngx_http_core_loc_conf_t *clcf;
2053
+
2054
+ r->gzip_tested = 1;
2055
+
2056
+ if (r != r->main) {
2057
+ return NGX_DECLINED;
2058
+ }
2059
+
2060
+ ae = r->headers_in.accept_encoding;
2061
+ if (ae == NULL) {
2062
+ return NGX_DECLINED;
2063
+ }
2064
+
2065
+ if (ae->value.len < sizeof("gzip") - 1) {
2066
+ return NGX_DECLINED;
2067
+ }
2068
+
2069
+ /*
2070
+ * test first for the most common case "gzip,...":
2071
+ * MSIE: "gzip, deflate"
2072
+ * Firefox: "gzip,deflate"
2073
+ * Chrome: "gzip,deflate,sdch"
2074
+ * Safari: "gzip, deflate"
2075
+ * Opera: "gzip, deflate"
2076
+ */
2077
+
2078
+ if (ngx_memcmp(ae->value.data, "gzip,", 5) != 0
2079
+ && ngx_http_gzip_accept_encoding(&ae->value) != NGX_OK)
2080
+ {
2081
+ return NGX_DECLINED;
2082
+ }
2083
+
2084
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
2085
+
2086
+ if (r->headers_in.msie6 && clcf->gzip_disable_msie6) {
2087
+ return NGX_DECLINED;
2088
+ }
2089
+
2090
+ if (r->http_version < clcf->gzip_http_version) {
2091
+ return NGX_DECLINED;
2092
+ }
2093
+
2094
+ if (r->headers_in.via == NULL) {
2095
+ goto ok;
2096
+ }
2097
+
2098
+ p = clcf->gzip_proxied;
2099
+
2100
+ if (p & NGX_HTTP_GZIP_PROXIED_OFF) {
2101
+ return NGX_DECLINED;
2102
+ }
2103
+
2104
+ if (p & NGX_HTTP_GZIP_PROXIED_ANY) {
2105
+ goto ok;
2106
+ }
2107
+
2108
+ if (r->headers_in.authorization && (p & NGX_HTTP_GZIP_PROXIED_AUTH)) {
2109
+ goto ok;
2110
+ }
2111
+
2112
+ e = r->headers_out.expires;
2113
+
2114
+ if (e) {
2115
+
2116
+ if (!(p & NGX_HTTP_GZIP_PROXIED_EXPIRED)) {
2117
+ return NGX_DECLINED;
2118
+ }
2119
+
2120
+ expires = ngx_http_parse_time(e->value.data, e->value.len);
2121
+ if (expires == NGX_ERROR) {
2122
+ return NGX_DECLINED;
2123
+ }
2124
+
2125
+ d = r->headers_out.date;
2126
+
2127
+ if (d) {
2128
+ date = ngx_http_parse_time(d->value.data, d->value.len);
2129
+ if (date == NGX_ERROR) {
2130
+ return NGX_DECLINED;
2131
+ }
2132
+
2133
+ } else {
2134
+ date = ngx_time();
2135
+ }
2136
+
2137
+ if (expires < date) {
2138
+ goto ok;
2139
+ }
2140
+
2141
+ return NGX_DECLINED;
2142
+ }
2143
+
2144
+ cc = &r->headers_out.cache_control;
2145
+
2146
+ if (cc->elts) {
2147
+
2148
+ if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE)
2149
+ && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache,
2150
+ NULL)
2151
+ >= 0)
2152
+ {
2153
+ goto ok;
2154
+ }
2155
+
2156
+ if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE)
2157
+ && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store,
2158
+ NULL)
2159
+ >= 0)
2160
+ {
2161
+ goto ok;
2162
+ }
2163
+
2164
+ if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE)
2165
+ && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private,
2166
+ NULL)
2167
+ >= 0)
2168
+ {
2169
+ goto ok;
2170
+ }
2171
+
2172
+ return NGX_DECLINED;
2173
+ }
2174
+
2175
+ if ((p & NGX_HTTP_GZIP_PROXIED_NO_LM) && r->headers_out.last_modified) {
2176
+ return NGX_DECLINED;
2177
+ }
2178
+
2179
+ if ((p & NGX_HTTP_GZIP_PROXIED_NO_ETAG) && r->headers_out.etag) {
2180
+ return NGX_DECLINED;
2181
+ }
2182
+
2183
+ ok:
2184
+
2185
+ #if (NGX_PCRE)
2186
+
2187
+ if (clcf->gzip_disable && r->headers_in.user_agent) {
2188
+
2189
+ if (ngx_regex_exec_array(clcf->gzip_disable,
2190
+ &r->headers_in.user_agent->value,
2191
+ r->connection->log)
2192
+ != NGX_DECLINED)
2193
+ {
2194
+ return NGX_DECLINED;
2195
+ }
2196
+ }
2197
+
2198
+ #endif
2199
+
2200
+ r->gzip_ok = 1;
2201
+
2202
+ return NGX_OK;
2203
+ }
2204
+
2205
+
2206
+ /*
2207
+ * gzip is enabled for the following quantities:
2208
+ * "gzip; q=0.001" ... "gzip; q=1.000"
2209
+ * gzip is disabled for the following quantities:
2210
+ * "gzip; q=0" ... "gzip; q=0.000", and for any invalid cases
2211
+ */
2212
+
2213
+ static ngx_int_t
2214
+ ngx_http_gzip_accept_encoding(ngx_str_t *ae)
2215
+ {
2216
+ u_char *p, *start, *last;
2217
+
2218
+ start = ae->data;
2219
+ last = start + ae->len;
2220
+
2221
+ for ( ;; ) {
2222
+ p = ngx_strcasestrn(start, "gzip", 4 - 1);
2223
+ if (p == NULL) {
2224
+ return NGX_DECLINED;
2225
+ }
2226
+
2227
+ if (p == start || (*(p - 1) == ',' || *(p - 1) == ' ')) {
2228
+ break;
2229
+ }
2230
+
2231
+ start = p + 4;
2232
+ }
2233
+
2234
+ p += 4;
2235
+
2236
+ while (p < last) {
2237
+ switch(*p++) {
2238
+ case ',':
2239
+ return NGX_OK;
2240
+ case ';':
2241
+ goto quantity;
2242
+ case ' ':
2243
+ continue;
2244
+ default:
2245
+ return NGX_DECLINED;
2246
+ }
2247
+ }
2248
+
2249
+ return NGX_OK;
2250
+
2251
+ quantity:
2252
+
2253
+ while (p < last) {
2254
+ switch(*p++) {
2255
+ case 'q':
2256
+ case 'Q':
2257
+ goto equal;
2258
+ case ' ':
2259
+ continue;
2260
+ default:
2261
+ return NGX_DECLINED;
2262
+ }
2263
+ }
2264
+
2265
+ return NGX_OK;
2266
+
2267
+ equal:
2268
+
2269
+ if (p + 2 > last || *p++ != '=') {
2270
+ return NGX_DECLINED;
2271
+ }
2272
+
2273
+ if (ngx_http_gzip_quantity(p, last) == 0) {
2274
+ return NGX_DECLINED;
2275
+ }
2276
+
2277
+ return NGX_OK;
2278
+ }
2279
+
2280
+
2281
+ ngx_uint_t
2282
+ ngx_http_gzip_quantity(u_char *p, u_char *last)
2283
+ {
2284
+ u_char c;
2285
+ ngx_uint_t n, q;
2286
+
2287
+ c = *p++;
2288
+
2289
+ if (c != '0' && c != '1') {
2290
+ return 0;
2291
+ }
2292
+
2293
+ q = (c - '0') * 100;
2294
+
2295
+ if (p == last) {
2296
+ return q;
2297
+ }
2298
+
2299
+ c = *p++;
2300
+
2301
+ if (c == ',' || c == ' ') {
2302
+ return q;
2303
+ }
2304
+
2305
+ if (c != '.') {
2306
+ return 0;
2307
+ }
2308
+
2309
+ n = 0;
2310
+
2311
+ while (p < last) {
2312
+ c = *p++;
2313
+
2314
+ if (c == ',' || c == ' ') {
2315
+ break;
2316
+ }
2317
+
2318
+ if (c >= '0' && c <= '9') {
2319
+ q += c - '0';
2320
+ n++;
2321
+ continue;
2322
+ }
2323
+
2324
+ return 0;
2325
+ }
2326
+
2327
+ if (q > 100 || n > 3) {
2328
+ return 0;
2329
+ }
2330
+
2331
+ return q;
2332
+ }
2333
+
2334
+ #endif
2335
+
2336
+
2337
+ ngx_int_t
2338
+ ngx_http_subrequest(ngx_http_request_t *r,
2339
+ ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr,
2340
+ ngx_http_post_subrequest_t *ps, ngx_uint_t flags)
2341
+ {
2342
+ ngx_time_t *tp;
2343
+ ngx_connection_t *c;
2344
+ ngx_http_request_t *sr;
2345
+ ngx_http_core_srv_conf_t *cscf;
2346
+ ngx_http_postponed_request_t *pr, *p;
2347
+
2348
+ r->main->subrequests--;
2349
+
2350
+ if (r->main->subrequests == 0) {
2351
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2352
+ "subrequests cycle while processing \"%V\"", uri);
2353
+ r->main->subrequests = 1;
2354
+ return NGX_ERROR;
2355
+ }
2356
+
2357
+ sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
2358
+ if (sr == NULL) {
2359
+ return NGX_ERROR;
2360
+ }
2361
+
2362
+ sr->signature = NGX_HTTP_MODULE;
2363
+
2364
+ c = r->connection;
2365
+ sr->connection = c;
2366
+
2367
+ sr->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
2368
+ if (sr->ctx == NULL) {
2369
+ return NGX_ERROR;
2370
+ }
2371
+
2372
+ if (ngx_list_init(&sr->headers_out.headers, r->pool, 20,
2373
+ sizeof(ngx_table_elt_t))
2374
+ != NGX_OK)
2375
+ {
2376
+ return NGX_ERROR;
2377
+ }
2378
+
2379
+ cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2380
+ sr->main_conf = cscf->ctx->main_conf;
2381
+ sr->srv_conf = cscf->ctx->srv_conf;
2382
+ sr->loc_conf = cscf->ctx->loc_conf;
2383
+
2384
+ sr->pool = r->pool;
2385
+
2386
+ sr->headers_in = r->headers_in;
2387
+
2388
+ ngx_http_clear_content_length(sr);
2389
+ ngx_http_clear_accept_ranges(sr);
2390
+ ngx_http_clear_last_modified(sr);
2391
+
2392
+ sr->request_body = r->request_body;
2393
+
2394
+ sr->method = NGX_HTTP_GET;
2395
+ sr->http_version = r->http_version;
2396
+
2397
+ sr->request_line = r->request_line;
2398
+ sr->uri = *uri;
2399
+
2400
+ if (args) {
2401
+ sr->args = *args;
2402
+ }
2403
+
2404
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
2405
+ "http subrequest \"%V?%V\"", uri, &sr->args);
2406
+
2407
+ sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;
2408
+ sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0;
2409
+
2410
+ sr->unparsed_uri = r->unparsed_uri;
2411
+ sr->method_name = ngx_http_core_get_method;
2412
+ sr->http_protocol = r->http_protocol;
2413
+
2414
+ ngx_http_set_exten(sr);
2415
+
2416
+ sr->main = r->main;
2417
+ sr->parent = r;
2418
+ sr->post_subrequest = ps;
2419
+ sr->read_event_handler = ngx_http_request_empty_handler;
2420
+ sr->write_event_handler = ngx_http_handler;
2421
+
2422
+ if (c->data == r && r->postponed == NULL) {
2423
+ c->data = sr;
2424
+ }
2425
+
2426
+ sr->variables = r->variables;
2427
+
2428
+ sr->log_handler = r->log_handler;
2429
+
2430
+ pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
2431
+ if (pr == NULL) {
2432
+ return NGX_ERROR;
2433
+ }
2434
+
2435
+ pr->request = sr;
2436
+ pr->out = NULL;
2437
+ pr->next = NULL;
2438
+
2439
+ if (r->postponed) {
2440
+ for (p = r->postponed; p->next; p = p->next) { /* void */ }
2441
+ p->next = pr;
2442
+
2443
+ } else {
2444
+ r->postponed = pr;
2445
+ }
2446
+
2447
+ sr->internal = 1;
2448
+
2449
+ sr->discard_body = r->discard_body;
2450
+ sr->expect_tested = 1;
2451
+ sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
2452
+
2453
+ sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
2454
+
2455
+ tp = ngx_timeofday();
2456
+ sr->start_sec = tp->sec;
2457
+ sr->start_msec = tp->msec;
2458
+
2459
+ r->main->subrequests++;
2460
+ r->main->count++;
2461
+
2462
+ *psr = sr;
2463
+
2464
+ return ngx_http_post_request(sr, NULL);
2465
+ }
2466
+
2467
+
2468
+ ngx_int_t
2469
+ ngx_http_internal_redirect(ngx_http_request_t *r,
2470
+ ngx_str_t *uri, ngx_str_t *args)
2471
+ {
2472
+ ngx_http_core_srv_conf_t *cscf;
2473
+
2474
+ r->uri_changes--;
2475
+
2476
+ if (r->uri_changes == 0) {
2477
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2478
+ "rewrite or internal redirection cycle "
2479
+ "while internally redirecting to \"%V\"", uri);
2480
+
2481
+ r->main->count++;
2482
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2483
+ return NGX_DONE;
2484
+ }
2485
+
2486
+ r->uri = *uri;
2487
+
2488
+ if (args) {
2489
+ r->args = *args;
2490
+
2491
+ } else {
2492
+ ngx_str_null(&r->args);
2493
+ }
2494
+
2495
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2496
+ "internal redirect: \"%V?%V\"", uri, &r->args);
2497
+
2498
+ ngx_http_set_exten(r);
2499
+
2500
+ /* clear the modules contexts */
2501
+ ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
2502
+
2503
+ cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2504
+ r->loc_conf = cscf->ctx->loc_conf;
2505
+
2506
+ ngx_http_update_location_config(r);
2507
+
2508
+ #if (NGX_HTTP_CACHE)
2509
+ r->cache = NULL;
2510
+ #endif
2511
+
2512
+ r->internal = 1;
2513
+ r->add_uri_to_alias = 0;
2514
+ r->main->count++;
2515
+
2516
+ ngx_http_handler(r);
2517
+
2518
+ return NGX_DONE;
2519
+ }
2520
+
2521
+
2522
+ ngx_int_t
2523
+ ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name)
2524
+ {
2525
+ ngx_http_core_srv_conf_t *cscf;
2526
+ ngx_http_core_loc_conf_t **clcfp;
2527
+ ngx_http_core_main_conf_t *cmcf;
2528
+
2529
+ r->main->count++;
2530
+ r->uri_changes--;
2531
+
2532
+ if (r->uri_changes == 0) {
2533
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2534
+ "rewrite or internal redirection cycle "
2535
+ "while redirect to named location \"%V\"", name);
2536
+
2537
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2538
+ return NGX_DONE;
2539
+ }
2540
+
2541
+ cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
2542
+
2543
+ if (cscf->named_locations) {
2544
+
2545
+ for (clcfp = cscf->named_locations; *clcfp; clcfp++) {
2546
+
2547
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2548
+ "test location: \"%V\"", &(*clcfp)->name);
2549
+
2550
+ if (name->len != (*clcfp)->name.len
2551
+ || ngx_strncmp(name->data, (*clcfp)->name.data, name->len) != 0)
2552
+ {
2553
+ continue;
2554
+ }
2555
+
2556
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2557
+ "using location: %V \"%V?%V\"",
2558
+ name, &r->uri, &r->args);
2559
+
2560
+ r->internal = 1;
2561
+ r->content_handler = NULL;
2562
+ r->loc_conf = (*clcfp)->loc_conf;
2563
+
2564
+ ngx_http_update_location_config(r);
2565
+
2566
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
2567
+
2568
+ r->phase_handler = cmcf->phase_engine.location_rewrite_index;
2569
+
2570
+ ngx_http_core_run_phases(r);
2571
+
2572
+ return NGX_DONE;
2573
+ }
2574
+ }
2575
+
2576
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2577
+ "could not find named location \"%V\"", name);
2578
+
2579
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
2580
+
2581
+ return NGX_DONE;
2582
+ }
2583
+
2584
+
2585
+ ngx_http_cleanup_t *
2586
+ ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
2587
+ {
2588
+ ngx_http_cleanup_t *cln;
2589
+
2590
+ r = r->main;
2591
+
2592
+ cln = ngx_palloc(r->pool, sizeof(ngx_http_cleanup_t));
2593
+ if (cln == NULL) {
2594
+ return NULL;
2595
+ }
2596
+
2597
+ if (size) {
2598
+ cln->data = ngx_palloc(r->pool, size);
2599
+ if (cln->data == NULL) {
2600
+ return NULL;
2601
+ }
2602
+
2603
+ } else {
2604
+ cln->data = NULL;
2605
+ }
2606
+
2607
+ cln->handler = NULL;
2608
+ cln->next = r->cleanup;
2609
+
2610
+ r->cleanup = cln;
2611
+
2612
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2613
+ "http cleanup add: %p", cln);
2614
+
2615
+ return cln;
2616
+ }
2617
+
2618
+
2619
+ static char *
2620
+ ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
2621
+ {
2622
+ char *rv;
2623
+ void *mconf;
2624
+ ngx_uint_t i;
2625
+ ngx_conf_t pcf;
2626
+ ngx_http_module_t *module;
2627
+ struct sockaddr_in *sin;
2628
+ ngx_http_conf_ctx_t *ctx, *http_ctx;
2629
+ ngx_http_listen_opt_t lsopt;
2630
+ ngx_http_core_srv_conf_t *cscf, **cscfp;
2631
+ ngx_http_core_main_conf_t *cmcf;
2632
+
2633
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2634
+ if (ctx == NULL) {
2635
+ return NGX_CONF_ERROR;
2636
+ }
2637
+
2638
+ http_ctx = cf->ctx;
2639
+ ctx->main_conf = http_ctx->main_conf;
2640
+
2641
+ /* the server{}'s srv_conf */
2642
+
2643
+ ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2644
+ if (ctx->srv_conf == NULL) {
2645
+ return NGX_CONF_ERROR;
2646
+ }
2647
+
2648
+ /* the server{}'s loc_conf */
2649
+
2650
+ ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2651
+ if (ctx->loc_conf == NULL) {
2652
+ return NGX_CONF_ERROR;
2653
+ }
2654
+
2655
+ for (i = 0; ngx_modules[i]; i++) {
2656
+ if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
2657
+ continue;
2658
+ }
2659
+
2660
+ module = ngx_modules[i]->ctx;
2661
+
2662
+ if (module->create_srv_conf) {
2663
+ mconf = module->create_srv_conf(cf);
2664
+ if (mconf == NULL) {
2665
+ return NGX_CONF_ERROR;
2666
+ }
2667
+
2668
+ ctx->srv_conf[ngx_modules[i]->ctx_index] = mconf;
2669
+ }
2670
+
2671
+ if (module->create_loc_conf) {
2672
+ mconf = module->create_loc_conf(cf);
2673
+ if (mconf == NULL) {
2674
+ return NGX_CONF_ERROR;
2675
+ }
2676
+
2677
+ ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
2678
+ }
2679
+ }
2680
+
2681
+
2682
+ /* the server configuration context */
2683
+
2684
+ cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
2685
+ cscf->ctx = ctx;
2686
+
2687
+
2688
+ cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
2689
+
2690
+ cscfp = ngx_array_push(&cmcf->servers);
2691
+ if (cscfp == NULL) {
2692
+ return NGX_CONF_ERROR;
2693
+ }
2694
+
2695
+ *cscfp = cscf;
2696
+
2697
+
2698
+ /* parse inside server{} */
2699
+
2700
+ pcf = *cf;
2701
+ cf->ctx = ctx;
2702
+ cf->cmd_type = NGX_HTTP_SRV_CONF;
2703
+
2704
+ rv = ngx_conf_parse(cf, NULL);
2705
+
2706
+ *cf = pcf;
2707
+
2708
+ if (rv == NGX_CONF_OK && !cscf->listen) {
2709
+ ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
2710
+
2711
+ sin = &lsopt.u.sockaddr_in;
2712
+
2713
+ sin->sin_family = AF_INET;
2714
+ #if (NGX_WIN32)
2715
+ sin->sin_port = htons(80);
2716
+ #else
2717
+ sin->sin_port = htons((getuid() == 0) ? 80 : 8000);
2718
+ #endif
2719
+ sin->sin_addr.s_addr = INADDR_ANY;
2720
+
2721
+ lsopt.socklen = sizeof(struct sockaddr_in);
2722
+
2723
+ lsopt.backlog = NGX_LISTEN_BACKLOG;
2724
+ lsopt.rcvbuf = -1;
2725
+ lsopt.sndbuf = -1;
2726
+ #if (NGX_HAVE_SETFIB)
2727
+ lsopt.setfib = -1;
2728
+ #endif
2729
+ lsopt.wildcard = 1;
2730
+
2731
+ (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr,
2732
+ NGX_SOCKADDR_STRLEN, 1);
2733
+
2734
+ if (ngx_http_add_listen(cf, cscf, &lsopt) != NGX_OK) {
2735
+ return NGX_CONF_ERROR;
2736
+ }
2737
+ }
2738
+
2739
+ return rv;
2740
+ }
2741
+
2742
+
2743
+ static char *
2744
+ ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
2745
+ {
2746
+ char *rv;
2747
+ u_char *mod;
2748
+ size_t len;
2749
+ ngx_str_t *value, *name;
2750
+ ngx_uint_t i;
2751
+ ngx_conf_t save;
2752
+ ngx_http_module_t *module;
2753
+ ngx_http_conf_ctx_t *ctx, *pctx;
2754
+ ngx_http_core_loc_conf_t *clcf, *pclcf;
2755
+
2756
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2757
+ if (ctx == NULL) {
2758
+ return NGX_CONF_ERROR;
2759
+ }
2760
+
2761
+ pctx = cf->ctx;
2762
+ ctx->main_conf = pctx->main_conf;
2763
+ ctx->srv_conf = pctx->srv_conf;
2764
+
2765
+ ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2766
+ if (ctx->loc_conf == NULL) {
2767
+ return NGX_CONF_ERROR;
2768
+ }
2769
+
2770
+ for (i = 0; ngx_modules[i]; i++) {
2771
+ if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
2772
+ continue;
2773
+ }
2774
+
2775
+ module = ngx_modules[i]->ctx;
2776
+
2777
+ if (module->create_loc_conf) {
2778
+ ctx->loc_conf[ngx_modules[i]->ctx_index] =
2779
+ module->create_loc_conf(cf);
2780
+ if (ctx->loc_conf[ngx_modules[i]->ctx_index] == NULL) {
2781
+ return NGX_CONF_ERROR;
2782
+ }
2783
+ }
2784
+ }
2785
+
2786
+ clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
2787
+ clcf->loc_conf = ctx->loc_conf;
2788
+
2789
+ value = cf->args->elts;
2790
+
2791
+ if (cf->args->nelts == 3) {
2792
+
2793
+ len = value[1].len;
2794
+ mod = value[1].data;
2795
+ name = &value[2];
2796
+
2797
+ if (len == 1 && mod[0] == '=') {
2798
+
2799
+ clcf->name = *name;
2800
+ clcf->exact_match = 1;
2801
+
2802
+ } else if (len == 2 && mod[0] == '^' && mod[1] == '~') {
2803
+
2804
+ clcf->name = *name;
2805
+ clcf->noregex = 1;
2806
+
2807
+ } else if (len == 1 && mod[0] == '~') {
2808
+
2809
+ if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
2810
+ return NGX_CONF_ERROR;
2811
+ }
2812
+
2813
+ } else if (len == 2 && mod[0] == '~' && mod[1] == '*') {
2814
+
2815
+ if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
2816
+ return NGX_CONF_ERROR;
2817
+ }
2818
+
2819
+ } else {
2820
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2821
+ "invalid location modifier \"%V\"", &value[1]);
2822
+ return NGX_CONF_ERROR;
2823
+ }
2824
+
2825
+ } else {
2826
+
2827
+ name = &value[1];
2828
+
2829
+ if (name->data[0] == '=') {
2830
+
2831
+ clcf->name.len = name->len - 1;
2832
+ clcf->name.data = name->data + 1;
2833
+ clcf->exact_match = 1;
2834
+
2835
+ } else if (name->data[0] == '^' && name->data[1] == '~') {
2836
+
2837
+ clcf->name.len = name->len - 2;
2838
+ clcf->name.data = name->data + 2;
2839
+ clcf->noregex = 1;
2840
+
2841
+ } else if (name->data[0] == '~') {
2842
+
2843
+ name->len--;
2844
+ name->data++;
2845
+
2846
+ if (name->data[0] == '*') {
2847
+
2848
+ name->len--;
2849
+ name->data++;
2850
+
2851
+ if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
2852
+ return NGX_CONF_ERROR;
2853
+ }
2854
+
2855
+ } else {
2856
+ if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
2857
+ return NGX_CONF_ERROR;
2858
+ }
2859
+ }
2860
+
2861
+ } else {
2862
+
2863
+ clcf->name = *name;
2864
+
2865
+ if (name->data[0] == '@') {
2866
+ clcf->named = 1;
2867
+ }
2868
+ }
2869
+ }
2870
+
2871
+ pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
2872
+
2873
+ if (pclcf->name.len) {
2874
+
2875
+ /* nested location */
2876
+
2877
+ #if 0
2878
+ clcf->prev_location = pclcf;
2879
+ #endif
2880
+
2881
+ if (pclcf->exact_match) {
2882
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2883
+ "location \"%V\" cannot be inside "
2884
+ "the exact location \"%V\"",
2885
+ &clcf->name, &pclcf->name);
2886
+ return NGX_CONF_ERROR;
2887
+ }
2888
+
2889
+ if (pclcf->named) {
2890
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2891
+ "location \"%V\" cannot be inside "
2892
+ "the named location \"%V\"",
2893
+ &clcf->name, &pclcf->name);
2894
+ return NGX_CONF_ERROR;
2895
+ }
2896
+
2897
+ if (clcf->named) {
2898
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2899
+ "named location \"%V\" can be "
2900
+ "on the server level only",
2901
+ &clcf->name);
2902
+ return NGX_CONF_ERROR;
2903
+ }
2904
+
2905
+ len = pclcf->name.len;
2906
+
2907
+ #if (NGX_PCRE)
2908
+ if (clcf->regex == NULL
2909
+ && ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
2910
+ #else
2911
+ if (ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
2912
+ #endif
2913
+ {
2914
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2915
+ "location \"%V\" is outside location \"%V\"",
2916
+ &clcf->name, &pclcf->name);
2917
+ return NGX_CONF_ERROR;
2918
+ }
2919
+ }
2920
+
2921
+ if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
2922
+ return NGX_CONF_ERROR;
2923
+ }
2924
+
2925
+ save = *cf;
2926
+ cf->ctx = ctx;
2927
+ cf->cmd_type = NGX_HTTP_LOC_CONF;
2928
+
2929
+ rv = ngx_conf_parse(cf, NULL);
2930
+
2931
+ *cf = save;
2932
+
2933
+ return rv;
2934
+ }
2935
+
2936
+
2937
+ static ngx_int_t
2938
+ ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf,
2939
+ ngx_str_t *regex, ngx_uint_t caseless)
2940
+ {
2941
+ #if (NGX_PCRE)
2942
+ ngx_regex_compile_t rc;
2943
+ u_char errstr[NGX_MAX_CONF_ERRSTR];
2944
+
2945
+ ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
2946
+
2947
+ rc.pattern = *regex;
2948
+ rc.err.len = NGX_MAX_CONF_ERRSTR;
2949
+ rc.err.data = errstr;
2950
+
2951
+ #if (NGX_HAVE_CASELESS_FILESYSTEM)
2952
+ rc.options = NGX_REGEX_CASELESS;
2953
+ #else
2954
+ rc.options = caseless;
2955
+ #endif
2956
+
2957
+ clcf->regex = ngx_http_regex_compile(cf, &rc);
2958
+ if (clcf->regex == NULL) {
2959
+ return NGX_ERROR;
2960
+ }
2961
+
2962
+ clcf->name = *regex;
2963
+
2964
+ return NGX_OK;
2965
+
2966
+ #else
2967
+
2968
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2969
+ "using regex \"%V\" requires PCRE library",
2970
+ regex);
2971
+ return NGX_ERROR;
2972
+
2973
+ #endif
2974
+ }
2975
+
2976
+
2977
+ static char *
2978
+ ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2979
+ {
2980
+ ngx_http_core_loc_conf_t *clcf = conf;
2981
+
2982
+ char *rv;
2983
+ ngx_conf_t save;
2984
+
2985
+ if (clcf->types == NULL) {
2986
+ clcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
2987
+ if (clcf->types == NULL) {
2988
+ return NGX_CONF_ERROR;
2989
+ }
2990
+ }
2991
+
2992
+ save = *cf;
2993
+ cf->handler = ngx_http_core_type;
2994
+ cf->handler_conf = conf;
2995
+
2996
+ rv = ngx_conf_parse(cf, NULL);
2997
+
2998
+ *cf = save;
2999
+
3000
+ return rv;
3001
+ }
3002
+
3003
+
3004
+ static char *
3005
+ ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
3006
+ {
3007
+ ngx_http_core_loc_conf_t *clcf = conf;
3008
+
3009
+ ngx_str_t *value, *content_type, *old, file;
3010
+ ngx_uint_t i, n, hash;
3011
+ ngx_hash_key_t *type;
3012
+
3013
+ value = cf->args->elts;
3014
+
3015
+ if (ngx_strcmp(value[0].data, "include") == 0) {
3016
+ if (cf->args->nelts != 2) {
3017
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3018
+ "invalid number of arguments"
3019
+ " in \"include\" directive");
3020
+ return NGX_CONF_ERROR;
3021
+ }
3022
+ file = value[1];
3023
+
3024
+ if (ngx_conf_full_name(cf->cycle, &file, 1) != NGX_OK) {
3025
+ return NGX_CONF_ERROR;
3026
+ }
3027
+
3028
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
3029
+
3030
+ return ngx_conf_parse(cf, &file);
3031
+ }
3032
+
3033
+ content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
3034
+ if (content_type == NULL) {
3035
+ return NGX_CONF_ERROR;
3036
+ }
3037
+
3038
+ *content_type = value[0];
3039
+
3040
+ for (i = 1; i < cf->args->nelts; i++) {
3041
+
3042
+ hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
3043
+
3044
+ type = clcf->types->elts;
3045
+ for (n = 0; n < clcf->types->nelts; n++) {
3046
+ if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
3047
+ old = type[n].value;
3048
+ type[n].value = content_type;
3049
+
3050
+ ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
3051
+ "duplicate extension \"%V\", "
3052
+ "content type: \"%V\", "
3053
+ "previous content type: \"%V\"",
3054
+ &value[i], content_type, old);
3055
+ goto next;
3056
+ }
3057
+ }
3058
+
3059
+
3060
+ type = ngx_array_push(clcf->types);
3061
+ if (type == NULL) {
3062
+ return NGX_CONF_ERROR;
3063
+ }
3064
+
3065
+ type->key = value[i];
3066
+ type->key_hash = hash;
3067
+ type->value = content_type;
3068
+
3069
+ next:
3070
+ continue;
3071
+ }
3072
+
3073
+ return NGX_CONF_OK;
3074
+ }
3075
+
3076
+
3077
+ static ngx_int_t
3078
+ ngx_http_core_preconfiguration(ngx_conf_t *cf)
3079
+ {
3080
+ return ngx_http_variables_add_core_vars(cf);
3081
+ }
3082
+
3083
+
3084
+ static void *
3085
+ ngx_http_core_create_main_conf(ngx_conf_t *cf)
3086
+ {
3087
+ ngx_http_core_main_conf_t *cmcf;
3088
+
3089
+ cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
3090
+ if (cmcf == NULL) {
3091
+ return NULL;
3092
+ }
3093
+
3094
+ if (ngx_array_init(&cmcf->servers, cf->pool, 4,
3095
+ sizeof(ngx_http_core_srv_conf_t *))
3096
+ != NGX_OK)
3097
+ {
3098
+ return NULL;
3099
+ }
3100
+
3101
+ cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT;
3102
+ cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT;
3103
+
3104
+ cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
3105
+ cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
3106
+
3107
+ return cmcf;
3108
+ }
3109
+
3110
+
3111
+ static char *
3112
+ ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
3113
+ {
3114
+ ngx_http_core_main_conf_t *cmcf = conf;
3115
+
3116
+ if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) {
3117
+ cmcf->server_names_hash_max_size = 512;
3118
+ }
3119
+
3120
+ if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) {
3121
+ cmcf->server_names_hash_bucket_size = ngx_cacheline_size;
3122
+ }
3123
+
3124
+ cmcf->server_names_hash_bucket_size =
3125
+ ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size);
3126
+
3127
+
3128
+ if (cmcf->variables_hash_max_size == NGX_CONF_UNSET_UINT) {
3129
+ cmcf->variables_hash_max_size = 512;
3130
+ }
3131
+
3132
+ if (cmcf->variables_hash_bucket_size == NGX_CONF_UNSET_UINT) {
3133
+ cmcf->variables_hash_bucket_size = 64;
3134
+ }
3135
+
3136
+ cmcf->variables_hash_bucket_size =
3137
+ ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
3138
+
3139
+ if (cmcf->ncaptures) {
3140
+ cmcf->ncaptures = (cmcf->ncaptures + 1) * 3;
3141
+ }
3142
+
3143
+ return NGX_CONF_OK;
3144
+ }
3145
+
3146
+
3147
+ static void *
3148
+ ngx_http_core_create_srv_conf(ngx_conf_t *cf)
3149
+ {
3150
+ ngx_http_core_srv_conf_t *cscf;
3151
+
3152
+ cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
3153
+ if (cscf == NULL) {
3154
+ return NULL;
3155
+ }
3156
+
3157
+ /*
3158
+ * set by ngx_pcalloc():
3159
+ *
3160
+ * conf->client_large_buffers.num = 0;
3161
+ */
3162
+
3163
+ if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4,
3164
+ sizeof(ngx_http_server_name_t))
3165
+ != NGX_OK)
3166
+ {
3167
+ return NULL;
3168
+ }
3169
+
3170
+ cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
3171
+ cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
3172
+ cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
3173
+ cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
3174
+ cscf->ignore_invalid_headers = NGX_CONF_UNSET;
3175
+ cscf->merge_slashes = NGX_CONF_UNSET;
3176
+ cscf->underscores_in_headers = NGX_CONF_UNSET;
3177
+
3178
+ return cscf;
3179
+ }
3180
+
3181
+
3182
+ static char *
3183
+ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
3184
+ {
3185
+ ngx_http_core_srv_conf_t *prev = parent;
3186
+ ngx_http_core_srv_conf_t *conf = child;
3187
+
3188
+ ngx_str_t name;
3189
+ ngx_http_server_name_t *sn;
3190
+
3191
+ /* TODO: it does not merge, it inits only */
3192
+
3193
+ ngx_conf_merge_size_value(conf->connection_pool_size,
3194
+ prev->connection_pool_size, 256);
3195
+ ngx_conf_merge_size_value(conf->request_pool_size,
3196
+ prev->request_pool_size, 4096);
3197
+ ngx_conf_merge_msec_value(conf->client_header_timeout,
3198
+ prev->client_header_timeout, 60000);
3199
+ ngx_conf_merge_size_value(conf->client_header_buffer_size,
3200
+ prev->client_header_buffer_size, 1024);
3201
+ ngx_conf_merge_bufs_value(conf->large_client_header_buffers,
3202
+ prev->large_client_header_buffers,
3203
+ 4, 8192);
3204
+
3205
+ if (conf->large_client_header_buffers.size < conf->connection_pool_size) {
3206
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3207
+ "the \"large_client_header_buffers\" size must be "
3208
+ "equal to or greater than \"connection_pool_size\"");
3209
+ return NGX_CONF_ERROR;
3210
+ }
3211
+
3212
+ ngx_conf_merge_value(conf->ignore_invalid_headers,
3213
+ prev->ignore_invalid_headers, 1);
3214
+
3215
+ ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1);
3216
+
3217
+ ngx_conf_merge_value(conf->underscores_in_headers,
3218
+ prev->underscores_in_headers, 0);
3219
+
3220
+ if (conf->server_names.nelts == 0) {
3221
+ /* the array has 4 empty preallocated elements, so push cannot fail */
3222
+ sn = ngx_array_push(&conf->server_names);
3223
+ #if (NGX_PCRE)
3224
+ sn->regex = NULL;
3225
+ #endif
3226
+ sn->server = conf;
3227
+ ngx_str_set(&sn->name, "");
3228
+ }
3229
+
3230
+ sn = conf->server_names.elts;
3231
+ name = sn[0].name;
3232
+
3233
+ #if (NGX_PCRE)
3234
+ if (sn->regex) {
3235
+ name.len++;
3236
+ name.data--;
3237
+ } else
3238
+ #endif
3239
+
3240
+ if (name.data[0] == '.') {
3241
+ name.len--;
3242
+ name.data++;
3243
+ }
3244
+
3245
+ conf->server_name.len = name.len;
3246
+ conf->server_name.data = ngx_pstrdup(cf->pool, &name);
3247
+ if (conf->server_name.data == NULL) {
3248
+ return NGX_CONF_ERROR;
3249
+ }
3250
+
3251
+ return NGX_CONF_OK;
3252
+ }
3253
+
3254
+
3255
+ static void *
3256
+ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
3257
+ {
3258
+ ngx_http_core_loc_conf_t *clcf;
3259
+
3260
+ clcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
3261
+ if (clcf == NULL) {
3262
+ return NULL;
3263
+ }
3264
+
3265
+ /*
3266
+ * set by ngx_pcalloc():
3267
+ *
3268
+ * clcf->root = { 0, NULL };
3269
+ * clcf->limit_except = 0;
3270
+ * clcf->post_action = { 0, NULL };
3271
+ * clcf->types = NULL;
3272
+ * clcf->default_type = { 0, NULL };
3273
+ * clcf->error_log = NULL;
3274
+ * clcf->error_pages = NULL;
3275
+ * clcf->try_files = NULL;
3276
+ * clcf->client_body_path = NULL;
3277
+ * clcf->regex = NULL;
3278
+ * clcf->exact_match = 0;
3279
+ * clcf->auto_redirect = 0;
3280
+ * clcf->alias = 0;
3281
+ * clcf->gzip_proxied = 0;
3282
+ * clcf->keepalive_disable = 0;
3283
+ */
3284
+
3285
+ clcf->client_max_body_size = NGX_CONF_UNSET;
3286
+ clcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
3287
+ clcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
3288
+ clcf->satisfy = NGX_CONF_UNSET_UINT;
3289
+ clcf->if_modified_since = NGX_CONF_UNSET_UINT;
3290
+ clcf->max_ranges = NGX_CONF_UNSET_UINT;
3291
+ clcf->client_body_in_file_only = NGX_CONF_UNSET_UINT;
3292
+ clcf->client_body_in_single_buffer = NGX_CONF_UNSET;
3293
+ clcf->internal = NGX_CONF_UNSET;
3294
+ clcf->sendfile = NGX_CONF_UNSET;
3295
+ clcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE;
3296
+ #if (NGX_HAVE_FILE_AIO)
3297
+ clcf->aio = NGX_CONF_UNSET;
3298
+ #endif
3299
+ clcf->read_ahead = NGX_CONF_UNSET_SIZE;
3300
+ clcf->directio = NGX_CONF_UNSET;
3301
+ clcf->directio_alignment = NGX_CONF_UNSET;
3302
+ clcf->tcp_nopush = NGX_CONF_UNSET;
3303
+ clcf->tcp_nodelay = NGX_CONF_UNSET;
3304
+ clcf->send_timeout = NGX_CONF_UNSET_MSEC;
3305
+ clcf->send_lowat = NGX_CONF_UNSET_SIZE;
3306
+ clcf->postpone_output = NGX_CONF_UNSET_SIZE;
3307
+ clcf->limit_rate = NGX_CONF_UNSET_SIZE;
3308
+ clcf->limit_rate_after = NGX_CONF_UNSET_SIZE;
3309
+ clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
3310
+ clcf->keepalive_header = NGX_CONF_UNSET;
3311
+ clcf->keepalive_requests = NGX_CONF_UNSET_UINT;
3312
+ clcf->lingering_close = NGX_CONF_UNSET_UINT;
3313
+ clcf->lingering_time = NGX_CONF_UNSET_MSEC;
3314
+ clcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
3315
+ clcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
3316
+ clcf->reset_timedout_connection = NGX_CONF_UNSET;
3317
+ clcf->server_name_in_redirect = NGX_CONF_UNSET;
3318
+ clcf->port_in_redirect = NGX_CONF_UNSET;
3319
+ clcf->msie_padding = NGX_CONF_UNSET;
3320
+ clcf->msie_refresh = NGX_CONF_UNSET;
3321
+ clcf->log_not_found = NGX_CONF_UNSET;
3322
+ clcf->log_subrequest = NGX_CONF_UNSET;
3323
+ clcf->recursive_error_pages = NGX_CONF_UNSET;
3324
+ clcf->server_tokens = NGX_CONF_UNSET;
3325
+ clcf->chunked_transfer_encoding = NGX_CONF_UNSET;
3326
+ clcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
3327
+ clcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
3328
+
3329
+ clcf->open_file_cache = NGX_CONF_UNSET_PTR;
3330
+ clcf->open_file_cache_valid = NGX_CONF_UNSET;
3331
+ clcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT;
3332
+ clcf->open_file_cache_errors = NGX_CONF_UNSET;
3333
+ clcf->open_file_cache_events = NGX_CONF_UNSET;
3334
+
3335
+ #if (NGX_HTTP_GZIP)
3336
+ clcf->gzip_vary = NGX_CONF_UNSET;
3337
+ clcf->gzip_http_version = NGX_CONF_UNSET_UINT;
3338
+ #if (NGX_PCRE)
3339
+ clcf->gzip_disable = NGX_CONF_UNSET_PTR;
3340
+ #endif
3341
+ clcf->gzip_disable_msie6 = 3;
3342
+ #if (NGX_HTTP_DEGRADATION)
3343
+ clcf->gzip_disable_degradation = 3;
3344
+ #endif
3345
+ #endif
3346
+
3347
+ return clcf;
3348
+ }
3349
+
3350
+
3351
+ static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
3352
+ static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
3353
+ static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
3354
+
3355
+ static ngx_hash_key_t ngx_http_core_default_types[] = {
3356
+ { ngx_string("html"), 0, &ngx_http_core_text_html_type },
3357
+ { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
3358
+ { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
3359
+ { ngx_null_string, 0, NULL }
3360
+ };
3361
+
3362
+
3363
+ static char *
3364
+ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
3365
+ {
3366
+ ngx_http_core_loc_conf_t *prev = parent;
3367
+ ngx_http_core_loc_conf_t *conf = child;
3368
+
3369
+ ngx_uint_t i;
3370
+ ngx_hash_key_t *type;
3371
+ ngx_hash_init_t types_hash;
3372
+
3373
+ if (conf->root.data == NULL) {
3374
+
3375
+ conf->alias = prev->alias;
3376
+ conf->root = prev->root;
3377
+ conf->root_lengths = prev->root_lengths;
3378
+ conf->root_values = prev->root_values;
3379
+
3380
+ if (prev->root.data == NULL) {
3381
+ ngx_str_set(&conf->root, "html");
3382
+
3383
+ if (ngx_conf_full_name(cf->cycle, &conf->root, 0) != NGX_OK) {
3384
+ return NGX_CONF_ERROR;
3385
+ }
3386
+ }
3387
+ }
3388
+
3389
+ if (conf->post_action.data == NULL) {
3390
+ conf->post_action = prev->post_action;
3391
+ }
3392
+
3393
+ ngx_conf_merge_uint_value(conf->types_hash_max_size,
3394
+ prev->types_hash_max_size, 1024);
3395
+
3396
+ ngx_conf_merge_uint_value(conf->types_hash_bucket_size,
3397
+ prev->types_hash_bucket_size,
3398
+ ngx_cacheline_size);
3399
+
3400
+ conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
3401
+ ngx_cacheline_size);
3402
+
3403
+ /*
3404
+ * the special handling of the "types" directive in the "http" section
3405
+ * to inherit the http's conf->types_hash to all servers
3406
+ */
3407
+
3408
+ if (prev->types && prev->types_hash.buckets == NULL) {
3409
+
3410
+ types_hash.hash = &prev->types_hash;
3411
+ types_hash.key = ngx_hash_key_lc;
3412
+ types_hash.max_size = conf->types_hash_max_size;
3413
+ types_hash.bucket_size = conf->types_hash_bucket_size;
3414
+ types_hash.name = "types_hash";
3415
+ types_hash.pool = cf->pool;
3416
+ types_hash.temp_pool = NULL;
3417
+
3418
+ if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
3419
+ != NGX_OK)
3420
+ {
3421
+ return NGX_CONF_ERROR;
3422
+ }
3423
+ }
3424
+
3425
+ if (conf->types == NULL) {
3426
+ conf->types = prev->types;
3427
+ conf->types_hash = prev->types_hash;
3428
+ }
3429
+
3430
+ if (conf->types == NULL) {
3431
+ conf->types = ngx_array_create(cf->pool, 3, sizeof(ngx_hash_key_t));
3432
+ if (conf->types == NULL) {
3433
+ return NGX_CONF_ERROR;
3434
+ }
3435
+
3436
+ for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
3437
+ type = ngx_array_push(conf->types);
3438
+ if (type == NULL) {
3439
+ return NGX_CONF_ERROR;
3440
+ }
3441
+
3442
+ type->key = ngx_http_core_default_types[i].key;
3443
+ type->key_hash =
3444
+ ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
3445
+ ngx_http_core_default_types[i].key.len);
3446
+ type->value = ngx_http_core_default_types[i].value;
3447
+ }
3448
+ }
3449
+
3450
+ if (conf->types_hash.buckets == NULL) {
3451
+
3452
+ types_hash.hash = &conf->types_hash;
3453
+ types_hash.key = ngx_hash_key_lc;
3454
+ types_hash.max_size = conf->types_hash_max_size;
3455
+ types_hash.bucket_size = conf->types_hash_bucket_size;
3456
+ types_hash.name = "types_hash";
3457
+ types_hash.pool = cf->pool;
3458
+ types_hash.temp_pool = NULL;
3459
+
3460
+ if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
3461
+ != NGX_OK)
3462
+ {
3463
+ return NGX_CONF_ERROR;
3464
+ }
3465
+ }
3466
+
3467
+ if (conf->error_log == NULL) {
3468
+ if (prev->error_log) {
3469
+ conf->error_log = prev->error_log;
3470
+ } else {
3471
+ conf->error_log = &cf->cycle->new_log;
3472
+ }
3473
+ }
3474
+
3475
+ if (conf->error_pages == NULL && prev->error_pages) {
3476
+ conf->error_pages = prev->error_pages;
3477
+ }
3478
+
3479
+ ngx_conf_merge_str_value(conf->default_type,
3480
+ prev->default_type, "text/plain");
3481
+
3482
+ ngx_conf_merge_off_value(conf->client_max_body_size,
3483
+ prev->client_max_body_size, 1 * 1024 * 1024);
3484
+ ngx_conf_merge_size_value(conf->client_body_buffer_size,
3485
+ prev->client_body_buffer_size,
3486
+ (size_t) 2 * ngx_pagesize);
3487
+ ngx_conf_merge_msec_value(conf->client_body_timeout,
3488
+ prev->client_body_timeout, 60000);
3489
+
3490
+ ngx_conf_merge_bitmask_value(conf->keepalive_disable,
3491
+ prev->keepalive_disable,
3492
+ (NGX_CONF_BITMASK_SET
3493
+ |NGX_HTTP_KEEPALIVE_DISABLE_MSIE6
3494
+ |NGX_HTTP_KEEPALIVE_DISABLE_SAFARI));
3495
+ ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy,
3496
+ NGX_HTTP_SATISFY_ALL);
3497
+ ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since,
3498
+ NGX_HTTP_IMS_EXACT);
3499
+ ngx_conf_merge_uint_value(conf->max_ranges, prev->max_ranges,
3500
+ NGX_MAX_INT32_VALUE);
3501
+ ngx_conf_merge_uint_value(conf->client_body_in_file_only,
3502
+ prev->client_body_in_file_only,
3503
+ NGX_HTTP_REQUEST_BODY_FILE_OFF);
3504
+ ngx_conf_merge_value(conf->client_body_in_single_buffer,
3505
+ prev->client_body_in_single_buffer, 0);
3506
+ ngx_conf_merge_value(conf->internal, prev->internal, 0);
3507
+ ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
3508
+ ngx_conf_merge_size_value(conf->sendfile_max_chunk,
3509
+ prev->sendfile_max_chunk, 0);
3510
+ #if (NGX_HAVE_FILE_AIO)
3511
+ ngx_conf_merge_value(conf->aio, prev->aio, NGX_HTTP_AIO_OFF);
3512
+ #endif
3513
+ ngx_conf_merge_size_value(conf->read_ahead, prev->read_ahead, 0);
3514
+ ngx_conf_merge_off_value(conf->directio, prev->directio,
3515
+ NGX_OPEN_FILE_DIRECTIO_OFF);
3516
+ ngx_conf_merge_off_value(conf->directio_alignment, prev->directio_alignment,
3517
+ 512);
3518
+ ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
3519
+ ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1);
3520
+
3521
+ ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
3522
+ ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
3523
+ ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
3524
+ 1460);
3525
+ ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);
3526
+ ngx_conf_merge_size_value(conf->limit_rate_after, prev->limit_rate_after,
3527
+ 0);
3528
+ ngx_conf_merge_msec_value(conf->keepalive_timeout,
3529
+ prev->keepalive_timeout, 75000);
3530
+ ngx_conf_merge_sec_value(conf->keepalive_header,
3531
+ prev->keepalive_header, 0);
3532
+ ngx_conf_merge_uint_value(conf->keepalive_requests,
3533
+ prev->keepalive_requests, 100);
3534
+ ngx_conf_merge_uint_value(conf->lingering_close,
3535
+ prev->lingering_close, NGX_HTTP_LINGERING_ON);
3536
+ ngx_conf_merge_msec_value(conf->lingering_time,
3537
+ prev->lingering_time, 30000);
3538
+ ngx_conf_merge_msec_value(conf->lingering_timeout,
3539
+ prev->lingering_timeout, 5000);
3540
+ ngx_conf_merge_msec_value(conf->resolver_timeout,
3541
+ prev->resolver_timeout, 30000);
3542
+
3543
+ if (conf->resolver == NULL) {
3544
+
3545
+ if (prev->resolver == NULL) {
3546
+
3547
+ /*
3548
+ * create dummy resolver in http {} context
3549
+ * to inherit it in all servers
3550
+ */
3551
+
3552
+ prev->resolver = ngx_resolver_create(cf, NULL);
3553
+ if (prev->resolver == NULL) {
3554
+ return NGX_CONF_ERROR;
3555
+ }
3556
+ }
3557
+
3558
+ conf->resolver = prev->resolver;
3559
+ }
3560
+
3561
+ if (ngx_conf_merge_path_value(cf, &conf->client_body_temp_path,
3562
+ prev->client_body_temp_path,
3563
+ &ngx_http_client_temp_path)
3564
+ != NGX_OK)
3565
+ {
3566
+ return NGX_CONF_ERROR;
3567
+ }
3568
+
3569
+ ngx_conf_merge_value(conf->reset_timedout_connection,
3570
+ prev->reset_timedout_connection, 0);
3571
+ ngx_conf_merge_value(conf->server_name_in_redirect,
3572
+ prev->server_name_in_redirect, 0);
3573
+ ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
3574
+ ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
3575
+ ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0);
3576
+ ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
3577
+ ngx_conf_merge_value(conf->log_subrequest, prev->log_subrequest, 0);
3578
+ ngx_conf_merge_value(conf->recursive_error_pages,
3579
+ prev->recursive_error_pages, 0);
3580
+ ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1);
3581
+ ngx_conf_merge_value(conf->chunked_transfer_encoding,
3582
+ prev->chunked_transfer_encoding, 1);
3583
+
3584
+ ngx_conf_merge_ptr_value(conf->open_file_cache,
3585
+ prev->open_file_cache, NULL);
3586
+
3587
+ ngx_conf_merge_sec_value(conf->open_file_cache_valid,
3588
+ prev->open_file_cache_valid, 60);
3589
+
3590
+ ngx_conf_merge_uint_value(conf->open_file_cache_min_uses,
3591
+ prev->open_file_cache_min_uses, 1);
3592
+
3593
+ ngx_conf_merge_sec_value(conf->open_file_cache_errors,
3594
+ prev->open_file_cache_errors, 0);
3595
+
3596
+ ngx_conf_merge_sec_value(conf->open_file_cache_events,
3597
+ prev->open_file_cache_events, 0);
3598
+ #if (NGX_HTTP_GZIP)
3599
+
3600
+ ngx_conf_merge_value(conf->gzip_vary, prev->gzip_vary, 0);
3601
+ ngx_conf_merge_uint_value(conf->gzip_http_version, prev->gzip_http_version,
3602
+ NGX_HTTP_VERSION_11);
3603
+ ngx_conf_merge_bitmask_value(conf->gzip_proxied, prev->gzip_proxied,
3604
+ (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF));
3605
+
3606
+ #if (NGX_PCRE)
3607
+ ngx_conf_merge_ptr_value(conf->gzip_disable, prev->gzip_disable, NULL);
3608
+ #endif
3609
+
3610
+ if (conf->gzip_disable_msie6 == 3) {
3611
+ conf->gzip_disable_msie6 =
3612
+ (prev->gzip_disable_msie6 == 3) ? 0 : prev->gzip_disable_msie6;
3613
+ }
3614
+
3615
+ #if (NGX_HTTP_DEGRADATION)
3616
+
3617
+ if (conf->gzip_disable_degradation == 3) {
3618
+ conf->gzip_disable_degradation =
3619
+ (prev->gzip_disable_degradation == 3) ?
3620
+ 0 : prev->gzip_disable_degradation;
3621
+ }
3622
+
3623
+ #endif
3624
+ #endif
3625
+
3626
+ return NGX_CONF_OK;
3627
+ }
3628
+
3629
+
3630
+ static char *
3631
+ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3632
+ {
3633
+ ngx_http_core_srv_conf_t *cscf = conf;
3634
+
3635
+ ngx_str_t *value, size;
3636
+ ngx_url_t u;
3637
+ ngx_uint_t n;
3638
+ ngx_http_listen_opt_t lsopt;
3639
+
3640
+ cscf->listen = 1;
3641
+
3642
+ value = cf->args->elts;
3643
+
3644
+ ngx_memzero(&u, sizeof(ngx_url_t));
3645
+
3646
+ u.url = value[1];
3647
+ u.listen = 1;
3648
+ u.default_port = 80;
3649
+
3650
+ if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
3651
+ if (u.err) {
3652
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3653
+ "%s in \"%V\" of the \"listen\" directive",
3654
+ u.err, &u.url);
3655
+ }
3656
+
3657
+ return NGX_CONF_ERROR;
3658
+ }
3659
+
3660
+ ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
3661
+
3662
+ ngx_memcpy(&lsopt.u.sockaddr, u.sockaddr, u.socklen);
3663
+
3664
+ lsopt.socklen = u.socklen;
3665
+ lsopt.backlog = NGX_LISTEN_BACKLOG;
3666
+ lsopt.rcvbuf = -1;
3667
+ lsopt.sndbuf = -1;
3668
+ #if (NGX_HAVE_SETFIB)
3669
+ lsopt.setfib = -1;
3670
+ #endif
3671
+ lsopt.wildcard = u.wildcard;
3672
+
3673
+ (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr,
3674
+ NGX_SOCKADDR_STRLEN, 1);
3675
+
3676
+ for (n = 2; n < cf->args->nelts; n++) {
3677
+
3678
+ if (ngx_strcmp(value[n].data, "default_server") == 0
3679
+ || ngx_strcmp(value[n].data, "default") == 0)
3680
+ {
3681
+ lsopt.default_server = 1;
3682
+ continue;
3683
+ }
3684
+
3685
+ if (ngx_strcmp(value[n].data, "bind") == 0) {
3686
+ lsopt.set = 1;
3687
+ lsopt.bind = 1;
3688
+ continue;
3689
+ }
3690
+
3691
+ #if (NGX_HAVE_SETFIB)
3692
+ if (ngx_strncmp(value[n].data, "setfib=", 7) == 0) {
3693
+ lsopt.setfib = ngx_atoi(value[n].data + 7, value[n].len - 7);
3694
+
3695
+ if (lsopt.setfib == NGX_ERROR) {
3696
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3697
+ "invalid setfib \"%V\"", &value[n]);
3698
+ return NGX_CONF_ERROR;
3699
+ }
3700
+
3701
+ continue;
3702
+ }
3703
+ #endif
3704
+ if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
3705
+ lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
3706
+ lsopt.set = 1;
3707
+ lsopt.bind = 1;
3708
+
3709
+ if (lsopt.backlog == NGX_ERROR || lsopt.backlog == 0) {
3710
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3711
+ "invalid backlog \"%V\"", &value[n]);
3712
+ return NGX_CONF_ERROR;
3713
+ }
3714
+
3715
+ continue;
3716
+ }
3717
+
3718
+ if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
3719
+ size.len = value[n].len - 7;
3720
+ size.data = value[n].data + 7;
3721
+
3722
+ lsopt.rcvbuf = ngx_parse_size(&size);
3723
+ lsopt.set = 1;
3724
+ lsopt.bind = 1;
3725
+
3726
+ if (lsopt.rcvbuf == NGX_ERROR) {
3727
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3728
+ "invalid rcvbuf \"%V\"", &value[n]);
3729
+ return NGX_CONF_ERROR;
3730
+ }
3731
+
3732
+ continue;
3733
+ }
3734
+
3735
+ if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
3736
+ size.len = value[n].len - 7;
3737
+ size.data = value[n].data + 7;
3738
+
3739
+ lsopt.sndbuf = ngx_parse_size(&size);
3740
+ lsopt.set = 1;
3741
+ lsopt.bind = 1;
3742
+
3743
+ if (lsopt.sndbuf == NGX_ERROR) {
3744
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3745
+ "invalid sndbuf \"%V\"", &value[n]);
3746
+ return NGX_CONF_ERROR;
3747
+ }
3748
+
3749
+ continue;
3750
+ }
3751
+
3752
+ if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
3753
+ #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
3754
+ lsopt.accept_filter = (char *) &value[n].data[14];
3755
+ lsopt.set = 1;
3756
+ lsopt.bind = 1;
3757
+ #else
3758
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3759
+ "accept filters \"%V\" are not supported "
3760
+ "on this platform, ignored",
3761
+ &value[n]);
3762
+ #endif
3763
+ continue;
3764
+ }
3765
+
3766
+ if (ngx_strcmp(value[n].data, "deferred") == 0) {
3767
+ #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
3768
+ lsopt.deferred_accept = 1;
3769
+ lsopt.set = 1;
3770
+ lsopt.bind = 1;
3771
+ #else
3772
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3773
+ "the deferred accept is not supported "
3774
+ "on this platform, ignored");
3775
+ #endif
3776
+ continue;
3777
+ }
3778
+
3779
+ if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) {
3780
+ #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
3781
+ struct sockaddr *sa;
3782
+
3783
+ sa = &lsopt.u.sockaddr;
3784
+
3785
+ if (sa->sa_family == AF_INET6) {
3786
+
3787
+ if (ngx_strcmp(&value[n].data[10], "n") == 0) {
3788
+ lsopt.ipv6only = 1;
3789
+
3790
+ } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) {
3791
+ lsopt.ipv6only = 2;
3792
+
3793
+ } else {
3794
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3795
+ "invalid ipv6only flags \"%s\"",
3796
+ &value[n].data[9]);
3797
+ return NGX_CONF_ERROR;
3798
+ }
3799
+
3800
+ lsopt.set = 1;
3801
+ lsopt.bind = 1;
3802
+
3803
+ } else {
3804
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3805
+ "ipv6only is not supported "
3806
+ "on addr \"%s\", ignored", lsopt.addr);
3807
+ }
3808
+
3809
+ continue;
3810
+ #else
3811
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3812
+ "ipv6only is not supported "
3813
+ "on this platform");
3814
+ return NGX_CONF_ERROR;
3815
+ #endif
3816
+ }
3817
+
3818
+ if (ngx_strcmp(value[n].data, "ssl") == 0) {
3819
+ #if (NGX_HTTP_SSL)
3820
+ lsopt.ssl = 1;
3821
+ continue;
3822
+ #else
3823
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3824
+ "the \"ssl\" parameter requires "
3825
+ "ngx_http_ssl_module");
3826
+ return NGX_CONF_ERROR;
3827
+ #endif
3828
+ }
3829
+
3830
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3831
+ "invalid parameter \"%V\"", &value[n]);
3832
+ return NGX_CONF_ERROR;
3833
+ }
3834
+
3835
+ if (ngx_http_add_listen(cf, cscf, &lsopt) == NGX_OK) {
3836
+ return NGX_CONF_OK;
3837
+ }
3838
+
3839
+ return NGX_CONF_ERROR;
3840
+ }
3841
+
3842
+
3843
+ static char *
3844
+ ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3845
+ {
3846
+ ngx_http_core_srv_conf_t *cscf = conf;
3847
+
3848
+ u_char ch;
3849
+ ngx_str_t *value;
3850
+ ngx_uint_t i;
3851
+ ngx_http_server_name_t *sn;
3852
+
3853
+ value = cf->args->elts;
3854
+
3855
+ for (i = 1; i < cf->args->nelts; i++) {
3856
+
3857
+ ch = value[i].data[0];
3858
+
3859
+ if ((ch == '*' && (value[i].len < 3 || value[i].data[1] != '.'))
3860
+ || (ch == '.' && value[i].len < 2))
3861
+ {
3862
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3863
+ "server name \"%V\" is invalid", &value[i]);
3864
+ return NGX_CONF_ERROR;
3865
+ }
3866
+
3867
+ if (ngx_strchr(value[i].data, '/')) {
3868
+ ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
3869
+ "server name \"%V\" has suspicious symbols",
3870
+ &value[i]);
3871
+ }
3872
+
3873
+ sn = ngx_array_push(&cscf->server_names);
3874
+ if (sn == NULL) {
3875
+ return NGX_CONF_ERROR;
3876
+ }
3877
+
3878
+ #if (NGX_PCRE)
3879
+ sn->regex = NULL;
3880
+ #endif
3881
+ sn->server = cscf;
3882
+
3883
+ if (ngx_strcasecmp(value[i].data, (u_char *) "$hostname") == 0) {
3884
+ sn->name = cf->cycle->hostname;
3885
+
3886
+ } else {
3887
+ sn->name = value[i];
3888
+ }
3889
+
3890
+ if (value[i].data[0] != '~') {
3891
+ ngx_strlow(sn->name.data, sn->name.data, sn->name.len);
3892
+ continue;
3893
+ }
3894
+
3895
+ #if (NGX_PCRE)
3896
+ {
3897
+ u_char *p;
3898
+ ngx_regex_compile_t rc;
3899
+ u_char errstr[NGX_MAX_CONF_ERRSTR];
3900
+
3901
+ if (value[i].len == 1) {
3902
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3903
+ "empty regex in server name \"%V\"", &value[i]);
3904
+ return NGX_CONF_ERROR;
3905
+ }
3906
+
3907
+ value[i].len--;
3908
+ value[i].data++;
3909
+
3910
+ ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
3911
+
3912
+ rc.pattern = value[i];
3913
+ rc.err.len = NGX_MAX_CONF_ERRSTR;
3914
+ rc.err.data = errstr;
3915
+
3916
+ for (p = value[i].data; p < value[i].data + value[i].len; p++) {
3917
+ if (*p >= 'A' && *p <= 'Z') {
3918
+ rc.options = NGX_REGEX_CASELESS;
3919
+ break;
3920
+ }
3921
+ }
3922
+
3923
+ sn->regex = ngx_http_regex_compile(cf, &rc);
3924
+ if (sn->regex == NULL) {
3925
+ return NGX_CONF_ERROR;
3926
+ }
3927
+
3928
+ sn->name = value[i];
3929
+ cscf->captures = (rc.captures > 0);
3930
+ }
3931
+ #else
3932
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3933
+ "using regex \"%V\" "
3934
+ "requires PCRE library", &value[i]);
3935
+
3936
+ return NGX_CONF_ERROR;
3937
+ #endif
3938
+ }
3939
+
3940
+ return NGX_CONF_OK;
3941
+ }
3942
+
3943
+
3944
+ static char *
3945
+ ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3946
+ {
3947
+ ngx_http_core_loc_conf_t *clcf = conf;
3948
+
3949
+ ngx_str_t *value;
3950
+ ngx_int_t alias;
3951
+ ngx_uint_t n;
3952
+ ngx_http_script_compile_t sc;
3953
+
3954
+ alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
3955
+
3956
+ if (clcf->root.data) {
3957
+
3958
+ if ((clcf->alias != 0) == alias) {
3959
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3960
+ "\"%V\" directive is duplicate",
3961
+ &cmd->name);
3962
+ } else {
3963
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3964
+ "\"%V\" directive is duplicate, "
3965
+ "\"%s\" directive was specified earlier",
3966
+ &cmd->name, clcf->alias ? "alias" : "root");
3967
+ }
3968
+
3969
+ return NGX_CONF_ERROR;
3970
+ }
3971
+
3972
+ if (clcf->named && alias) {
3973
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3974
+ "the \"alias\" directive cannot be used "
3975
+ "inside the named location");
3976
+
3977
+ return NGX_CONF_ERROR;
3978
+ }
3979
+
3980
+ value = cf->args->elts;
3981
+
3982
+ if (ngx_strstr(value[1].data, "$document_root")
3983
+ || ngx_strstr(value[1].data, "${document_root}"))
3984
+ {
3985
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3986
+ "the $document_root variable cannot be used "
3987
+ "in the \"%V\" directive",
3988
+ &cmd->name);
3989
+
3990
+ return NGX_CONF_ERROR;
3991
+ }
3992
+
3993
+ if (ngx_strstr(value[1].data, "$realpath_root")
3994
+ || ngx_strstr(value[1].data, "${realpath_root}"))
3995
+ {
3996
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3997
+ "the $realpath_root variable cannot be used "
3998
+ "in the \"%V\" directive",
3999
+ &cmd->name);
4000
+
4001
+ return NGX_CONF_ERROR;
4002
+ }
4003
+
4004
+ clcf->alias = alias ? clcf->name.len : 0;
4005
+ clcf->root = value[1];
4006
+
4007
+ if (!alias && clcf->root.data[clcf->root.len - 1] == '/') {
4008
+ clcf->root.len--;
4009
+ }
4010
+
4011
+ if (clcf->root.data[0] != '$') {
4012
+ if (ngx_conf_full_name(cf->cycle, &clcf->root, 0) != NGX_OK) {
4013
+ return NGX_CONF_ERROR;
4014
+ }
4015
+ }
4016
+
4017
+ n = ngx_http_script_variables_count(&clcf->root);
4018
+
4019
+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
4020
+ sc.variables = n;
4021
+
4022
+ #if (NGX_PCRE)
4023
+ if (alias && clcf->regex) {
4024
+ n = 1;
4025
+ }
4026
+ #endif
4027
+
4028
+ if (n) {
4029
+ sc.cf = cf;
4030
+ sc.source = &clcf->root;
4031
+ sc.lengths = &clcf->root_lengths;
4032
+ sc.values = &clcf->root_values;
4033
+ sc.complete_lengths = 1;
4034
+ sc.complete_values = 1;
4035
+
4036
+ if (ngx_http_script_compile(&sc) != NGX_OK) {
4037
+ return NGX_CONF_ERROR;
4038
+ }
4039
+ }
4040
+
4041
+ return NGX_CONF_OK;
4042
+ }
4043
+
4044
+
4045
+ static ngx_http_method_name_t ngx_methods_names[] = {
4046
+ { (u_char *) "GET", (uint32_t) ~NGX_HTTP_GET },
4047
+ { (u_char *) "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
4048
+ { (u_char *) "POST", (uint32_t) ~NGX_HTTP_POST },
4049
+ { (u_char *) "PUT", (uint32_t) ~NGX_HTTP_PUT },
4050
+ { (u_char *) "DELETE", (uint32_t) ~NGX_HTTP_DELETE },
4051
+ { (u_char *) "MKCOL", (uint32_t) ~NGX_HTTP_MKCOL },
4052
+ { (u_char *) "COPY", (uint32_t) ~NGX_HTTP_COPY },
4053
+ { (u_char *) "MOVE", (uint32_t) ~NGX_HTTP_MOVE },
4054
+ { (u_char *) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS },
4055
+ { (u_char *) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND },
4056
+ { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH },
4057
+ { (u_char *) "LOCK", (uint32_t) ~NGX_HTTP_LOCK },
4058
+ { (u_char *) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK },
4059
+ { (u_char *) "PATCH", (uint32_t) ~NGX_HTTP_PATCH },
4060
+ { NULL, 0 }
4061
+ };
4062
+
4063
+
4064
+ static char *
4065
+ ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4066
+ {
4067
+ ngx_http_core_loc_conf_t *pclcf = conf;
4068
+
4069
+ char *rv;
4070
+ void *mconf;
4071
+ ngx_str_t *value;
4072
+ ngx_uint_t i;
4073
+ ngx_conf_t save;
4074
+ ngx_http_module_t *module;
4075
+ ngx_http_conf_ctx_t *ctx, *pctx;
4076
+ ngx_http_method_name_t *name;
4077
+ ngx_http_core_loc_conf_t *clcf;
4078
+
4079
+ if (pclcf->limit_except) {
4080
+ return "duplicate";
4081
+ }
4082
+
4083
+ pclcf->limit_except = 0xffffffff;
4084
+
4085
+ value = cf->args->elts;
4086
+
4087
+ for (i = 1; i < cf->args->nelts; i++) {
4088
+ for (name = ngx_methods_names; name->name; name++) {
4089
+
4090
+ if (ngx_strcasecmp(value[i].data, name->name) == 0) {
4091
+ pclcf->limit_except &= name->method;
4092
+ goto next;
4093
+ }
4094
+ }
4095
+
4096
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4097
+ "invalid method \"%V\"", &value[i]);
4098
+ return NGX_CONF_ERROR;
4099
+
4100
+ next:
4101
+ continue;
4102
+ }
4103
+
4104
+ if (!(pclcf->limit_except & NGX_HTTP_GET)) {
4105
+ pclcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
4106
+ }
4107
+
4108
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
4109
+ if (ctx == NULL) {
4110
+ return NGX_CONF_ERROR;
4111
+ }
4112
+
4113
+ pctx = cf->ctx;
4114
+ ctx->main_conf = pctx->main_conf;
4115
+ ctx->srv_conf = pctx->srv_conf;
4116
+
4117
+ ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
4118
+ if (ctx->loc_conf == NULL) {
4119
+ return NGX_CONF_ERROR;
4120
+ }
4121
+
4122
+ for (i = 0; ngx_modules[i]; i++) {
4123
+ if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
4124
+ continue;
4125
+ }
4126
+
4127
+ module = ngx_modules[i]->ctx;
4128
+
4129
+ if (module->create_loc_conf) {
4130
+
4131
+ mconf = module->create_loc_conf(cf);
4132
+ if (mconf == NULL) {
4133
+ return NGX_CONF_ERROR;
4134
+ }
4135
+
4136
+ ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
4137
+ }
4138
+ }
4139
+
4140
+
4141
+ clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
4142
+ pclcf->limit_except_loc_conf = ctx->loc_conf;
4143
+ clcf->loc_conf = ctx->loc_conf;
4144
+ clcf->name = pclcf->name;
4145
+ clcf->noname = 1;
4146
+ clcf->lmt_excpt = 1;
4147
+
4148
+ if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
4149
+ return NGX_CONF_ERROR;
4150
+ }
4151
+
4152
+ save = *cf;
4153
+ cf->ctx = ctx;
4154
+ cf->cmd_type = NGX_HTTP_LMT_CONF;
4155
+
4156
+ rv = ngx_conf_parse(cf, NULL);
4157
+
4158
+ *cf = save;
4159
+
4160
+ return rv;
4161
+ }
4162
+
4163
+
4164
+ static char *
4165
+ ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4166
+ {
4167
+ ngx_http_core_loc_conf_t *clcf = conf;
4168
+
4169
+ ngx_str_t *value;
4170
+
4171
+ if (clcf->directio != NGX_CONF_UNSET) {
4172
+ return "is duplicate";
4173
+ }
4174
+
4175
+ value = cf->args->elts;
4176
+
4177
+ if (ngx_strcmp(value[1].data, "off") == 0) {
4178
+ clcf->directio = NGX_OPEN_FILE_DIRECTIO_OFF;
4179
+ return NGX_CONF_OK;
4180
+ }
4181
+
4182
+ clcf->directio = ngx_parse_offset(&value[1]);
4183
+ if (clcf->directio == (off_t) NGX_ERROR) {
4184
+ return "invalid value";
4185
+ }
4186
+
4187
+ return NGX_CONF_OK;
4188
+ }
4189
+
4190
+
4191
+ static char *
4192
+ ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4193
+ {
4194
+ ngx_http_core_loc_conf_t *clcf = conf;
4195
+
4196
+ u_char *p;
4197
+ ngx_int_t overwrite;
4198
+ ngx_str_t *value, uri, args;
4199
+ ngx_uint_t i, n;
4200
+ ngx_http_err_page_t *err;
4201
+ ngx_http_complex_value_t cv;
4202
+ ngx_http_compile_complex_value_t ccv;
4203
+
4204
+ if (clcf->error_pages == NULL) {
4205
+ clcf->error_pages = ngx_array_create(cf->pool, 4,
4206
+ sizeof(ngx_http_err_page_t));
4207
+ if (clcf->error_pages == NULL) {
4208
+ return NGX_CONF_ERROR;
4209
+ }
4210
+ }
4211
+
4212
+ value = cf->args->elts;
4213
+
4214
+ i = cf->args->nelts - 2;
4215
+
4216
+ if (value[i].data[0] == '=') {
4217
+ if (i == 1) {
4218
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4219
+ "invalid value \"%V\"", &value[i]);
4220
+ return NGX_CONF_ERROR;
4221
+ }
4222
+
4223
+ if (value[i].len > 1) {
4224
+ overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1);
4225
+
4226
+ if (overwrite == NGX_ERROR) {
4227
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4228
+ "invalid value \"%V\"", &value[i]);
4229
+ return NGX_CONF_ERROR;
4230
+ }
4231
+
4232
+ } else {
4233
+ overwrite = 0;
4234
+ }
4235
+
4236
+ n = 2;
4237
+
4238
+ } else {
4239
+ overwrite = -1;
4240
+ n = 1;
4241
+ }
4242
+
4243
+ uri = value[cf->args->nelts - 1];
4244
+
4245
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
4246
+
4247
+ ccv.cf = cf;
4248
+ ccv.value = &uri;
4249
+ ccv.complex_value = &cv;
4250
+
4251
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
4252
+ return NGX_CONF_ERROR;
4253
+ }
4254
+
4255
+ ngx_str_null(&args);
4256
+
4257
+ if (cv.lengths == NULL && uri.data[0] == '/') {
4258
+ p = (u_char *) ngx_strchr(uri.data, '?');
4259
+
4260
+ if (p) {
4261
+ cv.value.len = p - uri.data;
4262
+ cv.value.data = uri.data;
4263
+ p++;
4264
+ args.len = (uri.data + uri.len) - p;
4265
+ args.data = p;
4266
+ }
4267
+ }
4268
+
4269
+ for (i = 1; i < cf->args->nelts - n; i++) {
4270
+ err = ngx_array_push(clcf->error_pages);
4271
+ if (err == NULL) {
4272
+ return NGX_CONF_ERROR;
4273
+ }
4274
+
4275
+ err->status = ngx_atoi(value[i].data, value[i].len);
4276
+
4277
+ if (err->status == NGX_ERROR || err->status == 499) {
4278
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4279
+ "invalid value \"%V\"", &value[i]);
4280
+ return NGX_CONF_ERROR;
4281
+ }
4282
+
4283
+ if (err->status < 300 || err->status > 599) {
4284
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4285
+ "value \"%V\" must be between 300 and 599",
4286
+ &value[i]);
4287
+ return NGX_CONF_ERROR;
4288
+ }
4289
+
4290
+ err->overwrite = overwrite;
4291
+
4292
+ if (overwrite == -1) {
4293
+ switch (err->status) {
4294
+ case NGX_HTTP_TO_HTTPS:
4295
+ case NGX_HTTPS_CERT_ERROR:
4296
+ case NGX_HTTPS_NO_CERT:
4297
+ err->overwrite = NGX_HTTP_BAD_REQUEST;
4298
+ default:
4299
+ break;
4300
+ }
4301
+ }
4302
+
4303
+ err->value = cv;
4304
+ err->args = args;
4305
+ }
4306
+
4307
+ return NGX_CONF_OK;
4308
+ }
4309
+
4310
+
4311
+ static char *
4312
+ ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4313
+ {
4314
+ ngx_http_core_loc_conf_t *clcf = conf;
4315
+
4316
+ ngx_str_t *value;
4317
+ ngx_int_t code;
4318
+ ngx_uint_t i, n;
4319
+ ngx_http_try_file_t *tf;
4320
+ ngx_http_script_compile_t sc;
4321
+ ngx_http_core_main_conf_t *cmcf;
4322
+
4323
+ if (clcf->try_files) {
4324
+ return "is duplicate";
4325
+ }
4326
+
4327
+ cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
4328
+
4329
+ cmcf->try_files = 1;
4330
+
4331
+ tf = ngx_pcalloc(cf->pool, cf->args->nelts * sizeof(ngx_http_try_file_t));
4332
+ if (tf == NULL) {
4333
+ return NGX_CONF_ERROR;
4334
+ }
4335
+
4336
+ clcf->try_files = tf;
4337
+
4338
+ value = cf->args->elts;
4339
+
4340
+ for (i = 0; i < cf->args->nelts - 1; i++) {
4341
+
4342
+ tf[i].name = value[i + 1];
4343
+
4344
+ if (tf[i].name.data[tf[i].name.len - 1] == '/') {
4345
+ tf[i].test_dir = 1;
4346
+ tf[i].name.len--;
4347
+ tf[i].name.data[tf[i].name.len] = '\0';
4348
+ }
4349
+
4350
+ n = ngx_http_script_variables_count(&tf[i].name);
4351
+
4352
+ if (n) {
4353
+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
4354
+
4355
+ sc.cf = cf;
4356
+ sc.source = &tf[i].name;
4357
+ sc.lengths = &tf[i].lengths;
4358
+ sc.values = &tf[i].values;
4359
+ sc.variables = n;
4360
+ sc.complete_lengths = 1;
4361
+ sc.complete_values = 1;
4362
+
4363
+ if (ngx_http_script_compile(&sc) != NGX_OK) {
4364
+ return NGX_CONF_ERROR;
4365
+ }
4366
+
4367
+ } else {
4368
+ /* add trailing '\0' to length */
4369
+ tf[i].name.len++;
4370
+ }
4371
+ }
4372
+
4373
+ if (tf[i - 1].name.data[0] == '=') {
4374
+
4375
+ code = ngx_atoi(tf[i - 1].name.data + 1, tf[i - 1].name.len - 2);
4376
+
4377
+ if (code == NGX_ERROR) {
4378
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4379
+ "invalid code \"%*s\"",
4380
+ tf[i - 1].name.len - 1, tf[i - 1].name.data);
4381
+ return NGX_CONF_ERROR;
4382
+ }
4383
+
4384
+ tf[i].code = code;
4385
+ }
4386
+
4387
+ return NGX_CONF_OK;
4388
+ }
4389
+
4390
+
4391
+ static char *
4392
+ ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4393
+ {
4394
+ ngx_http_core_loc_conf_t *clcf = conf;
4395
+
4396
+ time_t inactive;
4397
+ ngx_str_t *value, s;
4398
+ ngx_int_t max;
4399
+ ngx_uint_t i;
4400
+
4401
+ if (clcf->open_file_cache != NGX_CONF_UNSET_PTR) {
4402
+ return "is duplicate";
4403
+ }
4404
+
4405
+ value = cf->args->elts;
4406
+
4407
+ max = 0;
4408
+ inactive = 60;
4409
+
4410
+ for (i = 1; i < cf->args->nelts; i++) {
4411
+
4412
+ if (ngx_strncmp(value[i].data, "max=", 4) == 0) {
4413
+
4414
+ max = ngx_atoi(value[i].data + 4, value[i].len - 4);
4415
+ if (max <= 0) {
4416
+ goto failed;
4417
+ }
4418
+
4419
+ continue;
4420
+ }
4421
+
4422
+ if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {
4423
+
4424
+ s.len = value[i].len - 9;
4425
+ s.data = value[i].data + 9;
4426
+
4427
+ inactive = ngx_parse_time(&s, 1);
4428
+ if (inactive < 0) {
4429
+ goto failed;
4430
+ }
4431
+
4432
+ continue;
4433
+ }
4434
+
4435
+ if (ngx_strcmp(value[i].data, "off") == 0) {
4436
+
4437
+ clcf->open_file_cache = NULL;
4438
+
4439
+ continue;
4440
+ }
4441
+
4442
+ failed:
4443
+
4444
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4445
+ "invalid \"open_file_cache\" parameter \"%V\"",
4446
+ &value[i]);
4447
+ return NGX_CONF_ERROR;
4448
+ }
4449
+
4450
+ if (clcf->open_file_cache == NULL) {
4451
+ return NGX_CONF_OK;
4452
+ }
4453
+
4454
+ if (max == 0) {
4455
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4456
+ "\"open_file_cache\" must have the \"max\" parameter");
4457
+ return NGX_CONF_ERROR;
4458
+ }
4459
+
4460
+ clcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive);
4461
+ if (clcf->open_file_cache) {
4462
+ return NGX_CONF_OK;
4463
+ }
4464
+
4465
+ return NGX_CONF_ERROR;
4466
+ }
4467
+
4468
+
4469
+ static char *
4470
+ ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4471
+ {
4472
+ ngx_http_core_loc_conf_t *clcf = conf;
4473
+
4474
+ ngx_str_t *value;
4475
+
4476
+ if (clcf->error_log) {
4477
+ return "is duplicate";
4478
+ }
4479
+
4480
+ value = cf->args->elts;
4481
+
4482
+ clcf->error_log = ngx_log_create(cf->cycle, &value[1]);
4483
+ if (clcf->error_log == NULL) {
4484
+ return NGX_CONF_ERROR;
4485
+ }
4486
+
4487
+ if (cf->args->nelts == 2) {
4488
+ clcf->error_log->log_level = NGX_LOG_ERR;
4489
+ return NGX_CONF_OK;
4490
+ }
4491
+
4492
+ return ngx_log_set_levels(cf, clcf->error_log);
4493
+ }
4494
+
4495
+
4496
+ static char *
4497
+ ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4498
+ {
4499
+ ngx_http_core_loc_conf_t *clcf = conf;
4500
+
4501
+ ngx_str_t *value;
4502
+
4503
+ if (clcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) {
4504
+ return "is duplicate";
4505
+ }
4506
+
4507
+ value = cf->args->elts;
4508
+
4509
+ clcf->keepalive_timeout = ngx_parse_time(&value[1], 0);
4510
+
4511
+ if (clcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) {
4512
+ return "invalid value";
4513
+ }
4514
+
4515
+ if (clcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
4516
+ return "value must be less than 597 hours";
4517
+ }
4518
+
4519
+ if (cf->args->nelts == 2) {
4520
+ return NGX_CONF_OK;
4521
+ }
4522
+
4523
+ clcf->keepalive_header = ngx_parse_time(&value[2], 1);
4524
+
4525
+ if (clcf->keepalive_header == NGX_ERROR) {
4526
+ return "invalid value";
4527
+ }
4528
+
4529
+ if (clcf->keepalive_header == NGX_PARSE_LARGE_TIME) {
4530
+ return "value must be less than 68 years";
4531
+ }
4532
+
4533
+ return NGX_CONF_OK;
4534
+ }
4535
+
4536
+
4537
+ static char *
4538
+ ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4539
+ {
4540
+ ngx_http_core_loc_conf_t *clcf = conf;
4541
+
4542
+ if (clcf->internal != NGX_CONF_UNSET) {
4543
+ return "is duplicate";
4544
+ }
4545
+
4546
+ clcf->internal = 1;
4547
+
4548
+ return NGX_CONF_OK;
4549
+ }
4550
+
4551
+
4552
+ static char *
4553
+ ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4554
+ {
4555
+ ngx_http_core_loc_conf_t *clcf = conf;
4556
+
4557
+ ngx_url_t u;
4558
+ ngx_str_t *value;
4559
+
4560
+ if (clcf->resolver) {
4561
+ return "is duplicate";
4562
+ }
4563
+
4564
+ value = cf->args->elts;
4565
+
4566
+ ngx_memzero(&u, sizeof(ngx_url_t));
4567
+
4568
+ u.host = value[1];
4569
+ u.port = 53;
4570
+
4571
+ if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
4572
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err);
4573
+ return NGX_CONF_ERROR;
4574
+ }
4575
+
4576
+ clcf->resolver = ngx_resolver_create(cf, &u.addrs[0]);
4577
+ if (clcf->resolver == NULL) {
4578
+ return NGX_OK;
4579
+ }
4580
+
4581
+ return NGX_CONF_OK;
4582
+ }
4583
+
4584
+
4585
+ #if (NGX_HTTP_GZIP)
4586
+
4587
+ static char *
4588
+ ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4589
+ {
4590
+ ngx_http_core_loc_conf_t *clcf = conf;
4591
+
4592
+ #if (NGX_PCRE)
4593
+
4594
+ ngx_str_t *value;
4595
+ ngx_uint_t i;
4596
+ ngx_regex_elt_t *re;
4597
+ ngx_regex_compile_t rc;
4598
+ u_char errstr[NGX_MAX_CONF_ERRSTR];
4599
+
4600
+ if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) {
4601
+ clcf->gzip_disable = ngx_array_create(cf->pool, 2,
4602
+ sizeof(ngx_regex_elt_t));
4603
+ if (clcf->gzip_disable == NULL) {
4604
+ return NGX_CONF_ERROR;
4605
+ }
4606
+ }
4607
+
4608
+ value = cf->args->elts;
4609
+
4610
+ ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
4611
+
4612
+ rc.pool = cf->pool;
4613
+ rc.err.len = NGX_MAX_CONF_ERRSTR;
4614
+ rc.err.data = errstr;
4615
+
4616
+ for (i = 1; i < cf->args->nelts; i++) {
4617
+
4618
+ if (ngx_strcmp(value[i].data, "msie6") == 0) {
4619
+ clcf->gzip_disable_msie6 = 1;
4620
+ continue;
4621
+ }
4622
+
4623
+ #if (NGX_HTTP_DEGRADATION)
4624
+
4625
+ if (ngx_strcmp(value[i].data, "degradation") == 0) {
4626
+ clcf->gzip_disable_degradation = 1;
4627
+ continue;
4628
+ }
4629
+
4630
+ #endif
4631
+
4632
+ re = ngx_array_push(clcf->gzip_disable);
4633
+ if (re == NULL) {
4634
+ return NGX_CONF_ERROR;
4635
+ }
4636
+
4637
+ rc.pattern = value[i];
4638
+ rc.options = NGX_REGEX_CASELESS;
4639
+
4640
+ if (ngx_regex_compile(&rc) != NGX_OK) {
4641
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
4642
+ return NGX_CONF_ERROR;
4643
+ }
4644
+
4645
+ re->regex = rc.regex;
4646
+ re->name = value[i].data;
4647
+ }
4648
+
4649
+ return NGX_CONF_OK;
4650
+
4651
+ #else
4652
+ ngx_str_t *value;
4653
+ ngx_uint_t i;
4654
+
4655
+ value = cf->args->elts;
4656
+
4657
+ for (i = 1; i < cf->args->nelts; i++) {
4658
+ if (ngx_strcmp(value[i].data, "msie6") == 0) {
4659
+ clcf->gzip_disable_msie6 = 1;
4660
+ continue;
4661
+ }
4662
+
4663
+ #if (NGX_HTTP_DEGRADATION)
4664
+
4665
+ if (ngx_strcmp(value[i].data, "degradation") == 0) {
4666
+ clcf->gzip_disable_degradation = 1;
4667
+ continue;
4668
+ }
4669
+
4670
+ #endif
4671
+
4672
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4673
+ "without PCRE library \"gzip_disable\" supports "
4674
+ "builtin \"msie6\" and \"degradation\" mask only");
4675
+
4676
+ return NGX_CONF_ERROR;
4677
+ }
4678
+
4679
+ return NGX_CONF_OK;
4680
+
4681
+ #endif
4682
+ }
4683
+
4684
+ #endif
4685
+
4686
+
4687
+ static char *
4688
+ ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
4689
+ {
4690
+ #if (NGX_FREEBSD)
4691
+ ssize_t *np = data;
4692
+
4693
+ if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
4694
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4695
+ "\"send_lowat\" must be less than %d "
4696
+ "(sysctl net.inet.tcp.sendspace)",
4697
+ ngx_freebsd_net_inet_tcp_sendspace);
4698
+
4699
+ return NGX_CONF_ERROR;
4700
+ }
4701
+
4702
+ #elif !(NGX_HAVE_SO_SNDLOWAT)
4703
+ ssize_t *np = data;
4704
+
4705
+ ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
4706
+ "\"send_lowat\" is not supported, ignored");
4707
+
4708
+ *np = 0;
4709
+
4710
+ #endif
4711
+
4712
+ return NGX_CONF_OK;
4713
+ }
4714
+
4715
+
4716
+ static char *
4717
+ ngx_http_core_pool_size(ngx_conf_t *cf, void *post, void *data)
4718
+ {
4719
+ size_t *sp = data;
4720
+
4721
+ if (*sp < NGX_MIN_POOL_SIZE) {
4722
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4723
+ "the pool size must be no less than %uz",
4724
+ NGX_MIN_POOL_SIZE);
4725
+ return NGX_CONF_ERROR;
4726
+ }
4727
+
4728
+ if (*sp % NGX_POOL_ALIGNMENT) {
4729
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4730
+ "the pool size must be a multiple of %uz",
4731
+ NGX_POOL_ALIGNMENT);
4732
+ return NGX_CONF_ERROR;
4733
+ }
4734
+
4735
+ return NGX_CONF_OK;
4736
+ }