[nginx] slice module issue

洪志道 hongzhidao at gmail.com
Tue Jun 20 17:22:09 UTC 2017


I hope slice module can satisfy customer requirements.

Now the key point is users want to control the behavior of slice.
And this is common.

Here's the patch, take a look please!

diff -r 5e05118678af src/http/modules/ngx_http_slice_filter_module.c
--- a/src/http/modules/ngx_http_slice_filter_module.c Mon May 29 23:33:38
2017 +0300
+++ b/src/http/modules/ngx_http_slice_filter_module.c Tue Jun 20 13:17:17
2017 -0400
@@ -12,6 +12,7 @@

 typedef struct {
     size_t               size;
+    ngx_flag_t           always;
 } ngx_http_slice_loc_conf_t;


@@ -57,6 +58,13 @@
       offsetof(ngx_http_slice_loc_conf_t, size),
       NULL },

+    { ngx_string("slice_always"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+      ngx_conf_set_flag_slot,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      offsetof(ngx_http_slice_loc_conf_t, always),
+      NULL },
+
       ngx_null_command
 };

@@ -389,6 +397,7 @@
     ngx_http_variable_value_t *v, uintptr_t data)
 {
     u_char                     *p;
+    off_t                      start;
     ngx_http_slice_ctx_t       *ctx;
     ngx_http_slice_loc_conf_t  *slcf;

@@ -407,6 +416,12 @@
             return NGX_OK;
         }

+        start = ngx_http_slice_get_start(r);
+        if (start == -1 && slcf->always == 0) {
+            v->not_found = 1;
+            return NGX_OK;
+        }
+
         ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_slice_ctx_t));
         if (ctx == NULL) {
             return NGX_ERROR;
@@ -419,7 +434,7 @@
             return NGX_ERROR;
         }

-        ctx->start = slcf->size * (ngx_http_slice_get_start(r) /
slcf->size);
+        ctx->start = slcf->size * (start / slcf->size);

         ctx->range.data = p;
         ctx->range.len = ngx_sprintf(p, "bytes=%O-%O", ctx->start,
@@ -445,7 +460,7 @@
     ngx_table_elt_t  *h;

     if (r->headers_in.if_range) {
-        return 0;
+        return -1;
     }

     h = r->headers_in.range;
@@ -454,13 +469,13 @@
         || h->value.len < 7
         || ngx_strncasecmp(h->value.data, (u_char *) "bytes=", 6) != 0)
     {
-        return 0;
+        return -1;
     }

     p = h->value.data + 6;

     if (ngx_strchr(p, ',')) {
-        return 0;
+        return -1;
     }

     while (*p == ' ') { p++; }
@@ -476,7 +491,7 @@

     while (*p >= '0' && *p <= '9') {
         if (start >= cutoff && (start > cutoff || *p - '0' > cutlim)) {
-            return 0;
+            return -1;
         }

         start = start * 10 + *p++ - '0';
@@ -497,6 +512,7 @@
     }

     slcf->size = NGX_CONF_UNSET_SIZE;
+    slcf->always = NGX_CONF_UNSET;

     return slcf;
 }
@@ -509,6 +525,7 @@
     ngx_http_slice_loc_conf_t *conf = child;

     ngx_conf_merge_size_value(conf->size, prev->size, 0);
+    ngx_conf_merge_value(conf->always, prev->always, 1);

     return NGX_CONF_OK;
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20170621/7a6dd61c/attachment.html>


More information about the nginx-devel mailing list