comparison src/http/ngx_http_upstream.c @ 480:549994537f15 NGINX_0_7_52

nginx 0.7.52 *) Feature: the first native Windows binary release. *) Bugfix: in processing HEAD method while caching. *) Bugfix: in processing the "If-Modified-Since", "If-Range", etc. client request header lines while caching. *) Bugfix: now the "Set-Cookie" and "P3P" header lines are hidden in cacheable responses. *) Bugfix: if nginx was built with the ngx_http_perl_module and with a perl which supports threads, then during a master process exit the message "panic: MUTEX_LOCK" might be issued. *) Bugfix: nginx could not be built --without-http-cache; the bug had appeared in 0.7.48. *) Bugfix: nginx could not be built on platforms different from i386, amd64, sparc, and ppc; the bug had appeared in 0.7.42.
author Igor Sysoev <http://sysoev.ru>
date Mon, 20 Apr 2009 00:00:00 +0400
parents f2c6a7373274
children 392c16f2d858
comparison
equal deleted inserted replaced
479:eb4fdebda673 480:549994537f15
530 ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u) 530 ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
531 { 531 {
532 ngx_int_t rc; 532 ngx_int_t rc;
533 ngx_http_cache_t *c; 533 ngx_http_cache_t *c;
534 534
535 if (!(r->method & NGX_HTTP_GET)) { 535 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
536 return NGX_DECLINED; 536 return NGX_DECLINED;
537 }
538
539 if (r->method & NGX_HTTP_HEAD) {
540 u->method = ngx_http_core_get_method;
537 } 541 }
538 542
539 c = ngx_pcalloc(r->pool, sizeof(ngx_http_cache_t)); 543 c = ngx_pcalloc(r->pool, sizeof(ngx_http_cache_t));
540 if (c == NULL) { 544 if (c == NULL) {
541 return NGX_ERROR; 545 return NGX_ERROR;
1819 ngx_connection_t *c; 1823 ngx_connection_t *c;
1820 ngx_http_core_loc_conf_t *clcf; 1824 ngx_http_core_loc_conf_t *clcf;
1821 1825
1822 rc = ngx_http_send_header(r); 1826 rc = ngx_http_send_header(r);
1823 1827
1824 if (rc == NGX_ERROR || rc > NGX_OK || r->post_action || r->header_only) { 1828 if (rc == NGX_ERROR || rc > NGX_OK || r->post_action) {
1825 ngx_http_upstream_finalize_request(r, u, rc); 1829 ngx_http_upstream_finalize_request(r, u, rc);
1826 return; 1830 return;
1831 }
1832
1833 c = r->connection;
1834
1835 if (r->header_only) {
1836
1837 if (u->cacheable || u->store) {
1838
1839 if (ngx_shutdown_socket(c->fd, NGX_WRITE_SHUTDOWN) == -1) {
1840 ngx_connection_error(c, ngx_socket_errno,
1841 ngx_shutdown_socket_n " failed");
1842 }
1843
1844 r->read_event_handler = ngx_http_request_empty_handler;
1845 r->write_event_handler = ngx_http_request_empty_handler;
1846 c->error = 1;
1847
1848 } else {
1849 ngx_http_upstream_finalize_request(r, u, rc);
1850 return;
1851 }
1827 } 1852 }
1828 1853
1829 u->header_sent = 1; 1854 u->header_sent = 1;
1830 1855
1831 if (r->request_body && r->request_body->temp_file) { 1856 if (r->request_body && r->request_body->temp_file) {
1832 ngx_pool_run_cleanup_file(r->pool, r->request_body->temp_file->file.fd); 1857 ngx_pool_run_cleanup_file(r->pool, r->request_body->temp_file->file.fd);
1833 r->request_body->temp_file->file.fd = NGX_INVALID_FILE; 1858 r->request_body->temp_file->file.fd = NGX_INVALID_FILE;
1834 } 1859 }
1835
1836 c = r->connection;
1837 1860
1838 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 1861 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1839 1862
1840 if (!u->buffering) { 1863 if (!u->buffering) {
1841 1864
1940 1963
1941 ngx_http_file_cache_set_header(r, u->buffer.start); 1964 ngx_http_file_cache_set_header(r, u->buffer.start);
1942 1965
1943 } else { 1966 } else {
1944 u->cacheable = 0; 1967 u->cacheable = 0;
1968 r->headers_out.last_modified_time = -1;
1945 } 1969 }
1946 } 1970 }
1947 1971
1948 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, 1972 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
1949 "http cacheable: %d", u->cacheable); 1973 "http cacheable: %d", u->cacheable);
2817 2841
2818 static ngx_int_t 2842 static ngx_int_t
2819 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, 2843 ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
2820 ngx_table_elt_t *h, ngx_uint_t offset) 2844 ngx_table_elt_t *h, ngx_uint_t offset)
2821 { 2845 {
2822 u_char *p, *last;
2823 ngx_int_t n;
2824 ngx_array_t *pa; 2846 ngx_array_t *pa;
2825 ngx_table_elt_t **ph; 2847 ngx_table_elt_t **ph;
2826 2848
2827 pa = &r->upstream->headers_in.cache_control; 2849 pa = &r->upstream->headers_in.cache_control;
2828 2850
2838 return NGX_ERROR; 2860 return NGX_ERROR;
2839 } 2861 }
2840 2862
2841 *ph = h; 2863 *ph = h;
2842 2864
2865 #if (NGX_HTTP_CACHE)
2866 {
2867 u_char *p, *last;
2868 ngx_int_t n;
2869
2843 if (r->cache == NULL) { 2870 if (r->cache == NULL) {
2844 return NGX_OK; 2871 return NGX_OK;
2845 } 2872 }
2846 2873
2847 if (r->cache->valid_sec != 0) { 2874 if (r->cache->valid_sec != 0) {
2883 r->upstream->cacheable = 0; 2910 r->upstream->cacheable = 0;
2884 return NGX_OK; 2911 return NGX_OK;
2885 } 2912 }
2886 2913
2887 r->cache->valid_sec = ngx_time() + n; 2914 r->cache->valid_sec = ngx_time() + n;
2915 }
2916 #endif
2917
2888 return NGX_OK; 2918 return NGX_OK;
2889 } 2919 }
2890 2920
2891 2921
2892 static ngx_int_t 2922 static ngx_int_t
2893 ngx_http_upstream_process_expires(ngx_http_request_t *r, ngx_table_elt_t *h, 2923 ngx_http_upstream_process_expires(ngx_http_request_t *r, ngx_table_elt_t *h,
2894 ngx_uint_t offset) 2924 ngx_uint_t offset)
2895 { 2925 {
2926 r->upstream->headers_in.expires = h;
2927
2928 #if (NGX_HTTP_CACHE)
2929 {
2896 time_t expires; 2930 time_t expires;
2897
2898 r->upstream->headers_in.expires = h;
2899 2931
2900 if (r->cache == NULL) { 2932 if (r->cache == NULL) {
2901 return NGX_OK; 2933 return NGX_OK;
2902 } 2934 }
2903 2935
2911 r->upstream->cacheable = 0; 2943 r->upstream->cacheable = 0;
2912 return NGX_OK; 2944 return NGX_OK;
2913 } 2945 }
2914 2946
2915 r->cache->valid_sec = expires; 2947 r->cache->valid_sec = expires;
2948 }
2949 #endif
2916 2950
2917 return NGX_OK; 2951 return NGX_OK;
2918 } 2952 }
2919 2953
2920 2954
2921 static ngx_int_t 2955 static ngx_int_t
2922 ngx_http_upstream_process_accel_expires(ngx_http_request_t *r, 2956 ngx_http_upstream_process_accel_expires(ngx_http_request_t *r,
2923 ngx_table_elt_t *h, ngx_uint_t offset) 2957 ngx_table_elt_t *h, ngx_uint_t offset)
2924 { 2958 {
2959 r->upstream->headers_in.x_accel_expires = h;
2960
2961 #if (NGX_HTTP_CACHE)
2962 {
2925 u_char *p; 2963 u_char *p;
2926 size_t len; 2964 size_t len;
2927 ngx_int_t n; 2965 ngx_int_t n;
2928
2929 r->upstream->headers_in.x_accel_expires = h;
2930 2966
2931 if (r->cache == NULL) { 2967 if (r->cache == NULL) {
2932 return NGX_OK; 2968 return NGX_OK;
2933 } 2969 }
2934 2970
2956 n = ngx_atoi(p, len); 2992 n = ngx_atoi(p, len);
2957 2993
2958 if (n != NGX_ERROR) { 2994 if (n != NGX_ERROR) {
2959 r->cache->valid_sec = n; 2995 r->cache->valid_sec = n;
2960 } 2996 }
2997 }
2998 #endif
2961 2999
2962 return NGX_OK; 3000 return NGX_OK;
2963 } 3001 }
2964 3002
2965 3003
3161 3199
3162 *ho = *h; 3200 *ho = *h;
3163 3201
3164 #if (NGX_HTTP_CACHE) 3202 #if (NGX_HTTP_CACHE)
3165 3203
3166 if (r->cached) { 3204 if (r->cached || r->upstream->cacheable) {
3167 r->headers_out.last_modified = ho; 3205 r->headers_out.last_modified = ho;
3168 r->headers_out.last_modified_time = ngx_http_parse_time(h->value.data, 3206 r->headers_out.last_modified_time = ngx_http_parse_time(h->value.data,
3169 h->value.len); 3207 h->value.len);
3170 } 3208 }
3171 3209