You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ni...@apache.org on 2007/07/29 22:47:45 UTC

svn commit: r560811 - /httpd/httpd/trunk/modules/filters/mod_deflate.c

Author: niq
Date: Sun Jul 29 13:47:44 2007
New Revision: 560811

URL: http://svn.apache.org/viewvc?view=rev&rev=560811
Log:
Update r560689 following rpluem's analysis thereof.

Modified:
    httpd/httpd/trunk/modules/filters/mod_deflate.c

Modified: httpd/httpd/trunk/modules/filters/mod_deflate.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/filters/mod_deflate.c?view=diff&rev=560811&r1=560810&r2=560811
==============================================================================
--- httpd/httpd/trunk/modules/filters/mod_deflate.c (original)
+++ httpd/httpd/trunk/modules/filters/mod_deflate.c Sun Jul 29 13:47:44 2007
@@ -674,42 +674,37 @@
          */
         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 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;
                         }
-                        else {
-                            /* remove ":gzip" as found */
-                            memmove(ptr-sizeof(char), ptr+4*sizeof(char), sz);
-                        }
-                        /* 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 */
                 }
             }
         }