changeset 6:27628b3310ab

Better handle absence of controlling headers. Don't do any processing if there is no X-Compose headers. If there is no X-Compose-Length, clear content length and disallow ranges.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 24 Jul 2008 02:39:59 +0400
parents fc206607251c
children 88272d0f29f9
files ngx_http_compose_filter_module.c
diffstat 1 files changed, 20 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ngx_http_compose_filter_module.c	Mon Jul 21 05:34:36 2008 +0400
+++ b/ngx_http_compose_filter_module.c	Thu Jul 24 02:39:59 2008 +0400
@@ -108,6 +108,7 @@
 static ngx_int_t
 ngx_http_compose_header_filter(ngx_http_request_t *r)
 {
+    off_t                     len;
     ngx_uint_t                i;
     ngx_str_t                *uri;
     ngx_list_part_t          *part;
@@ -146,6 +147,7 @@
 
     part = &r->headers_out.headers.part;
     header = part->elts;
+    len = -1;
 
     for (i = 0; /* void */; i++) {
 
@@ -174,13 +176,7 @@
 
             header[i].hash = 0;
 
-            r->headers_out.content_length_n = ngx_atoof(header[i].value.data,
-                                                        header[i].value.len);
-
-            if (r->headers_out.content_length) {
-                r->headers_out.content_length->hash = 0;
-                r->headers_out.content_length = NULL;
-            }
+            len = ngx_atoof(header[i].value.data, header[i].value.len);
         }
 
         if (header[i].key.len == sizeof("X-Compose") - 1
@@ -208,11 +204,26 @@
         }
     }
 
+    if (ctx->parts.nelts == 0) {
+        return ngx_http_next_header_filter(r);
+    }
+
+    r->headers_out.content_length_n = len;
+
+    if (r->headers_out.content_length) {
+        r->headers_out.content_length->hash = 0;
+        r->headers_out.content_length = NULL;
+    }
 
     ngx_http_set_ctx(r, ctx, ngx_http_compose_filter_module);
 
-    r->allow_ranges = 1;
-    r->late_ranges = 1;
+    if (len != -1) {
+        r->allow_ranges = 1;
+        r->late_ranges = 1;
+
+    } else {
+        ngx_http_clear_accept_ranges(r);
+    }
 
     return ngx_http_next_header_filter(r);
 }