diff src/http/modules/ngx_http_static_module.c @ 126:df17fbafec8f NGINX_0_3_10

nginx 0.3.10 *) Change: the "valid_referers" directive and the "$invalid_referer" variable were moved to the new ngx_http_referer_module from the ngx_http_rewrite_module. *) Change: the "$apache_bytes_sent" variable name was changed to "$body_bytes_sent". *) Feature: the "$sent_http_..." variables. *) Feature: the "if" directive supports the "=" and "!=" operations. *) Feature: the "proxy_pass" directive supports the HTTPS protocol. *) Feature: the "proxy_set_body" directive. *) Feature: the "post_action" directive. *) Feature: the ngx_http_empty_gif_module. *) Feature: the "worker_cpu_affinity" directive for Linux. *) Bugfix: the "rewrite" directive did not unescape URI part in redirect, now it is unescaped except the %00-%25 and %7F-%FF characters. *) Bugfix: nginx could not be built by the icc 9.0 compiler. *) Bugfix: if the SSI was enabled for zero size static file, then the chunked response was encoded incorrectly.
author Igor Sysoev <http://sysoev.ru>
date Tue, 15 Nov 2005 00:00:00 +0300
parents d25a1d6034f1
children 82d695e3d662
line wrap: on
line diff
--- a/src/http/modules/ngx_http_static_module.c
+++ b/src/http/modules/ngx_http_static_module.c
@@ -44,13 +44,13 @@ ngx_http_module_t  ngx_http_static_modul
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
-    
+
     NULL,                                  /* create server configuration */
     NULL,                                  /* merge server configuration */
-    
+
     ngx_http_static_create_loc_conf,       /* create location configuration */
     ngx_http_static_merge_loc_conf         /* merge location configuration */
-};  
+};
 
 
 ngx_module_t  ngx_http_static_module = {
@@ -240,33 +240,23 @@ ngx_http_static_handler(ngx_http_request
     r->headers_out.content_length_n = ngx_file_size(&fi);
     r->headers_out.last_modified_time = ngx_file_mtime(&fi);
 
-    if (r->headers_out.content_length_n == 0) {
-        r->header_only = 1;
-    }
-
     if (ngx_http_set_content_type(r) != NGX_OK) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
-#if (NGX_SUPPRESS_WARN)
-    b = NULL;
-#endif
+    /* we need to allocate all before the header would be sent */
 
-    if (!r->header_only) {
-        /* we need to allocate all before the header would be sent */
+    b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
+    if (b == NULL) {
+        return NGX_HTTP_INTERNAL_SERVER_ERROR;
+    }
 
-        b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
-        if (b == NULL) {
-            return NGX_HTTP_INTERNAL_SERVER_ERROR;
-        }
+    b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
+    if (b->file == NULL) {
+        return NGX_HTTP_INTERNAL_SERVER_ERROR;
+    }
 
-        b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
-        if (b->file == NULL) {
-            return NGX_HTTP_INTERNAL_SERVER_ERROR;
-        }
-
-        r->filter_allow_ranges = 1;
-    }
+    r->filter_allow_ranges = 1;
 
     rc = ngx_http_send_header(r);
 
@@ -274,17 +264,13 @@ ngx_http_static_handler(ngx_http_request
         return rc;
     }
 
-    b->in_file = 1;
-
-    if (r->main == r) {
-        b->last_buf = 1;
-    }
-
-    b->last_in_chain = 1;
-
     b->file_pos = 0;
     b->file_last = ngx_file_size(&fi);
 
+    b->in_file = b->file_last ? 1: 0;
+    b->last_buf = (r->main == r) ? 1: 0;
+    b->last_in_chain = 1;
+
     b->file->fd = fd;
     b->file->name = path;
     b->file->log = log;
@@ -333,7 +319,7 @@ ngx_http_static_init(ngx_cycle_t *cycle)
     ngx_http_core_main_conf_t  *cmcf;
 
     cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
-    
+
     h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
     if (h == NULL) {
         return NGX_ERROR;