]> granicus.if.org Git - apache/commitdiff
Update r560689 following rpluem's analysis thereof.
authorNick Kew <niq@apache.org>
Sun, 29 Jul 2007 20:47:44 +0000 (20:47 +0000)
committerNick Kew <niq@apache.org>
Sun, 29 Jul 2007 20:47:44 +0000 (20:47 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@560811 13f79535-47bb-0310-9956-ffa450edef68

modules/filters/mod_deflate.c

index 0028429b80d9aead98e9443fc5b1d0d375f2fa8d..8d8d2df6dbae90bb0b96d2120507aa73abd99f70 100644 (file)
@@ -674,42 +674,37 @@ static apr_status_t deflate_in_filter(ap_filter_t *f,
          */
         encoding = apr_table_get(r->headers_in, "Content-Encoding");
         if (encoding && *encoding) {
-            const char *tmp = encoding;
 
             /* check the usual/simple case first */
             if (!strcasecmp(encoding, "gzip")) {
                 found = 1;
                 apr_table_unset(r->headers_in, "Content-Encoding");
             }
-            else {
-                token = ap_get_token(r->pool, &tmp, 0);
-                while (token && token[0]) {
-                    if (!strcasecmp(token, "gzip")) {
-                        char *new_encoding = apr_pstrdup(r->pool, encoding);
-                        char *ptr = ap_strstr(new_encoding, token);
-                        size_t sz = 5*sizeof(char);
-                        if (ptr == new_encoding) {
-                            /* remove "gzip:" at start */
-                            memmove(ptr, ptr+sz, sz);
-                        }
-                        else {
-                            /* remove ":gzip" as found */
-                            memmove(ptr-sizeof(char), ptr+4*sizeof(char), sz);
+            else if (ap_strchr_c(encoding, ':') != NULL) {
+                /* If the outermost encoding isn't gzip, there's nowt
+                 * we can do.  So only check the last non-identity token
+                 */
+                char *new_encoding = apr_pstrdup(r->pool, encoding);
+                for(;;) {
+                    token = ap_strrchr(new_encoding, ':');
+                    if (!token) {        /* gzip:identity or other:identity */
+                        if (!strcasecmp(new_encoding, "gzip")) {
+                            apr_table_unset(r->headers_in, "Content-Encoding");
+                            found = 1;
                         }
-                        /* Silly edge-case: if there's more than one "gzip"
-                         * token, this is a maybe-bug, as we remove exactly
-                         * one gzip token.  But it's not really our bug:
-                         * two gzips should mean it's double-gzipped,
-                         * shouldn't it?  Insert this filter twice!
-                         */
+                        break; /* seen all tokens */
+                    }
+                    if (!strcasecmp(token+sizeof(char), "gzip")) {
+                        *token = '\0';
                         apr_table_setn(r->headers_in, "Content-Encoding",
                                        new_encoding);
                         found = 1;
-                        break;
                     }
-                    /* Otherwise, skip token */
-                    tmp++;
-                    token = ap_get_token(r->pool, &tmp, 0);
+                    else if (!strcasecmp(token+sizeof(char), "identity")) {
+                        *token = '\0';
+                        continue; /* strip the token and find the next one */
+                    }
+                    break; /* found a non-identity token */
                 }
             }
         }