nginxtra 1.0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -0
- data/bin/nginxtra +5 -0
- data/lib/nginxtra.rb +12 -0
- data/lib/nginxtra/action.rb +36 -0
- data/lib/nginxtra/actions/compile.rb +60 -0
- data/lib/nginxtra/actions/install.rb +99 -0
- data/lib/nginxtra/actions/reload.rb +14 -0
- data/lib/nginxtra/actions/restart.rb +15 -0
- data/lib/nginxtra/actions/start.rb +53 -0
- data/lib/nginxtra/actions/status.rb +31 -0
- data/lib/nginxtra/actions/stop.rb +14 -0
- data/lib/nginxtra/cli.rb +77 -0
- data/lib/nginxtra/config.rb +339 -0
- data/lib/nginxtra/error.rb +13 -0
- data/lib/nginxtra/status.rb +57 -0
- data/src/nginx/CHANGES +5630 -0
- data/src/nginx/CHANGES.ru +5716 -0
- data/src/nginx/LICENSE +25 -0
- data/src/nginx/README +3 -0
- data/src/nginx/auto/cc/acc +15 -0
- data/src/nginx/auto/cc/bcc +72 -0
- data/src/nginx/auto/cc/ccc +46 -0
- data/src/nginx/auto/cc/conf +189 -0
- data/src/nginx/auto/cc/gcc +183 -0
- data/src/nginx/auto/cc/icc +121 -0
- data/src/nginx/auto/cc/msvc +138 -0
- data/src/nginx/auto/cc/name +101 -0
- data/src/nginx/auto/cc/owc +104 -0
- data/src/nginx/auto/cc/sunc +158 -0
- data/src/nginx/auto/define +12 -0
- data/src/nginx/auto/endianess +45 -0
- data/src/nginx/auto/feature +123 -0
- data/src/nginx/auto/have +12 -0
- data/src/nginx/auto/have_headers +12 -0
- data/src/nginx/auto/headers +13 -0
- data/src/nginx/auto/include +61 -0
- data/src/nginx/auto/init +51 -0
- data/src/nginx/auto/install +184 -0
- data/src/nginx/auto/lib/conf +83 -0
- data/src/nginx/auto/lib/geoip/conf +79 -0
- data/src/nginx/auto/lib/google-perftools/conf +45 -0
- data/src/nginx/auto/lib/libatomic/conf +43 -0
- data/src/nginx/auto/lib/libatomic/make +14 -0
- data/src/nginx/auto/lib/libgd/conf +83 -0
- data/src/nginx/auto/lib/libxslt/conf +156 -0
- data/src/nginx/auto/lib/make +32 -0
- data/src/nginx/auto/lib/md5/conf +103 -0
- data/src/nginx/auto/lib/md5/make +96 -0
- data/src/nginx/auto/lib/md5/makefile.bcc +22 -0
- data/src/nginx/auto/lib/md5/makefile.msvc +22 -0
- data/src/nginx/auto/lib/md5/makefile.owc +11 -0
- data/src/nginx/auto/lib/openssl/conf +74 -0
- data/src/nginx/auto/lib/openssl/make +67 -0
- data/src/nginx/auto/lib/openssl/makefile.bcc +18 -0
- data/src/nginx/auto/lib/openssl/makefile.msvc +14 -0
- data/src/nginx/auto/lib/pcre/conf +180 -0
- data/src/nginx/auto/lib/pcre/make +64 -0
- data/src/nginx/auto/lib/pcre/makefile.bcc +26 -0
- data/src/nginx/auto/lib/pcre/makefile.msvc +22 -0
- data/src/nginx/auto/lib/pcre/makefile.owc +24 -0
- data/src/nginx/auto/lib/perl/conf +60 -0
- data/src/nginx/auto/lib/perl/make +36 -0
- data/src/nginx/auto/lib/sha1/conf +79 -0
- data/src/nginx/auto/lib/sha1/make +96 -0
- data/src/nginx/auto/lib/sha1/makefile.bcc +22 -0
- data/src/nginx/auto/lib/sha1/makefile.msvc +22 -0
- data/src/nginx/auto/lib/sha1/makefile.owc +11 -0
- data/src/nginx/auto/lib/test +40 -0
- data/src/nginx/auto/lib/zlib/conf +76 -0
- data/src/nginx/auto/lib/zlib/make +114 -0
- data/src/nginx/auto/lib/zlib/makefile.bcc +15 -0
- data/src/nginx/auto/lib/zlib/makefile.msvc +14 -0
- data/src/nginx/auto/lib/zlib/makefile.owc +14 -0
- data/src/nginx/auto/lib/zlib/patch.zlib.h +10 -0
- data/src/nginx/auto/make +417 -0
- data/src/nginx/auto/modules +479 -0
- data/src/nginx/auto/nohave +12 -0
- data/src/nginx/auto/options +490 -0
- data/src/nginx/auto/os/conf +105 -0
- data/src/nginx/auto/os/darwin +116 -0
- data/src/nginx/auto/os/freebsd +136 -0
- data/src/nginx/auto/os/linux +152 -0
- data/src/nginx/auto/os/solaris +60 -0
- data/src/nginx/auto/os/win32 +29 -0
- data/src/nginx/auto/sources +518 -0
- data/src/nginx/auto/stubs +8 -0
- data/src/nginx/auto/summary +114 -0
- data/src/nginx/auto/types/sizeof +83 -0
- data/src/nginx/auto/types/typedef +77 -0
- data/src/nginx/auto/types/uintptr_t +42 -0
- data/src/nginx/auto/types/value +12 -0
- data/src/nginx/auto/unix +719 -0
- data/src/nginx/conf/fastcgi.conf +24 -0
- data/src/nginx/conf/fastcgi_params +23 -0
- data/src/nginx/conf/koi-utf +109 -0
- data/src/nginx/conf/koi-win +103 -0
- data/src/nginx/conf/mime.types +80 -0
- data/src/nginx/conf/nginx.conf +118 -0
- data/src/nginx/conf/scgi_params +15 -0
- data/src/nginx/conf/uwsgi_params +15 -0
- data/src/nginx/conf/win-utf +126 -0
- data/src/nginx/configure +108 -0
- data/src/nginx/contrib/README +15 -0
- data/src/nginx/contrib/geo2nginx.pl +58 -0
- data/src/nginx/contrib/unicode2nginx/koi-utf +131 -0
- data/src/nginx/contrib/unicode2nginx/unicode-to-nginx.pl +45 -0
- data/src/nginx/contrib/unicode2nginx/win-utf +130 -0
- data/src/nginx/html/50x.html +18 -0
- data/src/nginx/html/index.html +8 -0
- data/src/nginx/man/nginx.8 +202 -0
- data/src/nginx/src/core/nginx.c +1333 -0
- data/src/nginx/src/core/nginx.h +20 -0
- data/src/nginx/src/core/ngx_array.c +147 -0
- data/src/nginx/src/core/ngx_array.h +53 -0
- data/src/nginx/src/core/ngx_buf.c +218 -0
- data/src/nginx/src/core/ngx_buf.h +162 -0
- data/src/nginx/src/core/ngx_conf_file.c +1506 -0
- data/src/nginx/src/core/ngx_conf_file.h +348 -0
- data/src/nginx/src/core/ngx_config.h +134 -0
- data/src/nginx/src/core/ngx_connection.c +1074 -0
- data/src/nginx/src/core/ngx_connection.h +195 -0
- data/src/nginx/src/core/ngx_core.h +95 -0
- data/src/nginx/src/core/ngx_cpuinfo.c +139 -0
- data/src/nginx/src/core/ngx_crc.h +39 -0
- data/src/nginx/src/core/ngx_crc32.c +129 -0
- data/src/nginx/src/core/ngx_crc32.h +79 -0
- data/src/nginx/src/core/ngx_crypt.c +238 -0
- data/src/nginx/src/core/ngx_crypt.h +20 -0
- data/src/nginx/src/core/ngx_cycle.c +1379 -0
- data/src/nginx/src/core/ngx_cycle.h +142 -0
- data/src/nginx/src/core/ngx_file.c +993 -0
- data/src/nginx/src/core/ngx_file.h +151 -0
- data/src/nginx/src/core/ngx_hash.c +976 -0
- data/src/nginx/src/core/ngx_hash.h +122 -0
- data/src/nginx/src/core/ngx_inet.c +1008 -0
- data/src/nginx/src/core/ngx_inet.h +120 -0
- data/src/nginx/src/core/ngx_list.c +71 -0
- data/src/nginx/src/core/ngx_list.h +83 -0
- data/src/nginx/src/core/ngx_log.c +459 -0
- data/src/nginx/src/core/ngx_log.h +250 -0
- data/src/nginx/src/core/ngx_md5.c +289 -0
- data/src/nginx/src/core/ngx_md5.h +60 -0
- data/src/nginx/src/core/ngx_murmurhash.c +50 -0
- data/src/nginx/src/core/ngx_murmurhash.h +19 -0
- data/src/nginx/src/core/ngx_open_file_cache.c +882 -0
- data/src/nginx/src/core/ngx_open_file_cache.h +119 -0
- data/src/nginx/src/core/ngx_output_chain.c +673 -0
- data/src/nginx/src/core/ngx_palloc.c +433 -0
- data/src/nginx/src/core/ngx_palloc.h +95 -0
- data/src/nginx/src/core/ngx_parse.c +249 -0
- data/src/nginx/src/core/ngx_parse.h +24 -0
- data/src/nginx/src/core/ngx_queue.c +80 -0
- data/src/nginx/src/core/ngx_queue.h +112 -0
- data/src/nginx/src/core/ngx_radix_tree.c +291 -0
- data/src/nginx/src/core/ngx_radix_tree.h +46 -0
- data/src/nginx/src/core/ngx_rbtree.c +383 -0
- data/src/nginx/src/core/ngx_rbtree.h +84 -0
- data/src/nginx/src/core/ngx_regex.c +206 -0
- data/src/nginx/src/core/ngx_regex.h +56 -0
- data/src/nginx/src/core/ngx_resolver.c +2201 -0
- data/src/nginx/src/core/ngx_resolver.h +149 -0
- data/src/nginx/src/core/ngx_sha1.h +31 -0
- data/src/nginx/src/core/ngx_shmtx.c +284 -0
- data/src/nginx/src/core/ngx_shmtx.h +38 -0
- data/src/nginx/src/core/ngx_slab.c +701 -0
- data/src/nginx/src/core/ngx_slab.h +54 -0
- data/src/nginx/src/core/ngx_spinlock.c +53 -0
- data/src/nginx/src/core/ngx_string.c +1837 -0
- data/src/nginx/src/core/ngx_string.h +231 -0
- data/src/nginx/src/core/ngx_times.c +407 -0
- data/src/nginx/src/core/ngx_times.h +51 -0
- data/src/nginx/src/event/modules/ngx_aio_module.c +171 -0
- data/src/nginx/src/event/modules/ngx_devpoll_module.c +569 -0
- data/src/nginx/src/event/modules/ngx_epoll_module.c +833 -0
- data/src/nginx/src/event/modules/ngx_eventport_module.c +602 -0
- data/src/nginx/src/event/modules/ngx_kqueue_module.c +785 -0
- data/src/nginx/src/event/modules/ngx_poll_module.c +443 -0
- data/src/nginx/src/event/modules/ngx_rtsig_module.c +735 -0
- data/src/nginx/src/event/modules/ngx_select_module.c +435 -0
- data/src/nginx/src/event/modules/ngx_win32_select_module.c +400 -0
- data/src/nginx/src/event/ngx_event.c +1275 -0
- data/src/nginx/src/event/ngx_event.h +573 -0
- data/src/nginx/src/event/ngx_event_accept.c +428 -0
- data/src/nginx/src/event/ngx_event_busy_lock.c +286 -0
- data/src/nginx/src/event/ngx_event_busy_lock.h +65 -0
- data/src/nginx/src/event/ngx_event_connect.c +258 -0
- data/src/nginx/src/event/ngx_event_connect.h +76 -0
- data/src/nginx/src/event/ngx_event_mutex.c +70 -0
- data/src/nginx/src/event/ngx_event_openssl.c +2382 -0
- data/src/nginx/src/event/ngx_event_openssl.h +162 -0
- data/src/nginx/src/event/ngx_event_pipe.c +996 -0
- data/src/nginx/src/event/ngx_event_pipe.h +95 -0
- data/src/nginx/src/event/ngx_event_posted.c +173 -0
- data/src/nginx/src/event/ngx_event_posted.h +75 -0
- data/src/nginx/src/event/ngx_event_timer.c +159 -0
- data/src/nginx/src/event/ngx_event_timer.h +102 -0
- data/src/nginx/src/http/modules/ngx_http_access_module.c +384 -0
- data/src/nginx/src/http/modules/ngx_http_addition_filter_module.c +250 -0
- data/src/nginx/src/http/modules/ngx_http_auth_basic_module.c +478 -0
- data/src/nginx/src/http/modules/ngx_http_autoindex_module.c +701 -0
- data/src/nginx/src/http/modules/ngx_http_browser_module.c +713 -0
- data/src/nginx/src/http/modules/ngx_http_charset_filter_module.c +1681 -0
- data/src/nginx/src/http/modules/ngx_http_chunked_filter_module.c +242 -0
- data/src/nginx/src/http/modules/ngx_http_dav_module.c +1141 -0
- data/src/nginx/src/http/modules/ngx_http_degradation_module.c +243 -0
- data/src/nginx/src/http/modules/ngx_http_empty_gif_module.c +140 -0
- data/src/nginx/src/http/modules/ngx_http_fastcgi_module.c +2916 -0
- data/src/nginx/src/http/modules/ngx_http_flv_module.c +254 -0
- data/src/nginx/src/http/modules/ngx_http_geo_module.c +1441 -0
- data/src/nginx/src/http/modules/ngx_http_geoip_module.c +671 -0
- data/src/nginx/src/http/modules/ngx_http_gzip_filter_module.c +1206 -0
- data/src/nginx/src/http/modules/ngx_http_gzip_static_module.c +299 -0
- data/src/nginx/src/http/modules/ngx_http_headers_filter_module.c +616 -0
- data/src/nginx/src/http/modules/ngx_http_image_filter_module.c +1489 -0
- data/src/nginx/src/http/modules/ngx_http_index_module.c +516 -0
- data/src/nginx/src/http/modules/ngx_http_limit_req_module.c +809 -0
- data/src/nginx/src/http/modules/ngx_http_limit_zone_module.c +553 -0
- data/src/nginx/src/http/modules/ngx_http_log_module.c +1357 -0
- data/src/nginx/src/http/modules/ngx_http_map_module.c +575 -0
- data/src/nginx/src/http/modules/ngx_http_memcached_module.c +624 -0
- data/src/nginx/src/http/modules/ngx_http_mp4_module.c +3000 -0
- data/src/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +143 -0
- data/src/nginx/src/http/modules/ngx_http_proxy_module.c +2831 -0
- data/src/nginx/src/http/modules/ngx_http_random_index_module.c +317 -0
- data/src/nginx/src/http/modules/ngx_http_range_filter_module.c +855 -0
- data/src/nginx/src/http/modules/ngx_http_realip_module.c +476 -0
- data/src/nginx/src/http/modules/ngx_http_referer_module.c +613 -0
- data/src/nginx/src/http/modules/ngx_http_rewrite_module.c +1019 -0
- data/src/nginx/src/http/modules/ngx_http_scgi_module.c +1714 -0
- data/src/nginx/src/http/modules/ngx_http_secure_link_module.c +355 -0
- data/src/nginx/src/http/modules/ngx_http_split_clients_module.c +242 -0
- data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.c +2913 -0
- data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.h +114 -0
- data/src/nginx/src/http/modules/ngx_http_ssl_module.c +652 -0
- data/src/nginx/src/http/modules/ngx_http_ssl_module.h +52 -0
- data/src/nginx/src/http/modules/ngx_http_static_module.c +278 -0
- data/src/nginx/src/http/modules/ngx_http_stub_status_module.c +144 -0
- data/src/nginx/src/http/modules/ngx_http_sub_filter_module.c +716 -0
- data/src/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +237 -0
- data/src/nginx/src/http/modules/ngx_http_userid_filter_module.c +846 -0
- data/src/nginx/src/http/modules/ngx_http_uwsgi_module.c +1774 -0
- data/src/nginx/src/http/modules/ngx_http_xslt_filter_module.c +984 -0
- data/src/nginx/src/http/modules/perl/Makefile.PL +42 -0
- data/src/nginx/src/http/modules/perl/nginx.pm +137 -0
- data/src/nginx/src/http/modules/perl/nginx.xs +986 -0
- data/src/nginx/src/http/modules/perl/ngx_http_perl_module.c +1076 -0
- data/src/nginx/src/http/modules/perl/ngx_http_perl_module.h +67 -0
- data/src/nginx/src/http/modules/perl/typemap +3 -0
- data/src/nginx/src/http/ngx_http.c +2073 -0
- data/src/nginx/src/http/ngx_http.h +160 -0
- data/src/nginx/src/http/ngx_http_busy_lock.c +307 -0
- data/src/nginx/src/http/ngx_http_busy_lock.h +54 -0
- data/src/nginx/src/http/ngx_http_cache.h +148 -0
- data/src/nginx/src/http/ngx_http_config.h +75 -0
- data/src/nginx/src/http/ngx_http_copy_filter_module.c +300 -0
- data/src/nginx/src/http/ngx_http_core_module.c +4736 -0
- data/src/nginx/src/http/ngx_http_core_module.h +541 -0
- data/src/nginx/src/http/ngx_http_file_cache.c +1715 -0
- data/src/nginx/src/http/ngx_http_header_filter_module.c +623 -0
- data/src/nginx/src/http/ngx_http_parse.c +1734 -0
- data/src/nginx/src/http/ngx_http_parse_time.c +276 -0
- data/src/nginx/src/http/ngx_http_postpone_filter_module.c +178 -0
- data/src/nginx/src/http/ngx_http_request.c +3181 -0
- data/src/nginx/src/http/ngx_http_request.h +573 -0
- data/src/nginx/src/http/ngx_http_request_body.c +644 -0
- data/src/nginx/src/http/ngx_http_script.c +1752 -0
- data/src/nginx/src/http/ngx_http_script.h +257 -0
- data/src/nginx/src/http/ngx_http_special_response.c +789 -0
- data/src/nginx/src/http/ngx_http_upstream.c +4555 -0
- data/src/nginx/src/http/ngx_http_upstream.h +350 -0
- data/src/nginx/src/http/ngx_http_upstream_round_robin.c +791 -0
- data/src/nginx/src/http/ngx_http_upstream_round_robin.h +85 -0
- data/src/nginx/src/http/ngx_http_variables.c +2053 -0
- data/src/nginx/src/http/ngx_http_variables.h +115 -0
- data/src/nginx/src/http/ngx_http_write_filter_module.c +315 -0
- data/src/nginx/src/mail/ngx_mail.c +542 -0
- data/src/nginx/src/mail/ngx_mail.h +407 -0
- data/src/nginx/src/mail/ngx_mail_auth_http_module.c +1452 -0
- data/src/nginx/src/mail/ngx_mail_core_module.c +553 -0
- data/src/nginx/src/mail/ngx_mail_handler.c +773 -0
- data/src/nginx/src/mail/ngx_mail_imap_handler.c +457 -0
- data/src/nginx/src/mail/ngx_mail_imap_module.c +253 -0
- data/src/nginx/src/mail/ngx_mail_imap_module.h +39 -0
- data/src/nginx/src/mail/ngx_mail_parse.c +885 -0
- data/src/nginx/src/mail/ngx_mail_pop3_handler.c +500 -0
- data/src/nginx/src/mail/ngx_mail_pop3_module.c +264 -0
- data/src/nginx/src/mail/ngx_mail_pop3_module.h +38 -0
- data/src/nginx/src/mail/ngx_mail_proxy_module.c +1089 -0
- data/src/nginx/src/mail/ngx_mail_smtp_handler.c +872 -0
- data/src/nginx/src/mail/ngx_mail_smtp_module.c +308 -0
- data/src/nginx/src/mail/ngx_mail_smtp_module.h +45 -0
- data/src/nginx/src/mail/ngx_mail_ssl_module.c +491 -0
- data/src/nginx/src/mail/ngx_mail_ssl_module.h +52 -0
- data/src/nginx/src/misc/ngx_cpp_test_module.cpp +27 -0
- data/src/nginx/src/misc/ngx_google_perftools_module.c +126 -0
- data/src/nginx/src/os/unix/ngx_aio_read.c +109 -0
- data/src/nginx/src/os/unix/ngx_aio_read_chain.c +78 -0
- data/src/nginx/src/os/unix/ngx_aio_write.c +109 -0
- data/src/nginx/src/os/unix/ngx_aio_write_chain.c +100 -0
- data/src/nginx/src/os/unix/ngx_alloc.c +90 -0
- data/src/nginx/src/os/unix/ngx_alloc.h +45 -0
- data/src/nginx/src/os/unix/ngx_atomic.h +311 -0
- data/src/nginx/src/os/unix/ngx_channel.c +258 -0
- data/src/nginx/src/os/unix/ngx_channel.h +34 -0
- data/src/nginx/src/os/unix/ngx_daemon.c +69 -0
- data/src/nginx/src/os/unix/ngx_darwin.h +20 -0
- data/src/nginx/src/os/unix/ngx_darwin_config.h +96 -0
- data/src/nginx/src/os/unix/ngx_darwin_init.c +166 -0
- data/src/nginx/src/os/unix/ngx_darwin_sendfile_chain.c +366 -0
- data/src/nginx/src/os/unix/ngx_errno.c +87 -0
- data/src/nginx/src/os/unix/ngx_errno.h +68 -0
- data/src/nginx/src/os/unix/ngx_file_aio_read.c +208 -0
- data/src/nginx/src/os/unix/ngx_files.c +566 -0
- data/src/nginx/src/os/unix/ngx_files.h +343 -0
- data/src/nginx/src/os/unix/ngx_freebsd.h +24 -0
- data/src/nginx/src/os/unix/ngx_freebsd_config.h +119 -0
- data/src/nginx/src/os/unix/ngx_freebsd_init.c +259 -0
- data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.c +756 -0
- data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.h +122 -0
- data/src/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +436 -0
- data/src/nginx/src/os/unix/ngx_gcc_atomic_amd64.h +82 -0
- data/src/nginx/src/os/unix/ngx_gcc_atomic_ppc.h +155 -0
- data/src/nginx/src/os/unix/ngx_gcc_atomic_sparc64.h +82 -0
- data/src/nginx/src/os/unix/ngx_gcc_atomic_x86.h +127 -0
- data/src/nginx/src/os/unix/ngx_linux.h +18 -0
- data/src/nginx/src/os/unix/ngx_linux_aio_read.c +137 -0
- data/src/nginx/src/os/unix/ngx_linux_config.h +117 -0
- data/src/nginx/src/os/unix/ngx_linux_init.c +91 -0
- data/src/nginx/src/os/unix/ngx_linux_sendfile_chain.c +378 -0
- data/src/nginx/src/os/unix/ngx_os.h +84 -0
- data/src/nginx/src/os/unix/ngx_posix_config.h +153 -0
- data/src/nginx/src/os/unix/ngx_posix_init.c +124 -0
- data/src/nginx/src/os/unix/ngx_process.c +590 -0
- data/src/nginx/src/os/unix/ngx_process.h +87 -0
- data/src/nginx/src/os/unix/ngx_process_cycle.c +1390 -0
- data/src/nginx/src/os/unix/ngx_process_cycle.h +61 -0
- data/src/nginx/src/os/unix/ngx_pthread_thread.c +278 -0
- data/src/nginx/src/os/unix/ngx_readv_chain.c +258 -0
- data/src/nginx/src/os/unix/ngx_recv.c +180 -0
- data/src/nginx/src/os/unix/ngx_send.c +73 -0
- data/src/nginx/src/os/unix/ngx_setproctitle.c +135 -0
- data/src/nginx/src/os/unix/ngx_setproctitle.h +52 -0
- data/src/nginx/src/os/unix/ngx_shmem.c +126 -0
- data/src/nginx/src/os/unix/ngx_shmem.h +29 -0
- data/src/nginx/src/os/unix/ngx_socket.c +116 -0
- data/src/nginx/src/os/unix/ngx_socket.h +64 -0
- data/src/nginx/src/os/unix/ngx_solaris.h +16 -0
- data/src/nginx/src/os/unix/ngx_solaris_config.h +107 -0
- data/src/nginx/src/os/unix/ngx_solaris_init.c +75 -0
- data/src/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +251 -0
- data/src/nginx/src/os/unix/ngx_sunpro_amd64.il +43 -0
- data/src/nginx/src/os/unix/ngx_sunpro_atomic_sparc64.h +61 -0
- data/src/nginx/src/os/unix/ngx_sunpro_sparc64.il +36 -0
- data/src/nginx/src/os/unix/ngx_sunpro_x86.il +44 -0
- data/src/nginx/src/os/unix/ngx_thread.h +128 -0
- data/src/nginx/src/os/unix/ngx_time.c +104 -0
- data/src/nginx/src/os/unix/ngx_time.h +66 -0
- data/src/nginx/src/os/unix/ngx_udp_recv.c +115 -0
- data/src/nginx/src/os/unix/ngx_user.c +109 -0
- data/src/nginx/src/os/unix/ngx_user.h +24 -0
- data/src/nginx/src/os/unix/ngx_writev_chain.c +181 -0
- data/src/nginx/src/os/unix/rfork_thread.S +73 -0
- metadata +419 -0
@@ -0,0 +1,1206 @@
|
|
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
|
+
#include <zlib.h>
|
13
|
+
|
14
|
+
|
15
|
+
typedef struct {
|
16
|
+
ngx_flag_t enable;
|
17
|
+
ngx_flag_t no_buffer;
|
18
|
+
|
19
|
+
ngx_hash_t types;
|
20
|
+
|
21
|
+
ngx_bufs_t bufs;
|
22
|
+
|
23
|
+
size_t postpone_gzipping;
|
24
|
+
ngx_int_t level;
|
25
|
+
size_t wbits;
|
26
|
+
size_t memlevel;
|
27
|
+
ssize_t min_length;
|
28
|
+
|
29
|
+
ngx_array_t *types_keys;
|
30
|
+
} ngx_http_gzip_conf_t;
|
31
|
+
|
32
|
+
|
33
|
+
typedef struct {
|
34
|
+
ngx_chain_t *in;
|
35
|
+
ngx_chain_t *free;
|
36
|
+
ngx_chain_t *busy;
|
37
|
+
ngx_chain_t *out;
|
38
|
+
ngx_chain_t **last_out;
|
39
|
+
|
40
|
+
ngx_chain_t *copied;
|
41
|
+
ngx_chain_t *copy_buf;
|
42
|
+
|
43
|
+
ngx_buf_t *in_buf;
|
44
|
+
ngx_buf_t *out_buf;
|
45
|
+
ngx_int_t bufs;
|
46
|
+
|
47
|
+
void *preallocated;
|
48
|
+
char *free_mem;
|
49
|
+
ngx_uint_t allocated;
|
50
|
+
|
51
|
+
int wbits;
|
52
|
+
int memlevel;
|
53
|
+
|
54
|
+
unsigned flush:4;
|
55
|
+
unsigned redo:1;
|
56
|
+
unsigned done:1;
|
57
|
+
unsigned nomem:1;
|
58
|
+
unsigned gzheader:1;
|
59
|
+
unsigned buffering:1;
|
60
|
+
|
61
|
+
size_t zin;
|
62
|
+
size_t zout;
|
63
|
+
|
64
|
+
uint32_t crc32;
|
65
|
+
z_stream zstream;
|
66
|
+
ngx_http_request_t *request;
|
67
|
+
} ngx_http_gzip_ctx_t;
|
68
|
+
|
69
|
+
|
70
|
+
#if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
|
71
|
+
|
72
|
+
struct gztrailer {
|
73
|
+
uint32_t crc32;
|
74
|
+
uint32_t zlen;
|
75
|
+
};
|
76
|
+
|
77
|
+
#else /* NGX_HAVE_BIG_ENDIAN || !NGX_HAVE_NONALIGNED */
|
78
|
+
|
79
|
+
struct gztrailer {
|
80
|
+
u_char crc32[4];
|
81
|
+
u_char zlen[4];
|
82
|
+
};
|
83
|
+
|
84
|
+
#endif
|
85
|
+
|
86
|
+
|
87
|
+
static void ngx_http_gzip_filter_memory(ngx_http_request_t *r,
|
88
|
+
ngx_http_gzip_ctx_t *ctx);
|
89
|
+
static ngx_int_t ngx_http_gzip_filter_buffer(ngx_http_gzip_ctx_t *ctx,
|
90
|
+
ngx_chain_t *in);
|
91
|
+
static ngx_int_t ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r,
|
92
|
+
ngx_http_gzip_ctx_t *ctx);
|
93
|
+
static ngx_int_t ngx_http_gzip_filter_gzheader(ngx_http_request_t *r,
|
94
|
+
ngx_http_gzip_ctx_t *ctx);
|
95
|
+
static ngx_int_t ngx_http_gzip_filter_add_data(ngx_http_request_t *r,
|
96
|
+
ngx_http_gzip_ctx_t *ctx);
|
97
|
+
static ngx_int_t ngx_http_gzip_filter_get_buf(ngx_http_request_t *r,
|
98
|
+
ngx_http_gzip_ctx_t *ctx);
|
99
|
+
static ngx_int_t ngx_http_gzip_filter_deflate(ngx_http_request_t *r,
|
100
|
+
ngx_http_gzip_ctx_t *ctx);
|
101
|
+
static ngx_int_t ngx_http_gzip_filter_deflate_end(ngx_http_request_t *r,
|
102
|
+
ngx_http_gzip_ctx_t *ctx);
|
103
|
+
|
104
|
+
static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items,
|
105
|
+
u_int size);
|
106
|
+
static void ngx_http_gzip_filter_free(void *opaque, void *address);
|
107
|
+
static void ngx_http_gzip_filter_free_copy_buf(ngx_http_request_t *r,
|
108
|
+
ngx_http_gzip_ctx_t *ctx);
|
109
|
+
|
110
|
+
static ngx_int_t ngx_http_gzip_add_variables(ngx_conf_t *cf);
|
111
|
+
static ngx_int_t ngx_http_gzip_ratio_variable(ngx_http_request_t *r,
|
112
|
+
ngx_http_variable_value_t *v, uintptr_t data);
|
113
|
+
|
114
|
+
static ngx_int_t ngx_http_gzip_filter_init(ngx_conf_t *cf);
|
115
|
+
static void *ngx_http_gzip_create_conf(ngx_conf_t *cf);
|
116
|
+
static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf,
|
117
|
+
void *parent, void *child);
|
118
|
+
static char *ngx_http_gzip_window(ngx_conf_t *cf, void *post, void *data);
|
119
|
+
static char *ngx_http_gzip_hash(ngx_conf_t *cf, void *post, void *data);
|
120
|
+
|
121
|
+
|
122
|
+
static ngx_conf_num_bounds_t ngx_http_gzip_comp_level_bounds = {
|
123
|
+
ngx_conf_check_num_bounds, 1, 9
|
124
|
+
};
|
125
|
+
|
126
|
+
static ngx_conf_post_handler_pt ngx_http_gzip_window_p = ngx_http_gzip_window;
|
127
|
+
static ngx_conf_post_handler_pt ngx_http_gzip_hash_p = ngx_http_gzip_hash;
|
128
|
+
|
129
|
+
|
130
|
+
static ngx_command_t ngx_http_gzip_filter_commands[] = {
|
131
|
+
|
132
|
+
{ ngx_string("gzip"),
|
133
|
+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
134
|
+
|NGX_CONF_FLAG,
|
135
|
+
ngx_conf_set_flag_slot,
|
136
|
+
NGX_HTTP_LOC_CONF_OFFSET,
|
137
|
+
offsetof(ngx_http_gzip_conf_t, enable),
|
138
|
+
NULL },
|
139
|
+
|
140
|
+
{ ngx_string("gzip_buffers"),
|
141
|
+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
|
142
|
+
ngx_conf_set_bufs_slot,
|
143
|
+
NGX_HTTP_LOC_CONF_OFFSET,
|
144
|
+
offsetof(ngx_http_gzip_conf_t, bufs),
|
145
|
+
NULL },
|
146
|
+
|
147
|
+
{ ngx_string("gzip_types"),
|
148
|
+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
149
|
+
ngx_http_types_slot,
|
150
|
+
NGX_HTTP_LOC_CONF_OFFSET,
|
151
|
+
offsetof(ngx_http_gzip_conf_t, types_keys),
|
152
|
+
&ngx_http_html_default_types[0] },
|
153
|
+
|
154
|
+
{ ngx_string("gzip_comp_level"),
|
155
|
+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
156
|
+
ngx_conf_set_num_slot,
|
157
|
+
NGX_HTTP_LOC_CONF_OFFSET,
|
158
|
+
offsetof(ngx_http_gzip_conf_t, level),
|
159
|
+
&ngx_http_gzip_comp_level_bounds },
|
160
|
+
|
161
|
+
{ ngx_string("gzip_window"),
|
162
|
+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
163
|
+
ngx_conf_set_size_slot,
|
164
|
+
NGX_HTTP_LOC_CONF_OFFSET,
|
165
|
+
offsetof(ngx_http_gzip_conf_t, wbits),
|
166
|
+
&ngx_http_gzip_window_p },
|
167
|
+
|
168
|
+
{ ngx_string("gzip_hash"),
|
169
|
+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
170
|
+
ngx_conf_set_size_slot,
|
171
|
+
NGX_HTTP_LOC_CONF_OFFSET,
|
172
|
+
offsetof(ngx_http_gzip_conf_t, memlevel),
|
173
|
+
&ngx_http_gzip_hash_p },
|
174
|
+
|
175
|
+
{ ngx_string("postpone_gzipping"),
|
176
|
+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
177
|
+
ngx_conf_set_size_slot,
|
178
|
+
NGX_HTTP_LOC_CONF_OFFSET,
|
179
|
+
offsetof(ngx_http_gzip_conf_t, postpone_gzipping),
|
180
|
+
NULL },
|
181
|
+
|
182
|
+
{ ngx_string("gzip_no_buffer"),
|
183
|
+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
184
|
+
ngx_conf_set_flag_slot,
|
185
|
+
NGX_HTTP_LOC_CONF_OFFSET,
|
186
|
+
offsetof(ngx_http_gzip_conf_t, no_buffer),
|
187
|
+
NULL },
|
188
|
+
|
189
|
+
{ ngx_string("gzip_min_length"),
|
190
|
+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
191
|
+
ngx_conf_set_size_slot,
|
192
|
+
NGX_HTTP_LOC_CONF_OFFSET,
|
193
|
+
offsetof(ngx_http_gzip_conf_t, min_length),
|
194
|
+
NULL },
|
195
|
+
|
196
|
+
ngx_null_command
|
197
|
+
};
|
198
|
+
|
199
|
+
|
200
|
+
static ngx_http_module_t ngx_http_gzip_filter_module_ctx = {
|
201
|
+
ngx_http_gzip_add_variables, /* preconfiguration */
|
202
|
+
ngx_http_gzip_filter_init, /* postconfiguration */
|
203
|
+
|
204
|
+
NULL, /* create main configuration */
|
205
|
+
NULL, /* init main configuration */
|
206
|
+
|
207
|
+
NULL, /* create server configuration */
|
208
|
+
NULL, /* merge server configuration */
|
209
|
+
|
210
|
+
ngx_http_gzip_create_conf, /* create location configuration */
|
211
|
+
ngx_http_gzip_merge_conf /* merge location configuration */
|
212
|
+
};
|
213
|
+
|
214
|
+
|
215
|
+
ngx_module_t ngx_http_gzip_filter_module = {
|
216
|
+
NGX_MODULE_V1,
|
217
|
+
&ngx_http_gzip_filter_module_ctx, /* module context */
|
218
|
+
ngx_http_gzip_filter_commands, /* module directives */
|
219
|
+
NGX_HTTP_MODULE, /* module type */
|
220
|
+
NULL, /* init master */
|
221
|
+
NULL, /* init module */
|
222
|
+
NULL, /* init process */
|
223
|
+
NULL, /* init thread */
|
224
|
+
NULL, /* exit thread */
|
225
|
+
NULL, /* exit process */
|
226
|
+
NULL, /* exit master */
|
227
|
+
NGX_MODULE_V1_PADDING
|
228
|
+
};
|
229
|
+
|
230
|
+
|
231
|
+
static ngx_str_t ngx_http_gzip_ratio = ngx_string("gzip_ratio");
|
232
|
+
|
233
|
+
static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
|
234
|
+
static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
|
235
|
+
|
236
|
+
|
237
|
+
static ngx_int_t
|
238
|
+
ngx_http_gzip_header_filter(ngx_http_request_t *r)
|
239
|
+
{
|
240
|
+
ngx_table_elt_t *h;
|
241
|
+
ngx_http_gzip_ctx_t *ctx;
|
242
|
+
ngx_http_gzip_conf_t *conf;
|
243
|
+
|
244
|
+
conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
|
245
|
+
|
246
|
+
if (!conf->enable
|
247
|
+
|| (r->headers_out.status != NGX_HTTP_OK
|
248
|
+
&& r->headers_out.status != NGX_HTTP_FORBIDDEN
|
249
|
+
&& r->headers_out.status != NGX_HTTP_NOT_FOUND)
|
250
|
+
|| (r->headers_out.content_encoding
|
251
|
+
&& r->headers_out.content_encoding->value.len)
|
252
|
+
|| (r->headers_out.content_length_n != -1
|
253
|
+
&& r->headers_out.content_length_n < conf->min_length)
|
254
|
+
|| ngx_http_test_content_type(r, &conf->types) == NULL
|
255
|
+
|| r->header_only)
|
256
|
+
{
|
257
|
+
return ngx_http_next_header_filter(r);
|
258
|
+
}
|
259
|
+
|
260
|
+
r->gzip_vary = 1;
|
261
|
+
|
262
|
+
#if (NGX_HTTP_DEGRADATION)
|
263
|
+
{
|
264
|
+
ngx_http_core_loc_conf_t *clcf;
|
265
|
+
|
266
|
+
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
267
|
+
|
268
|
+
if (clcf->gzip_disable_degradation && ngx_http_degraded(r)) {
|
269
|
+
return ngx_http_next_header_filter(r);
|
270
|
+
}
|
271
|
+
}
|
272
|
+
#endif
|
273
|
+
|
274
|
+
if (!r->gzip_tested) {
|
275
|
+
if (ngx_http_gzip_ok(r) != NGX_OK) {
|
276
|
+
return ngx_http_next_header_filter(r);
|
277
|
+
}
|
278
|
+
|
279
|
+
} else if (!r->gzip_ok) {
|
280
|
+
return ngx_http_next_header_filter(r);
|
281
|
+
}
|
282
|
+
|
283
|
+
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_gzip_ctx_t));
|
284
|
+
if (ctx == NULL) {
|
285
|
+
return NGX_ERROR;
|
286
|
+
}
|
287
|
+
|
288
|
+
ngx_http_set_ctx(r, ctx, ngx_http_gzip_filter_module);
|
289
|
+
|
290
|
+
ctx->request = r;
|
291
|
+
ctx->buffering = (conf->postpone_gzipping != 0);
|
292
|
+
|
293
|
+
ngx_http_gzip_filter_memory(r, ctx);
|
294
|
+
|
295
|
+
h = ngx_list_push(&r->headers_out.headers);
|
296
|
+
if (h == NULL) {
|
297
|
+
return NGX_ERROR;
|
298
|
+
}
|
299
|
+
|
300
|
+
h->hash = 1;
|
301
|
+
ngx_str_set(&h->key, "Content-Encoding");
|
302
|
+
ngx_str_set(&h->value, "gzip");
|
303
|
+
r->headers_out.content_encoding = h;
|
304
|
+
|
305
|
+
r->main_filter_need_in_memory = 1;
|
306
|
+
|
307
|
+
ngx_http_clear_content_length(r);
|
308
|
+
ngx_http_clear_accept_ranges(r);
|
309
|
+
|
310
|
+
return ngx_http_next_header_filter(r);
|
311
|
+
}
|
312
|
+
|
313
|
+
|
314
|
+
static ngx_int_t
|
315
|
+
ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
316
|
+
{
|
317
|
+
int rc;
|
318
|
+
ngx_chain_t *cl;
|
319
|
+
ngx_http_gzip_ctx_t *ctx;
|
320
|
+
|
321
|
+
ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module);
|
322
|
+
|
323
|
+
if (ctx == NULL || ctx->done) {
|
324
|
+
return ngx_http_next_body_filter(r, in);
|
325
|
+
}
|
326
|
+
|
327
|
+
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
328
|
+
"http gzip filter");
|
329
|
+
|
330
|
+
if (ctx->buffering) {
|
331
|
+
|
332
|
+
/*
|
333
|
+
* With default memory settings zlib starts to output gzipped data
|
334
|
+
* only after it has got about 90K, so it makes sense to allocate
|
335
|
+
* zlib memory (200-400K) only after we have enough data to compress.
|
336
|
+
* Although we copy buffers, nevertheless for not big responses
|
337
|
+
* this allows to allocate zlib memory, to compress and to output
|
338
|
+
* the response in one step using hot CPU cache.
|
339
|
+
*/
|
340
|
+
|
341
|
+
if (in) {
|
342
|
+
switch (ngx_http_gzip_filter_buffer(ctx, in)) {
|
343
|
+
|
344
|
+
case NGX_OK:
|
345
|
+
return NGX_OK;
|
346
|
+
|
347
|
+
case NGX_DONE:
|
348
|
+
in = NULL;
|
349
|
+
break;
|
350
|
+
|
351
|
+
default: /* NGX_ERROR */
|
352
|
+
goto failed;
|
353
|
+
}
|
354
|
+
|
355
|
+
} else {
|
356
|
+
ctx->buffering = 0;
|
357
|
+
}
|
358
|
+
}
|
359
|
+
|
360
|
+
if (ctx->preallocated == NULL) {
|
361
|
+
if (ngx_http_gzip_filter_deflate_start(r, ctx) != NGX_OK) {
|
362
|
+
goto failed;
|
363
|
+
}
|
364
|
+
}
|
365
|
+
|
366
|
+
if (in) {
|
367
|
+
if (ngx_chain_add_copy(r->pool, &ctx->in, in) != NGX_OK) {
|
368
|
+
goto failed;
|
369
|
+
}
|
370
|
+
}
|
371
|
+
|
372
|
+
if (ctx->nomem) {
|
373
|
+
|
374
|
+
/* flush busy buffers */
|
375
|
+
|
376
|
+
if (ngx_http_next_body_filter(r, NULL) == NGX_ERROR) {
|
377
|
+
goto failed;
|
378
|
+
}
|
379
|
+
|
380
|
+
cl = NULL;
|
381
|
+
|
382
|
+
ngx_chain_update_chains(&ctx->free, &ctx->busy, &cl,
|
383
|
+
(ngx_buf_tag_t) &ngx_http_gzip_filter_module);
|
384
|
+
ctx->nomem = 0;
|
385
|
+
}
|
386
|
+
|
387
|
+
for ( ;; ) {
|
388
|
+
|
389
|
+
/* cycle while we can write to a client */
|
390
|
+
|
391
|
+
for ( ;; ) {
|
392
|
+
|
393
|
+
/* cycle while there is data to feed zlib and ... */
|
394
|
+
|
395
|
+
rc = ngx_http_gzip_filter_add_data(r, ctx);
|
396
|
+
|
397
|
+
if (rc == NGX_DECLINED) {
|
398
|
+
break;
|
399
|
+
}
|
400
|
+
|
401
|
+
if (rc == NGX_AGAIN) {
|
402
|
+
continue;
|
403
|
+
}
|
404
|
+
|
405
|
+
|
406
|
+
/* ... there are buffers to write zlib output */
|
407
|
+
|
408
|
+
rc = ngx_http_gzip_filter_get_buf(r, ctx);
|
409
|
+
|
410
|
+
if (rc == NGX_DECLINED) {
|
411
|
+
break;
|
412
|
+
}
|
413
|
+
|
414
|
+
if (rc == NGX_ERROR) {
|
415
|
+
goto failed;
|
416
|
+
}
|
417
|
+
|
418
|
+
|
419
|
+
rc = ngx_http_gzip_filter_deflate(r, ctx);
|
420
|
+
|
421
|
+
if (rc == NGX_OK) {
|
422
|
+
break;
|
423
|
+
}
|
424
|
+
|
425
|
+
if (rc == NGX_ERROR) {
|
426
|
+
goto failed;
|
427
|
+
}
|
428
|
+
|
429
|
+
/* rc == NGX_AGAIN */
|
430
|
+
}
|
431
|
+
|
432
|
+
if (ctx->out == NULL) {
|
433
|
+
ngx_http_gzip_filter_free_copy_buf(r, ctx);
|
434
|
+
|
435
|
+
return ctx->busy ? NGX_AGAIN : NGX_OK;
|
436
|
+
}
|
437
|
+
|
438
|
+
if (!ctx->gzheader) {
|
439
|
+
if (ngx_http_gzip_filter_gzheader(r, ctx) != NGX_OK) {
|
440
|
+
goto failed;
|
441
|
+
}
|
442
|
+
}
|
443
|
+
|
444
|
+
rc = ngx_http_next_body_filter(r, ctx->out);
|
445
|
+
|
446
|
+
if (rc == NGX_ERROR) {
|
447
|
+
goto failed;
|
448
|
+
}
|
449
|
+
|
450
|
+
ngx_http_gzip_filter_free_copy_buf(r, ctx);
|
451
|
+
|
452
|
+
ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out,
|
453
|
+
(ngx_buf_tag_t) &ngx_http_gzip_filter_module);
|
454
|
+
ctx->last_out = &ctx->out;
|
455
|
+
|
456
|
+
ctx->nomem = 0;
|
457
|
+
|
458
|
+
if (ctx->done) {
|
459
|
+
return rc;
|
460
|
+
}
|
461
|
+
}
|
462
|
+
|
463
|
+
/* unreachable */
|
464
|
+
|
465
|
+
failed:
|
466
|
+
|
467
|
+
ctx->done = 1;
|
468
|
+
|
469
|
+
if (ctx->preallocated) {
|
470
|
+
deflateEnd(&ctx->zstream);
|
471
|
+
|
472
|
+
ngx_pfree(r->pool, ctx->preallocated);
|
473
|
+
}
|
474
|
+
|
475
|
+
ngx_http_gzip_filter_free_copy_buf(r, ctx);
|
476
|
+
|
477
|
+
return NGX_ERROR;
|
478
|
+
}
|
479
|
+
|
480
|
+
|
481
|
+
static void
|
482
|
+
ngx_http_gzip_filter_memory(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
|
483
|
+
{
|
484
|
+
int wbits, memlevel;
|
485
|
+
ngx_http_gzip_conf_t *conf;
|
486
|
+
|
487
|
+
conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
|
488
|
+
|
489
|
+
wbits = conf->wbits;
|
490
|
+
memlevel = conf->memlevel;
|
491
|
+
|
492
|
+
if (r->headers_out.content_length_n > 0) {
|
493
|
+
|
494
|
+
/* the actual zlib window size is smaller by 262 bytes */
|
495
|
+
|
496
|
+
while (r->headers_out.content_length_n < ((1 << (wbits - 1)) - 262)) {
|
497
|
+
wbits--;
|
498
|
+
memlevel--;
|
499
|
+
}
|
500
|
+
}
|
501
|
+
|
502
|
+
ctx->wbits = wbits;
|
503
|
+
ctx->memlevel = memlevel;
|
504
|
+
|
505
|
+
/*
|
506
|
+
* We preallocate a memory for zlib in one buffer (200K-400K), this
|
507
|
+
* decreases a number of malloc() and free() calls and also probably
|
508
|
+
* decreases a number of syscalls (sbrk()/mmap() and so on).
|
509
|
+
* Besides we free the memory as soon as a gzipping will complete
|
510
|
+
* and do not wait while a whole response will be sent to a client.
|
511
|
+
*
|
512
|
+
* 8K is for zlib deflate_state, it takes
|
513
|
+
* *) 5816 bytes on i386 and sparc64 (32-bit mode)
|
514
|
+
* *) 5920 bytes on amd64 and sparc64
|
515
|
+
*/
|
516
|
+
|
517
|
+
ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9));
|
518
|
+
}
|
519
|
+
|
520
|
+
|
521
|
+
static ngx_int_t
|
522
|
+
ngx_http_gzip_filter_buffer(ngx_http_gzip_ctx_t *ctx, ngx_chain_t *in)
|
523
|
+
{
|
524
|
+
size_t size, buffered;
|
525
|
+
ngx_buf_t *b, *buf;
|
526
|
+
ngx_chain_t *cl, **ll;
|
527
|
+
ngx_http_request_t *r;
|
528
|
+
ngx_http_gzip_conf_t *conf;
|
529
|
+
|
530
|
+
r = ctx->request;
|
531
|
+
|
532
|
+
r->connection->buffered |= NGX_HTTP_GZIP_BUFFERED;
|
533
|
+
|
534
|
+
buffered = 0;
|
535
|
+
ll = &ctx->in;
|
536
|
+
|
537
|
+
for (cl = ctx->in; cl; cl = cl->next) {
|
538
|
+
buffered += cl->buf->last - cl->buf->pos;
|
539
|
+
ll = &cl->next;
|
540
|
+
}
|
541
|
+
|
542
|
+
conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
|
543
|
+
|
544
|
+
while (in) {
|
545
|
+
cl = ngx_alloc_chain_link(r->pool);
|
546
|
+
if (cl == NULL) {
|
547
|
+
return NGX_ERROR;
|
548
|
+
}
|
549
|
+
|
550
|
+
b = in->buf;
|
551
|
+
|
552
|
+
size = b->last - b->pos;
|
553
|
+
buffered += size;
|
554
|
+
|
555
|
+
if (b->flush || b->last_buf || buffered > conf->postpone_gzipping) {
|
556
|
+
ctx->buffering = 0;
|
557
|
+
}
|
558
|
+
|
559
|
+
if (ctx->buffering && size) {
|
560
|
+
|
561
|
+
buf = ngx_create_temp_buf(r->pool, size);
|
562
|
+
if (buf == NULL) {
|
563
|
+
return NGX_ERROR;
|
564
|
+
}
|
565
|
+
|
566
|
+
buf->last = ngx_cpymem(buf->pos, b->pos, size);
|
567
|
+
b->pos = b->last;
|
568
|
+
|
569
|
+
buf->last_buf = b->last_buf;
|
570
|
+
buf->tag = (ngx_buf_tag_t) &ngx_http_gzip_filter_module;
|
571
|
+
|
572
|
+
cl->buf = buf;
|
573
|
+
|
574
|
+
} else {
|
575
|
+
cl->buf = b;
|
576
|
+
}
|
577
|
+
|
578
|
+
*ll = cl;
|
579
|
+
ll = &cl->next;
|
580
|
+
in = in->next;
|
581
|
+
}
|
582
|
+
|
583
|
+
*ll = NULL;
|
584
|
+
|
585
|
+
return ctx->buffering ? NGX_OK : NGX_DONE;
|
586
|
+
}
|
587
|
+
|
588
|
+
|
589
|
+
static ngx_int_t
|
590
|
+
ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r,
|
591
|
+
ngx_http_gzip_ctx_t *ctx)
|
592
|
+
{
|
593
|
+
int rc;
|
594
|
+
ngx_http_gzip_conf_t *conf;
|
595
|
+
|
596
|
+
conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
|
597
|
+
|
598
|
+
ctx->preallocated = ngx_palloc(r->pool, ctx->allocated);
|
599
|
+
if (ctx->preallocated == NULL) {
|
600
|
+
return NGX_ERROR;
|
601
|
+
}
|
602
|
+
|
603
|
+
ctx->free_mem = ctx->preallocated;
|
604
|
+
|
605
|
+
ctx->zstream.zalloc = ngx_http_gzip_filter_alloc;
|
606
|
+
ctx->zstream.zfree = ngx_http_gzip_filter_free;
|
607
|
+
ctx->zstream.opaque = ctx;
|
608
|
+
|
609
|
+
rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED,
|
610
|
+
- ctx->wbits, ctx->memlevel, Z_DEFAULT_STRATEGY);
|
611
|
+
|
612
|
+
if (rc != Z_OK) {
|
613
|
+
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
614
|
+
"deflateInit2() failed: %d", rc);
|
615
|
+
return NGX_ERROR;
|
616
|
+
}
|
617
|
+
|
618
|
+
ctx->last_out = &ctx->out;
|
619
|
+
ctx->crc32 = crc32(0L, Z_NULL, 0);
|
620
|
+
ctx->flush = Z_NO_FLUSH;
|
621
|
+
|
622
|
+
return NGX_OK;
|
623
|
+
}
|
624
|
+
|
625
|
+
|
626
|
+
static ngx_int_t
|
627
|
+
ngx_http_gzip_filter_gzheader(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
|
628
|
+
{
|
629
|
+
ngx_buf_t *b;
|
630
|
+
ngx_chain_t *cl;
|
631
|
+
static u_char gzheader[10] =
|
632
|
+
{ 0x1f, 0x8b, Z_DEFLATED, 0, 0, 0, 0, 0, 0, 3 };
|
633
|
+
|
634
|
+
b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
|
635
|
+
if (b == NULL) {
|
636
|
+
return NGX_ERROR;
|
637
|
+
}
|
638
|
+
|
639
|
+
b->memory = 1;
|
640
|
+
b->pos = gzheader;
|
641
|
+
b->last = b->pos + 10;
|
642
|
+
|
643
|
+
cl = ngx_alloc_chain_link(r->pool);
|
644
|
+
if (cl == NULL) {
|
645
|
+
return NGX_ERROR;
|
646
|
+
}
|
647
|
+
|
648
|
+
cl->buf = b;
|
649
|
+
cl->next = ctx->out;
|
650
|
+
ctx->out = cl;
|
651
|
+
|
652
|
+
ctx->gzheader = 1;
|
653
|
+
|
654
|
+
return NGX_OK;
|
655
|
+
}
|
656
|
+
|
657
|
+
|
658
|
+
static ngx_int_t
|
659
|
+
ngx_http_gzip_filter_add_data(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
|
660
|
+
{
|
661
|
+
if (ctx->zstream.avail_in || ctx->flush != Z_NO_FLUSH || ctx->redo) {
|
662
|
+
return NGX_OK;
|
663
|
+
}
|
664
|
+
|
665
|
+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
666
|
+
"gzip in: %p", ctx->in);
|
667
|
+
|
668
|
+
if (ctx->in == NULL) {
|
669
|
+
return NGX_DECLINED;
|
670
|
+
}
|
671
|
+
|
672
|
+
if (ctx->copy_buf) {
|
673
|
+
|
674
|
+
/*
|
675
|
+
* to avoid CPU cache trashing we do not free() just quit buf,
|
676
|
+
* but postpone free()ing after zlib compressing and data output
|
677
|
+
*/
|
678
|
+
|
679
|
+
ctx->copy_buf->next = ctx->copied;
|
680
|
+
ctx->copied = ctx->copy_buf;
|
681
|
+
ctx->copy_buf = NULL;
|
682
|
+
}
|
683
|
+
|
684
|
+
ctx->in_buf = ctx->in->buf;
|
685
|
+
|
686
|
+
if (ctx->in_buf->tag == (ngx_buf_tag_t) &ngx_http_gzip_filter_module) {
|
687
|
+
ctx->copy_buf = ctx->in;
|
688
|
+
}
|
689
|
+
|
690
|
+
ctx->in = ctx->in->next;
|
691
|
+
|
692
|
+
ctx->zstream.next_in = ctx->in_buf->pos;
|
693
|
+
ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos;
|
694
|
+
|
695
|
+
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
696
|
+
"gzip in_buf:%p ni:%p ai:%ud",
|
697
|
+
ctx->in_buf,
|
698
|
+
ctx->zstream.next_in, ctx->zstream.avail_in);
|
699
|
+
|
700
|
+
if (ctx->in_buf->last_buf) {
|
701
|
+
ctx->flush = Z_FINISH;
|
702
|
+
|
703
|
+
} else if (ctx->in_buf->flush) {
|
704
|
+
ctx->flush = Z_SYNC_FLUSH;
|
705
|
+
}
|
706
|
+
|
707
|
+
if (ctx->zstream.avail_in) {
|
708
|
+
|
709
|
+
ctx->crc32 = crc32(ctx->crc32, ctx->zstream.next_in,
|
710
|
+
ctx->zstream.avail_in);
|
711
|
+
|
712
|
+
} else if (ctx->flush == Z_NO_FLUSH) {
|
713
|
+
return NGX_AGAIN;
|
714
|
+
}
|
715
|
+
|
716
|
+
return NGX_OK;
|
717
|
+
}
|
718
|
+
|
719
|
+
|
720
|
+
static ngx_int_t
|
721
|
+
ngx_http_gzip_filter_get_buf(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
|
722
|
+
{
|
723
|
+
ngx_http_gzip_conf_t *conf;
|
724
|
+
|
725
|
+
if (ctx->zstream.avail_out) {
|
726
|
+
return NGX_OK;
|
727
|
+
}
|
728
|
+
|
729
|
+
conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
|
730
|
+
|
731
|
+
if (ctx->free) {
|
732
|
+
ctx->out_buf = ctx->free->buf;
|
733
|
+
ctx->free = ctx->free->next;
|
734
|
+
|
735
|
+
} else if (ctx->bufs < conf->bufs.num) {
|
736
|
+
|
737
|
+
ctx->out_buf = ngx_create_temp_buf(r->pool, conf->bufs.size);
|
738
|
+
if (ctx->out_buf == NULL) {
|
739
|
+
return NGX_ERROR;
|
740
|
+
}
|
741
|
+
|
742
|
+
ctx->out_buf->tag = (ngx_buf_tag_t) &ngx_http_gzip_filter_module;
|
743
|
+
ctx->out_buf->recycled = 1;
|
744
|
+
ctx->bufs++;
|
745
|
+
|
746
|
+
} else {
|
747
|
+
ctx->nomem = 1;
|
748
|
+
return NGX_DECLINED;
|
749
|
+
}
|
750
|
+
|
751
|
+
ctx->zstream.next_out = ctx->out_buf->pos;
|
752
|
+
ctx->zstream.avail_out = conf->bufs.size;
|
753
|
+
|
754
|
+
return NGX_OK;
|
755
|
+
}
|
756
|
+
|
757
|
+
|
758
|
+
static ngx_int_t
|
759
|
+
ngx_http_gzip_filter_deflate(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
|
760
|
+
{
|
761
|
+
int rc;
|
762
|
+
ngx_chain_t *cl;
|
763
|
+
ngx_http_gzip_conf_t *conf;
|
764
|
+
|
765
|
+
ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
766
|
+
"deflate in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d",
|
767
|
+
ctx->zstream.next_in, ctx->zstream.next_out,
|
768
|
+
ctx->zstream.avail_in, ctx->zstream.avail_out,
|
769
|
+
ctx->flush, ctx->redo);
|
770
|
+
|
771
|
+
rc = deflate(&ctx->zstream, ctx->flush);
|
772
|
+
|
773
|
+
if (rc != Z_OK && rc != Z_STREAM_END) {
|
774
|
+
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
775
|
+
"deflate() failed: %d, %d", ctx->flush, rc);
|
776
|
+
return NGX_ERROR;
|
777
|
+
}
|
778
|
+
|
779
|
+
ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
780
|
+
"deflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d",
|
781
|
+
ctx->zstream.next_in, ctx->zstream.next_out,
|
782
|
+
ctx->zstream.avail_in, ctx->zstream.avail_out,
|
783
|
+
rc);
|
784
|
+
|
785
|
+
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
786
|
+
"gzip in_buf:%p pos:%p",
|
787
|
+
ctx->in_buf, ctx->in_buf->pos);
|
788
|
+
|
789
|
+
if (ctx->zstream.next_in) {
|
790
|
+
ctx->in_buf->pos = ctx->zstream.next_in;
|
791
|
+
|
792
|
+
if (ctx->zstream.avail_in == 0) {
|
793
|
+
ctx->zstream.next_in = NULL;
|
794
|
+
}
|
795
|
+
}
|
796
|
+
|
797
|
+
ctx->out_buf->last = ctx->zstream.next_out;
|
798
|
+
|
799
|
+
if (ctx->zstream.avail_out == 0) {
|
800
|
+
|
801
|
+
/* zlib wants to output some more gzipped data */
|
802
|
+
|
803
|
+
cl = ngx_alloc_chain_link(r->pool);
|
804
|
+
if (cl == NULL) {
|
805
|
+
return NGX_ERROR;
|
806
|
+
}
|
807
|
+
|
808
|
+
cl->buf = ctx->out_buf;
|
809
|
+
cl->next = NULL;
|
810
|
+
*ctx->last_out = cl;
|
811
|
+
ctx->last_out = &cl->next;
|
812
|
+
|
813
|
+
ctx->redo = 1;
|
814
|
+
|
815
|
+
return NGX_AGAIN;
|
816
|
+
}
|
817
|
+
|
818
|
+
ctx->redo = 0;
|
819
|
+
|
820
|
+
if (ctx->flush == Z_SYNC_FLUSH) {
|
821
|
+
|
822
|
+
ctx->zstream.avail_out = 0;
|
823
|
+
ctx->out_buf->flush = 1;
|
824
|
+
ctx->flush = Z_NO_FLUSH;
|
825
|
+
|
826
|
+
cl = ngx_alloc_chain_link(r->pool);
|
827
|
+
if (cl == NULL) {
|
828
|
+
return NGX_ERROR;
|
829
|
+
}
|
830
|
+
|
831
|
+
cl->buf = ctx->out_buf;
|
832
|
+
cl->next = NULL;
|
833
|
+
*ctx->last_out = cl;
|
834
|
+
ctx->last_out = &cl->next;
|
835
|
+
|
836
|
+
return NGX_OK;
|
837
|
+
}
|
838
|
+
|
839
|
+
if (rc == Z_STREAM_END) {
|
840
|
+
|
841
|
+
if (ngx_http_gzip_filter_deflate_end(r, ctx) != NGX_OK) {
|
842
|
+
return NGX_ERROR;
|
843
|
+
}
|
844
|
+
|
845
|
+
return NGX_OK;
|
846
|
+
}
|
847
|
+
|
848
|
+
conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
|
849
|
+
|
850
|
+
if (conf->no_buffer && ctx->in == NULL) {
|
851
|
+
|
852
|
+
cl = ngx_alloc_chain_link(r->pool);
|
853
|
+
if (cl == NULL) {
|
854
|
+
return NGX_ERROR;
|
855
|
+
}
|
856
|
+
|
857
|
+
cl->buf = ctx->out_buf;
|
858
|
+
cl->next = NULL;
|
859
|
+
*ctx->last_out = cl;
|
860
|
+
ctx->last_out = &cl->next;
|
861
|
+
|
862
|
+
return NGX_OK;
|
863
|
+
}
|
864
|
+
|
865
|
+
return NGX_AGAIN;
|
866
|
+
}
|
867
|
+
|
868
|
+
|
869
|
+
static ngx_int_t
|
870
|
+
ngx_http_gzip_filter_deflate_end(ngx_http_request_t *r,
|
871
|
+
ngx_http_gzip_ctx_t *ctx)
|
872
|
+
{
|
873
|
+
int rc;
|
874
|
+
ngx_buf_t *b;
|
875
|
+
ngx_chain_t *cl;
|
876
|
+
struct gztrailer *trailer;
|
877
|
+
|
878
|
+
ctx->zin = ctx->zstream.total_in;
|
879
|
+
ctx->zout = 10 + ctx->zstream.total_out + 8;
|
880
|
+
|
881
|
+
rc = deflateEnd(&ctx->zstream);
|
882
|
+
|
883
|
+
if (rc != Z_OK) {
|
884
|
+
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
885
|
+
"deflateEnd() failed: %d", rc);
|
886
|
+
return NGX_ERROR;
|
887
|
+
}
|
888
|
+
|
889
|
+
ngx_pfree(r->pool, ctx->preallocated);
|
890
|
+
|
891
|
+
cl = ngx_alloc_chain_link(r->pool);
|
892
|
+
if (cl == NULL) {
|
893
|
+
return NGX_ERROR;
|
894
|
+
}
|
895
|
+
|
896
|
+
cl->buf = ctx->out_buf;
|
897
|
+
cl->next = NULL;
|
898
|
+
*ctx->last_out = cl;
|
899
|
+
ctx->last_out = &cl->next;
|
900
|
+
|
901
|
+
if (ctx->zstream.avail_out >= 8) {
|
902
|
+
trailer = (struct gztrailer *) ctx->out_buf->last;
|
903
|
+
ctx->out_buf->last += 8;
|
904
|
+
ctx->out_buf->last_buf = 1;
|
905
|
+
|
906
|
+
} else {
|
907
|
+
b = ngx_create_temp_buf(r->pool, 8);
|
908
|
+
if (b == NULL) {
|
909
|
+
return NGX_ERROR;
|
910
|
+
}
|
911
|
+
|
912
|
+
b->last_buf = 1;
|
913
|
+
|
914
|
+
cl = ngx_alloc_chain_link(r->pool);
|
915
|
+
if (cl == NULL) {
|
916
|
+
return NGX_ERROR;
|
917
|
+
}
|
918
|
+
|
919
|
+
cl->buf = b;
|
920
|
+
cl->next = NULL;
|
921
|
+
*ctx->last_out = cl;
|
922
|
+
ctx->last_out = &cl->next;
|
923
|
+
trailer = (struct gztrailer *) b->pos;
|
924
|
+
b->last += 8;
|
925
|
+
}
|
926
|
+
|
927
|
+
#if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
|
928
|
+
|
929
|
+
trailer->crc32 = ctx->crc32;
|
930
|
+
trailer->zlen = ctx->zin;
|
931
|
+
|
932
|
+
#else
|
933
|
+
|
934
|
+
trailer->crc32[0] = (u_char) (ctx->crc32 & 0xff);
|
935
|
+
trailer->crc32[1] = (u_char) ((ctx->crc32 >> 8) & 0xff);
|
936
|
+
trailer->crc32[2] = (u_char) ((ctx->crc32 >> 16) & 0xff);
|
937
|
+
trailer->crc32[3] = (u_char) ((ctx->crc32 >> 24) & 0xff);
|
938
|
+
|
939
|
+
trailer->zlen[0] = (u_char) (ctx->zin & 0xff);
|
940
|
+
trailer->zlen[1] = (u_char) ((ctx->zin >> 8) & 0xff);
|
941
|
+
trailer->zlen[2] = (u_char) ((ctx->zin >> 16) & 0xff);
|
942
|
+
trailer->zlen[3] = (u_char) ((ctx->zin >> 24) & 0xff);
|
943
|
+
|
944
|
+
#endif
|
945
|
+
|
946
|
+
ctx->zstream.avail_in = 0;
|
947
|
+
ctx->zstream.avail_out = 0;
|
948
|
+
|
949
|
+
ctx->done = 1;
|
950
|
+
|
951
|
+
r->connection->buffered &= ~NGX_HTTP_GZIP_BUFFERED;
|
952
|
+
|
953
|
+
return NGX_OK;
|
954
|
+
}
|
955
|
+
|
956
|
+
|
957
|
+
static void *
|
958
|
+
ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size)
|
959
|
+
{
|
960
|
+
ngx_http_gzip_ctx_t *ctx = opaque;
|
961
|
+
|
962
|
+
void *p;
|
963
|
+
ngx_uint_t alloc;
|
964
|
+
|
965
|
+
alloc = items * size;
|
966
|
+
|
967
|
+
if (alloc % 512 != 0 && alloc < 8192) {
|
968
|
+
|
969
|
+
/*
|
970
|
+
* The zlib deflate_state allocation, it takes about 6K,
|
971
|
+
* we allocate 8K. Other allocations are divisible by 512.
|
972
|
+
*/
|
973
|
+
|
974
|
+
alloc = 8192;
|
975
|
+
}
|
976
|
+
|
977
|
+
if (alloc <= ctx->allocated) {
|
978
|
+
p = ctx->free_mem;
|
979
|
+
ctx->free_mem += alloc;
|
980
|
+
ctx->allocated -= alloc;
|
981
|
+
|
982
|
+
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
|
983
|
+
"gzip alloc: n:%ud s:%ud a:%ud p:%p",
|
984
|
+
items, size, alloc, p);
|
985
|
+
|
986
|
+
return p;
|
987
|
+
}
|
988
|
+
|
989
|
+
ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0,
|
990
|
+
"gzip filter failed to use preallocated memory: %ud of %ud",
|
991
|
+
items * size, ctx->allocated);
|
992
|
+
|
993
|
+
p = ngx_palloc(ctx->request->pool, items * size);
|
994
|
+
|
995
|
+
return p;
|
996
|
+
}
|
997
|
+
|
998
|
+
|
999
|
+
static void
|
1000
|
+
ngx_http_gzip_filter_free(void *opaque, void *address)
|
1001
|
+
{
|
1002
|
+
#if 0
|
1003
|
+
ngx_http_gzip_ctx_t *ctx = opaque;
|
1004
|
+
|
1005
|
+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
|
1006
|
+
"gzip free: %p", address);
|
1007
|
+
#endif
|
1008
|
+
}
|
1009
|
+
|
1010
|
+
|
1011
|
+
static void
|
1012
|
+
ngx_http_gzip_filter_free_copy_buf(ngx_http_request_t *r,
|
1013
|
+
ngx_http_gzip_ctx_t *ctx)
|
1014
|
+
{
|
1015
|
+
ngx_chain_t *cl;
|
1016
|
+
|
1017
|
+
for (cl = ctx->copied; cl; cl = cl->next) {
|
1018
|
+
ngx_pfree(r->pool, cl->buf->start);
|
1019
|
+
}
|
1020
|
+
|
1021
|
+
ctx->copied = NULL;
|
1022
|
+
}
|
1023
|
+
|
1024
|
+
|
1025
|
+
static ngx_int_t
|
1026
|
+
ngx_http_gzip_add_variables(ngx_conf_t *cf)
|
1027
|
+
{
|
1028
|
+
ngx_http_variable_t *var;
|
1029
|
+
|
1030
|
+
var = ngx_http_add_variable(cf, &ngx_http_gzip_ratio, NGX_HTTP_VAR_NOHASH);
|
1031
|
+
if (var == NULL) {
|
1032
|
+
return NGX_ERROR;
|
1033
|
+
}
|
1034
|
+
|
1035
|
+
var->get_handler = ngx_http_gzip_ratio_variable;
|
1036
|
+
|
1037
|
+
return NGX_OK;
|
1038
|
+
}
|
1039
|
+
|
1040
|
+
|
1041
|
+
static ngx_int_t
|
1042
|
+
ngx_http_gzip_ratio_variable(ngx_http_request_t *r,
|
1043
|
+
ngx_http_variable_value_t *v, uintptr_t data)
|
1044
|
+
{
|
1045
|
+
ngx_uint_t zint, zfrac;
|
1046
|
+
ngx_http_gzip_ctx_t *ctx;
|
1047
|
+
|
1048
|
+
v->valid = 1;
|
1049
|
+
v->no_cacheable = 0;
|
1050
|
+
v->not_found = 0;
|
1051
|
+
|
1052
|
+
ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module);
|
1053
|
+
|
1054
|
+
if (ctx == NULL || ctx->zout == 0) {
|
1055
|
+
v->not_found = 1;
|
1056
|
+
return NGX_OK;
|
1057
|
+
}
|
1058
|
+
|
1059
|
+
v->data = ngx_pnalloc(r->pool, NGX_INT32_LEN + 3);
|
1060
|
+
if (v->data == NULL) {
|
1061
|
+
return NGX_ERROR;
|
1062
|
+
}
|
1063
|
+
|
1064
|
+
zint = (ngx_uint_t) (ctx->zin / ctx->zout);
|
1065
|
+
zfrac = (ngx_uint_t) ((ctx->zin * 100 / ctx->zout) % 100);
|
1066
|
+
|
1067
|
+
if ((ctx->zin * 1000 / ctx->zout) % 10 > 4) {
|
1068
|
+
|
1069
|
+
/* the rounding, e.g., 2.125 to 2.13 */
|
1070
|
+
|
1071
|
+
zfrac++;
|
1072
|
+
|
1073
|
+
if (zfrac > 99) {
|
1074
|
+
zint++;
|
1075
|
+
zfrac = 0;
|
1076
|
+
}
|
1077
|
+
}
|
1078
|
+
|
1079
|
+
v->len = ngx_sprintf(v->data, "%ui.%02ui", zint, zfrac) - v->data;
|
1080
|
+
|
1081
|
+
return NGX_OK;
|
1082
|
+
}
|
1083
|
+
|
1084
|
+
|
1085
|
+
static void *
|
1086
|
+
ngx_http_gzip_create_conf(ngx_conf_t *cf)
|
1087
|
+
{
|
1088
|
+
ngx_http_gzip_conf_t *conf;
|
1089
|
+
|
1090
|
+
conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t));
|
1091
|
+
if (conf == NULL) {
|
1092
|
+
return NULL;
|
1093
|
+
}
|
1094
|
+
|
1095
|
+
/*
|
1096
|
+
* set by ngx_pcalloc():
|
1097
|
+
*
|
1098
|
+
* conf->bufs.num = 0;
|
1099
|
+
* conf->types = { NULL };
|
1100
|
+
* conf->types_keys = NULL;
|
1101
|
+
*/
|
1102
|
+
|
1103
|
+
conf->enable = NGX_CONF_UNSET;
|
1104
|
+
conf->no_buffer = NGX_CONF_UNSET;
|
1105
|
+
|
1106
|
+
conf->postpone_gzipping = NGX_CONF_UNSET_SIZE;
|
1107
|
+
conf->level = NGX_CONF_UNSET;
|
1108
|
+
conf->wbits = NGX_CONF_UNSET_SIZE;
|
1109
|
+
conf->memlevel = NGX_CONF_UNSET_SIZE;
|
1110
|
+
conf->min_length = NGX_CONF_UNSET;
|
1111
|
+
|
1112
|
+
return conf;
|
1113
|
+
}
|
1114
|
+
|
1115
|
+
|
1116
|
+
static char *
|
1117
|
+
ngx_http_gzip_merge_conf(ngx_conf_t *cf, void *parent, void *child)
|
1118
|
+
{
|
1119
|
+
ngx_http_gzip_conf_t *prev = parent;
|
1120
|
+
ngx_http_gzip_conf_t *conf = child;
|
1121
|
+
|
1122
|
+
ngx_conf_merge_value(conf->enable, prev->enable, 0);
|
1123
|
+
ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0);
|
1124
|
+
|
1125
|
+
ngx_conf_merge_bufs_value(conf->bufs, prev->bufs,
|
1126
|
+
(128 * 1024) / ngx_pagesize, ngx_pagesize);
|
1127
|
+
|
1128
|
+
ngx_conf_merge_size_value(conf->postpone_gzipping, prev->postpone_gzipping,
|
1129
|
+
0);
|
1130
|
+
ngx_conf_merge_value(conf->level, prev->level, 1);
|
1131
|
+
ngx_conf_merge_size_value(conf->wbits, prev->wbits, MAX_WBITS);
|
1132
|
+
ngx_conf_merge_size_value(conf->memlevel, prev->memlevel,
|
1133
|
+
MAX_MEM_LEVEL - 1);
|
1134
|
+
ngx_conf_merge_value(conf->min_length, prev->min_length, 20);
|
1135
|
+
|
1136
|
+
if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types,
|
1137
|
+
&prev->types_keys, &prev->types,
|
1138
|
+
ngx_http_html_default_types)
|
1139
|
+
!= NGX_OK)
|
1140
|
+
{
|
1141
|
+
return NGX_CONF_ERROR;
|
1142
|
+
}
|
1143
|
+
|
1144
|
+
return NGX_CONF_OK;
|
1145
|
+
}
|
1146
|
+
|
1147
|
+
|
1148
|
+
static ngx_int_t
|
1149
|
+
ngx_http_gzip_filter_init(ngx_conf_t *cf)
|
1150
|
+
{
|
1151
|
+
ngx_http_next_header_filter = ngx_http_top_header_filter;
|
1152
|
+
ngx_http_top_header_filter = ngx_http_gzip_header_filter;
|
1153
|
+
|
1154
|
+
ngx_http_next_body_filter = ngx_http_top_body_filter;
|
1155
|
+
ngx_http_top_body_filter = ngx_http_gzip_body_filter;
|
1156
|
+
|
1157
|
+
return NGX_OK;
|
1158
|
+
}
|
1159
|
+
|
1160
|
+
|
1161
|
+
static char *
|
1162
|
+
ngx_http_gzip_window(ngx_conf_t *cf, void *post, void *data)
|
1163
|
+
{
|
1164
|
+
size_t *np = data;
|
1165
|
+
|
1166
|
+
size_t wbits, wsize;
|
1167
|
+
|
1168
|
+
wbits = 15;
|
1169
|
+
|
1170
|
+
for (wsize = 32 * 1024; wsize > 256; wsize >>= 1) {
|
1171
|
+
|
1172
|
+
if (wsize == *np) {
|
1173
|
+
*np = wbits;
|
1174
|
+
|
1175
|
+
return NGX_CONF_OK;
|
1176
|
+
}
|
1177
|
+
|
1178
|
+
wbits--;
|
1179
|
+
}
|
1180
|
+
|
1181
|
+
return "must be 512, 1k, 2k, 4k, 8k, 16k, or 32k";
|
1182
|
+
}
|
1183
|
+
|
1184
|
+
|
1185
|
+
static char *
|
1186
|
+
ngx_http_gzip_hash(ngx_conf_t *cf, void *post, void *data)
|
1187
|
+
{
|
1188
|
+
size_t *np = data;
|
1189
|
+
|
1190
|
+
size_t memlevel, hsize;
|
1191
|
+
|
1192
|
+
memlevel = 9;
|
1193
|
+
|
1194
|
+
for (hsize = 128 * 1024; hsize > 256; hsize >>= 1) {
|
1195
|
+
|
1196
|
+
if (hsize == *np) {
|
1197
|
+
*np = memlevel;
|
1198
|
+
|
1199
|
+
return NGX_CONF_OK;
|
1200
|
+
}
|
1201
|
+
|
1202
|
+
memlevel--;
|
1203
|
+
}
|
1204
|
+
|
1205
|
+
return "must be 512, 1k, 2k, 4k, 8k, 16k, 32k, 64k, or 128k";
|
1206
|
+
}
|