You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by wr...@apache.org on 2018/09/12 13:56:21 UTC

svn commit: r1840688 [13/37] - in /httpd/sandbox/httpd-2.4.x-trunk-delta: ./ build/ build/rpm/ build/win32/ docs/ docs/conf/ docs/conf/extra/ docs/log-message-tags/ docs/man/ docs/man/tr/ include/ modules/ modules/aaa/ modules/apreq/ modules/arch/unix/...

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_deflate.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_deflate.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_deflate.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_deflate.c Wed Sep 12 13:56:17 2018
@@ -53,6 +53,10 @@
 static const char deflateFilterName[] = "DEFLATE";
 module AP_MODULE_DECLARE_DATA deflate_module;
 
+#define AP_DEFLATE_ETAG_ADDSUFFIX 0
+#define AP_DEFLATE_ETAG_NOCHANGE  1
+#define AP_DEFLATE_ETAG_REMOVE    2
+
 #define AP_INFLATE_RATIO_LIMIT 200
 #define AP_INFLATE_RATIO_BURST 3
 
@@ -61,10 +65,11 @@ typedef struct deflate_filter_config_t
     int windowSize;
     int memlevel;
     int compressionlevel;
-    apr_size_t bufferSize;
+    int bufferSize;
     const char *note_ratio_name;
     const char *note_input_name;
     const char *note_output_name;
+    int etag_opt;
 } deflate_filter_config;
 
 typedef struct deflate_dirconf_t {
@@ -118,8 +123,8 @@ static int check_gzip(request_rec *r, ap
     if (encoding && *encoding) {
 
         /* check the usual/simple case first */
-        if (!strcasecmp(encoding, "gzip")
-            || !strcasecmp(encoding, "x-gzip")) {
+        if (!ap_cstr_casecmp(encoding, "gzip")
+            || !ap_cstr_casecmp(encoding, "x-gzip")) {
             found = 1;
             if (hdrs) {
                 apr_table_unset(hdrs, "Content-Encoding");
@@ -137,8 +142,8 @@ static int check_gzip(request_rec *r, ap
             for(;;) {
                 char *token = ap_strrchr(new_encoding, ',');
                 if (!token) {        /* gzip:identity or other:identity */
-                    if (!strcasecmp(new_encoding, "gzip")
-                        || !strcasecmp(new_encoding, "x-gzip")) {
+                    if (!ap_cstr_casecmp(new_encoding, "gzip")
+                        || !ap_cstr_casecmp(new_encoding, "x-gzip")) {
                         found = 1;
                         if (hdrs) {
                             apr_table_unset(hdrs, "Content-Encoding");
@@ -150,8 +155,8 @@ static int check_gzip(request_rec *r, ap
                     break; /* seen all tokens */
                 }
                 for (ptr=token+1; apr_isspace(*ptr); ++ptr);
-                if (!strcasecmp(ptr, "gzip")
-                    || !strcasecmp(ptr, "x-gzip")) {
+                if (!ap_cstr_casecmp(ptr, "gzip")
+                    || !ap_cstr_casecmp(ptr, "x-gzip")) {
                     *token = '\0';
                     if (hdrs) {
                         apr_table_setn(hdrs, "Content-Encoding", new_encoding);
@@ -161,7 +166,7 @@ static int check_gzip(request_rec *r, ap
                     }
                     found = 1;
                 }
-                else if (!ptr[0] || !strcasecmp(ptr, "identity")) {
+                else if (!ptr[0] || !ap_cstr_casecmp(ptr, "identity")) {
                     *token = '\0';
                     continue; /* strip the token and find the next one */
                 }
@@ -210,6 +215,7 @@ static void *create_deflate_server_confi
     c->windowSize = DEFAULT_WINDOWSIZE;
     c->bufferSize = DEFAULT_BUFFERSIZE;
     c->compressionlevel = DEFAULT_COMPRESSION;
+    c->etag_opt = AP_DEFLATE_ETAG_ADDSUFFIX;
 
     return c;
 }
@@ -250,7 +256,7 @@ static const char *deflate_set_buffer_si
         return "DeflateBufferSize should be positive";
     }
 
-    c->bufferSize = (apr_size_t)n;
+    c->bufferSize = n;
 
     return NULL;
 }
@@ -296,6 +302,29 @@ static const char *deflate_set_memlevel(
     return NULL;
 }
 
+static const char *deflate_set_etag(cmd_parms *cmd, void *dummy,
+                                        const char *arg)
+{
+    deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
+                                                    &deflate_module);
+
+    if (!strcasecmp(arg, "NoChange")) { 
+      c->etag_opt = AP_DEFLATE_ETAG_NOCHANGE;
+    }
+    else if (!strcasecmp(arg, "AddSuffix")) { 
+      c->etag_opt = AP_DEFLATE_ETAG_ADDSUFFIX;
+    }
+    else if (!strcasecmp(arg, "Remove")) { 
+      c->etag_opt = AP_DEFLATE_ETAG_REMOVE;
+    }
+    else { 
+        return "DeflateAlterETAG accepts only 'NoChange', 'AddSuffix', and 'Remove'";
+    }
+
+    return NULL;
+}
+
+
 static const char *deflate_set_compressionlevel(cmd_parms *cmd, void *dummy,
                                         const char *arg)
 {
@@ -389,37 +418,42 @@ typedef struct deflate_ctx_t
 /* Do update ctx->crc, see comment in flush_libz_buffer */
 #define UPDATE_CRC 1
 
-static int flush_libz_buffer(deflate_ctx *ctx, deflate_filter_config *c,
-                             struct apr_bucket_alloc_t *bucket_alloc,
-                             int (*libz_func)(z_streamp, int), int flush,
-                             int crc)
+static void consume_buffer(deflate_ctx *ctx, deflate_filter_config *c,
+                           int len, int crc, apr_bucket_brigade *bb)
 {
-    int zRC = Z_OK;
-    int done = 0;
-    unsigned int deflate_len;
     apr_bucket *b;
 
-    for (;;) {
-         deflate_len = c->bufferSize - ctx->stream.avail_out;
-
-         if (deflate_len != 0) {
              /*
               * Do we need to update ctx->crc? Usually this is the case for
               * inflate action where we need to do a crc on the output, whereas
               * in the deflate case we need to do a crc on the input
               */
              if (crc) {
-                 ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer,
-                                  deflate_len);
+        ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
              }
-             b = apr_bucket_heap_create((char *)ctx->buffer,
-                                        deflate_len, NULL,
-                                        bucket_alloc);
-             APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
+
+    b = apr_bucket_heap_create((char *)ctx->buffer, len, NULL,
+                               bb->bucket_alloc);
+    APR_BRIGADE_INSERT_TAIL(bb, b);
+
              ctx->stream.next_out = ctx->buffer;
              ctx->stream.avail_out = c->bufferSize;
          }
 
+static int flush_libz_buffer(deflate_ctx *ctx, deflate_filter_config *c,
+                             int (*libz_func)(z_streamp, int), int flush,
+                             int crc)
+{
+    int zRC = Z_OK;
+    int done = 0;
+    int deflate_len;
+
+    for (;;) {
+         deflate_len = c->bufferSize - ctx->stream.avail_out;
+         if (deflate_len > 0) {
+             consume_buffer(ctx, c, deflate_len, crc, ctx->bb);
+         }
+
          if (done)
              break;
 
@@ -465,11 +499,16 @@ static apr_status_t deflate_ctx_cleanup(
  * value inside the double-quotes if an ETag has already been set
  * and its value already contains double-quotes. PR 39727
  */
-static void deflate_check_etag(request_rec *r, const char *transform)
+static void deflate_check_etag(request_rec *r, const char *transform, int etag_opt)
 {
     const char *etag = apr_table_get(r->headers_out, "ETag");
     apr_size_t etaglen;
 
+    if (etag_opt == AP_DEFLATE_ETAG_REMOVE) { 
+        apr_table_unset(r->headers_out, "ETag");
+        return;
+    }
+
     if ((etag && ((etaglen = strlen(etag)) > 2))) {
         if (etag[etaglen - 1] == '"') {
             apr_size_t transformlen = strlen(transform);
@@ -530,6 +569,7 @@ static apr_status_t deflate_out_filter(a
     request_rec *r = f->r;
     deflate_ctx *ctx = f->ctx;
     int zRC;
+    apr_status_t rv;
     apr_size_t len = 0, blen;
     const char *data;
     deflate_filter_config *c;
@@ -705,7 +745,7 @@ static apr_status_t deflate_out_filter(a
             }
 
             token = ap_get_token(r->pool, &accepts, 0);
-            while (token && token[0] && strcasecmp(token, "gzip")) {
+            while (token && token[0] && ap_cstr_casecmp(token, "gzip")) {
                 /* skip parameters, XXX: ;q=foo evaluation? */
                 while (*accepts == ';') {
                     ++accepts;
@@ -779,7 +819,7 @@ static apr_status_t deflate_out_filter(a
          */
 
         /* If the entire Content-Encoding is "identity", we can replace it. */
-        if (!encoding || !strcasecmp(encoding, "identity")) {
+        if (!encoding || !ap_cstr_casecmp(encoding, "identity")) {
             apr_table_setn(r->headers_out, "Content-Encoding", "gzip");
         }
         else {
@@ -792,7 +832,9 @@ static apr_status_t deflate_out_filter(a
         }
         apr_table_unset(r->headers_out, "Content-Length");
         apr_table_unset(r->headers_out, "Content-MD5");
-        deflate_check_etag(r, "gzip");
+        if (c->etag_opt != AP_DEFLATE_ETAG_NOCHANGE) {  
+            deflate_check_etag(r, "gzip", c->etag_opt);
+        }
 
         /* For a 304 response, only change the headers */
         if (r->status == HTTP_NOT_MODIFIED) {
@@ -839,8 +881,7 @@ static apr_status_t deflate_out_filter(a
 
             ctx->stream.avail_in = 0; /* should be zero already anyway */
             /* flush the remaining data from the zlib buffers */
-            flush_libz_buffer(ctx, c, f->c->bucket_alloc, deflate, Z_FINISH,
-                              NO_UPDATE_CRC);
+            flush_libz_buffer(ctx, c, deflate, Z_FINISH, NO_UPDATE_CRC);
 
             buf = apr_palloc(r->pool, VALIDATION_SIZE);
             putLong((unsigned char *)&buf[0], ctx->crc);
@@ -891,15 +932,15 @@ static apr_status_t deflate_out_filter(a
             /* Okay, we've seen the EOS.
              * Time to pass it along down the chain.
              */
-            return ap_pass_brigade(f->next, ctx->bb);
+            rv = ap_pass_brigade(f->next, ctx->bb);
+            apr_brigade_cleanup(ctx->bb);
+            return rv;
         }
 
         if (APR_BUCKET_IS_FLUSH(e)) {
-            apr_status_t rv;
-
             /* flush the remaining data from the zlib buffers */
-            zRC = flush_libz_buffer(ctx, c, f->c->bucket_alloc, deflate,
-                                    Z_SYNC_FLUSH, NO_UPDATE_CRC);
+            zRC = flush_libz_buffer(ctx, c, deflate, Z_SYNC_FLUSH,
+                                    NO_UPDATE_CRC);
             if (zRC != Z_OK) {
                 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01385)
                               "Zlib error %d flushing zlib output buffer (%s)",
@@ -911,6 +952,7 @@ static apr_status_t deflate_out_filter(a
             APR_BUCKET_REMOVE(e);
             APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
             rv = ap_pass_brigade(f->next, ctx->bb);
+            apr_brigade_cleanup(ctx->bb);
             if (rv != APR_SUCCESS) {
                 return rv;
             }
@@ -945,21 +987,15 @@ static apr_status_t deflate_out_filter(a
         ctx->stream.next_in = (unsigned char *)data; /* We just lost const-ness,
                                                       * but we'll just have to
                                                       * trust zlib */
-        ctx->stream.avail_in = len;
+        ctx->stream.avail_in = (int)len;
 
         while (ctx->stream.avail_in != 0) {
             if (ctx->stream.avail_out == 0) {
-                apr_status_t rv;
-
-                ctx->stream.next_out = ctx->buffer;
-                len = c->bufferSize - ctx->stream.avail_out;
+                consume_buffer(ctx, c, c->bufferSize, NO_UPDATE_CRC, ctx->bb);
 
-                b = apr_bucket_heap_create((char *)ctx->buffer, len,
-                                           NULL, f->c->bucket_alloc);
-                APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
-                ctx->stream.avail_out = c->bufferSize;
                 /* Send what we have right now to the next filter. */
                 rv = ap_pass_brigade(f->next, ctx->bb);
+                apr_brigade_cleanup(ctx->bb);
                 if (rv != APR_SUCCESS) {
                     return rv;
                 }
@@ -1286,14 +1322,8 @@ static apr_status_t deflate_in_filter(ap
                     return APR_EINVAL;
                 }
 
-                len = c->bufferSize - ctx->stream.avail_out;
-                ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
-                tmp_b = apr_bucket_heap_create((char *)ctx->buffer, len,
-                                                NULL, f->c->bucket_alloc);
-                APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, tmp_b);
-
-                ctx->stream.next_out = ctx->buffer;
-                ctx->stream.avail_out = c->bufferSize;
+                consume_buffer(ctx, c, c->bufferSize - ctx->stream.avail_out,
+                               UPDATE_CRC, ctx->proc_bb);
 
                 /* Flush everything so far in the returning brigade, but continue
                  * reading should EOS/more follow (don't lose them).
@@ -1341,16 +1371,8 @@ static apr_status_t deflate_in_filter(ap
             if (!ctx->validation_buffer) {
                 while (ctx->stream.avail_in != 0) {
                     if (ctx->stream.avail_out == 0) {
-                        apr_bucket *tmp_heap;
-
-                        ctx->stream.next_out = ctx->buffer;
-                        len = c->bufferSize - ctx->stream.avail_out;
-
-                        ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
-                        tmp_heap = apr_bucket_heap_create((char *)ctx->buffer, len,
-                                                          NULL, f->c->bucket_alloc);
-                        APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, tmp_heap);
-                        ctx->stream.avail_out = c->bufferSize;
+                        consume_buffer(ctx, c, c->bufferSize, UPDATE_CRC,
+                                       ctx->proc_bb);
                     }
 
                     ctx->inflate_total += ctx->stream.avail_out;
@@ -1393,7 +1415,6 @@ static apr_status_t deflate_in_filter(ap
             }
 
             if (ctx->validation_buffer) {
-                apr_bucket *tmp_heap;
                 apr_size_t avail, valid;
                 unsigned char *buf = ctx->validation_buffer;
 
@@ -1421,13 +1442,8 @@ static apr_status_t deflate_in_filter(ap
                               ctx->stream.total_in, ctx->stream.total_out,
                               r->uri);
 
-                len = c->bufferSize - ctx->stream.avail_out;
-
-                ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
-                tmp_heap = apr_bucket_heap_create((char *)ctx->buffer, len,
-                                                  NULL, f->c->bucket_alloc);
-                APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, tmp_heap);
-                ctx->stream.avail_out = c->bufferSize;
+                consume_buffer(ctx, c, c->bufferSize - ctx->stream.avail_out,
+                               UPDATE_CRC, ctx->proc_bb);
 
                 {
                     unsigned long compCRC, compLen;
@@ -1472,16 +1488,8 @@ static apr_status_t deflate_in_filter(ap
     if (block == APR_BLOCK_READ &&
             APR_BRIGADE_EMPTY(ctx->proc_bb) &&
             ctx->stream.avail_out < c->bufferSize) {
-        apr_bucket *tmp_heap;
-        apr_size_t len;
-        ctx->stream.next_out = ctx->buffer;
-        len = c->bufferSize - ctx->stream.avail_out;
-
-        ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
-        tmp_heap = apr_bucket_heap_create((char *)ctx->buffer, len,
-                                          NULL, f->c->bucket_alloc);
-        APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, tmp_heap);
-        ctx->stream.avail_out = c->bufferSize;
+        consume_buffer(ctx, c, c->bufferSize - ctx->stream.avail_out,
+                       UPDATE_CRC, ctx->proc_bb);
     }
 
     if (!APR_BRIGADE_EMPTY(ctx->proc_bb)) {
@@ -1545,7 +1553,9 @@ static apr_status_t inflate_out_filter(a
          */
         apr_table_unset(r->headers_out, "Content-Length");
         apr_table_unset(r->headers_out, "Content-MD5");
-        deflate_check_etag(r, "gunzip");
+        if (c->etag_opt != AP_DEFLATE_ETAG_NOCHANGE) {
+            deflate_check_etag(r, "gunzip", c->etag_opt);
+        }
 
         /* For a 304 response, only change the headers */
         if (r->status == HTTP_NOT_MODIFIED) {
@@ -1593,7 +1603,6 @@ static apr_status_t inflate_out_filter(a
     while (!APR_BRIGADE_EMPTY(bb))
     {
         const char *data;
-        apr_bucket *b;
         apr_size_t len;
 
         e = APR_BRIGADE_FIRST(bb);
@@ -1615,8 +1624,7 @@ static apr_status_t inflate_out_filter(a
              * fails, whereas in the deflate case you can empty a filled output
              * buffer and call it again until no more output can be created.
              */
-            flush_libz_buffer(ctx, c, f->c->bucket_alloc, inflate, Z_SYNC_FLUSH,
-                              UPDATE_CRC);
+            flush_libz_buffer(ctx, c, inflate, Z_SYNC_FLUSH, UPDATE_CRC);
             ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01398)
                           "Zlib: Inflated %ld to %ld : URL %s",
                           ctx->stream.total_in, ctx->stream.total_out, r->uri);
@@ -1656,15 +1664,14 @@ static apr_status_t inflate_out_filter(a
              * Okay, we've seen the EOS.
              * Time to pass it along down the chain.
              */
-            return ap_pass_brigade(f->next, ctx->bb);
+            rv = ap_pass_brigade(f->next, ctx->bb);
+            apr_brigade_cleanup(ctx->bb);
+            return rv;
         }
 
         if (APR_BUCKET_IS_FLUSH(e)) {
-            apr_status_t rv;
-
             /* flush the remaining data from the zlib buffers */
-            zRC = flush_libz_buffer(ctx, c, f->c->bucket_alloc, inflate,
-                                    Z_SYNC_FLUSH, UPDATE_CRC);
+            zRC = flush_libz_buffer(ctx, c, inflate, Z_SYNC_FLUSH, UPDATE_CRC);
             if (zRC == Z_STREAM_END) {
                 if (ctx->validation_buffer == NULL) {
                     ctx->validation_buffer = apr_pcalloc(f->r->pool,
@@ -1682,6 +1689,7 @@ static apr_status_t inflate_out_filter(a
             APR_BUCKET_REMOVE(e);
             APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
             rv = ap_pass_brigade(f->next, ctx->bb);
+            apr_brigade_cleanup(ctx->bb);
             if (rv != APR_SUCCESS) {
                 return rv;
             }
@@ -1798,16 +1806,11 @@ static apr_status_t inflate_out_filter(a
 
         while (ctx->stream.avail_in != 0) {
             if (ctx->stream.avail_out == 0) {
-                ctx->stream.next_out = ctx->buffer;
-                len = c->bufferSize - ctx->stream.avail_out;
+                consume_buffer(ctx, c, c->bufferSize, UPDATE_CRC, ctx->bb);
 
-                ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
-                b = apr_bucket_heap_create((char *)ctx->buffer, len,
-                                           NULL, f->c->bucket_alloc);
-                APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
-                ctx->stream.avail_out = c->bufferSize;
                 /* Send what we have right now to the next filter. */
                 rv = ap_pass_brigade(f->next, ctx->bb);
+                apr_brigade_cleanup(ctx->bb);
                 if (rv != APR_SUCCESS) {
                     return rv;
                 }
@@ -1822,6 +1825,7 @@ static apr_status_t inflate_out_filter(a
                 return APR_EGENERAL;
             }
 
+            /* Don't check length limits on inflate_out */
             if (!check_ratio(r, ctx, dc)) {
                 ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(02650)
                               "Inflated content ratio is larger than the "
@@ -1892,6 +1896,8 @@ static const command_rec deflate_filter_
                   "Set the Deflate Memory Level (1-9)"),
     AP_INIT_TAKE1("DeflateCompressionLevel", deflate_set_compressionlevel, NULL, RSRC_CONF,
                   "Set the Deflate Compression Level (1-9)"),
+    AP_INIT_TAKE1("DeflateAlterEtag", deflate_set_etag, NULL, RSRC_CONF,
+                  "Set how mod_deflate should modify ETAG response headers: 'AddSuffix' (default), 'NoChange' (2.2.x behavior), 'Remove'"),
     AP_INIT_TAKE1("DeflateInflateLimitRequestBody", deflate_set_inflate_limit, NULL, OR_ALL,
                   "Set a limit on size of inflated input"),
     AP_INIT_TAKE1("DeflateInflateRatioLimit", deflate_set_inflate_ratio_limit, NULL, OR_ALL,
@@ -1903,6 +1909,10 @@ static const command_rec deflate_filter_
     {NULL}
 };
 
+/* zlib can be built with #define deflate z_deflate */
+#ifdef deflate
+#undef deflate
+#endif
 AP_DECLARE_MODULE(deflate) = {
     STANDARD20_MODULE_STUFF,
     create_deflate_dirconf,       /* dir config creater */

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_ext_filter.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_ext_filter.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_ext_filter.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_ext_filter.c Wed Sep 12 13:56:17 2018
@@ -161,7 +161,7 @@ static const char *parse_cmd(apr_pool_t
 
         ++*args; /* move past leading " */
         /* find true end of args string (accounting for escaped quotes) */
-        while (**args && (**args != '"' || (**args == '"' && escaping))) {
+        while (**args && (**args != '"' || escaping)) {
             if (escaping) {
                 escaping = 0;
             }

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_include.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_include.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_include.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_include.c Wed Sep 12 13:56:17 2018
@@ -1967,25 +1967,25 @@ static apr_status_t handle_echo(include_
                 token = apr_strtok(d, ", \t", &last);
 
                 while (token) {
-                    if (!strcasecmp(token, "none")) {
+                    if (!ap_cstr_casecmp(token, "none")) {
                         /* do nothing */
                     }
-                    else if (!strcasecmp(token, "url")) {
+                    else if (!ap_cstr_casecmp(token, "url")) {
                         char *buf = apr_pstrdup(ctx->pool, echo_text);
                         ap_unescape_url(buf);
                         echo_text = buf;
                     }
-                    else if (!strcasecmp(token, "urlencoded")) {
+                    else if (!ap_cstr_casecmp(token, "urlencoded")) {
                         char *buf = apr_pstrdup(ctx->pool, echo_text);
                         ap_unescape_urlencoded(buf);
                         echo_text = buf;
                     }
-                    else if (!strcasecmp(token, "entity")) {
+                    else if (!ap_cstr_casecmp(token, "entity")) {
                         char *buf = apr_pstrdup(ctx->pool, echo_text);
                         decodehtml(buf);
                         echo_text = buf;
                     }
-                    else if (!strcasecmp(token, "base64")) {
+                    else if (!ap_cstr_casecmp(token, "base64")) {
                         echo_text = ap_pbase64decode(ctx->dpool, echo_text);
                     }
                     else {
@@ -2003,19 +2003,19 @@ static apr_status_t handle_echo(include_
                 token = apr_strtok(e, ", \t", &last);
 
                 while (token) {
-                    if (!strcasecmp(token, "none")) {
+                    if (!ap_cstr_casecmp(token, "none")) {
                         /* do nothing */
                     }
-                    else if (!strcasecmp(token, "url")) {
+                    else if (!ap_cstr_casecmp(token, "url")) {
                         echo_text = ap_escape_uri(ctx->dpool, echo_text);
                     }
-                    else if (!strcasecmp(token, "urlencoded")) {
+                    else if (!ap_cstr_casecmp(token, "urlencoded")) {
                         echo_text = ap_escape_urlencoded(ctx->dpool, echo_text);
                     }
-                    else if (!strcasecmp(token, "entity")) {
+                    else if (!ap_cstr_casecmp(token, "entity")) {
                         echo_text = ap_escape_html2(ctx->dpool, echo_text, 0);
                     }
-                    else if (!strcasecmp(token, "base64")) {
+                    else if (!ap_cstr_casecmp(token, "base64")) {
                         char *buf;
                         buf = ap_pbase64encode(ctx->dpool, (char *)echo_text);
                         echo_text = buf;
@@ -2605,25 +2605,25 @@ static apr_status_t handle_set(include_c
                 token = apr_strtok(d, ", \t", &last);
 
                 while (token) {
-                    if (!strcasecmp(token, "none")) {
+                    if (!ap_cstr_casecmp(token, "none")) {
                         /* do nothing */
                     }
-                    else if (!strcasecmp(token, "url")) {
+                    else if (!ap_cstr_casecmp(token, "url")) {
                         char *buf = apr_pstrdup(ctx->pool, parsed_string);
                         ap_unescape_url(buf);
                         parsed_string = buf;
                     }
-                    else if (!strcasecmp(token, "urlencoded")) {
+                    else if (!ap_cstr_casecmp(token, "urlencoded")) {
                         char *buf = apr_pstrdup(ctx->pool, parsed_string);
                         ap_unescape_urlencoded(buf);
                         parsed_string = buf;
                     }
-                    else if (!strcasecmp(token, "entity")) {
+                    else if (!ap_cstr_casecmp(token, "entity")) {
                         char *buf = apr_pstrdup(ctx->pool, parsed_string);
                         decodehtml(buf);
                         parsed_string = buf;
                     }
-                    else if (!strcasecmp(token, "base64")) {
+                    else if (!ap_cstr_casecmp(token, "base64")) {
                         parsed_string = ap_pbase64decode(ctx->dpool, parsed_string);
                     }
                     else {
@@ -2641,19 +2641,19 @@ static apr_status_t handle_set(include_c
                 token = apr_strtok(e, ", \t", &last);
 
                 while (token) {
-                    if (!strcasecmp(token, "none")) {
+                    if (!ap_cstr_casecmp(token, "none")) {
                         /* do nothing */
                     }
-                    else if (!strcasecmp(token, "url")) {
+                    else if (!ap_cstr_casecmp(token, "url")) {
                         parsed_string = ap_escape_uri(ctx->dpool, parsed_string);
                     }
-                    else if (!strcasecmp(token, "urlencoded")) {
+                    else if (!ap_cstr_casecmp(token, "urlencoded")) {
                         parsed_string = ap_escape_urlencoded(ctx->dpool, parsed_string);
                     }
-                    else if (!strcasecmp(token, "entity")) {
+                    else if (!ap_cstr_casecmp(token, "entity")) {
                         parsed_string = ap_escape_html2(ctx->dpool, parsed_string, 0);
                     }
-                    else if (!strcasecmp(token, "base64")) {
+                    else if (!ap_cstr_casecmp(token, "base64")) {
                         char *buf;
                         buf = ap_pbase64encode(ctx->dpool, (char *)parsed_string);
                         parsed_string = buf;

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_proxy_html.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_proxy_html.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_proxy_html.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_proxy_html.c Wed Sep 12 13:56:17 2018
@@ -108,6 +108,7 @@ typedef struct {
     size_t avail;
     const char *encoding;
     urlmap *map;
+    const char *etag;
     char rbuf[4];
     apr_size_t rlen;
     apr_size_t rmin;
@@ -283,6 +284,33 @@ static void dump_content(saxctxt *ctx)
     }
     AP_fwrite(ctx, ctx->buf, strlen(ctx->buf), 1);
 }
+static void pinternalSubset(void* ctxt, const xmlChar *name,
+                            const xmlChar *externalID, const xmlChar *sysID)
+{
+    saxctxt* ctx = (saxctxt*) ctxt;
+    if (!ctxt || !name) {
+        /* sanity check */
+        return;
+    }
+    if (ctx->cfg->doctype != DEFAULT_DOCTYPE) {
+        /* do nothing if overridden in config */
+        return;
+    }
+    ap_fputstrs(ctx->f->next, ctx->bb, "<!DOCTYPE ", (const char *)name, NULL);
+    if (externalID) {
+        if (!ap_cstr_casecmp((const char*)name, "html") &&
+            !ap_cstr_casecmpn((const char *)externalID, "-//W3C//DTD XHTML ", 18)) {
+            ctx->etag = xhtml_etag;
+        }
+        else {
+            ctx->etag = html_etag;
+        }
+        ap_fputstrs(ctx->f->next, ctx->bb, " PUBLIC \"", (const char *)externalID, "\"", NULL);
+    if (sysID)
+        ap_fputstrs(ctx->f->next, ctx->bb, " \"", (const char *)sysID, "\"", NULL);
+    }
+    ap_fputs(ctx->f->next, ctx->bb, ">\n");
+}
 static void pcdata(void *ctxt, const xmlChar *uchars, int length)
 {
     const char *chars = (const char*) uchars;
@@ -629,7 +657,7 @@ static void pstartElement(void *ctxt, co
     }
     ctx->offset = 0;
     if (desc && desc->empty)
-        ap_fputs(ctx->f->next, ctx->bb, ctx->cfg->etag);
+        ap_fputs(ctx->f->next, ctx->bb, ctx->etag);
     else
         ap_fputc(ctx->f->next, ctx->bb, '>');
 
@@ -660,7 +688,12 @@ static meta *metafix(request_rec *r, con
         while (!apr_isalpha(*++p));
         for (q = p; apr_isalnum(*q) || (*q == '-'); ++q);
         header = apr_pstrmemdup(r->pool, p, q-p);
-        if (strncasecmp(header, "Content-", 8)) {
+        if (!ap_cstr_casecmpn(header, "Content-Type", 12)) {
+            ret = apr_palloc(r->pool, sizeof(meta));
+            ret->start = offs+pmatch[0].rm_so;
+            ret->end = offs+pmatch[0].rm_eo;
+        }
+        else {
             /* find content=... string */
             p = apr_strmatch(seek_content, buf+offs+pmatch[0].rm_so,
                               pmatch[0].rm_eo - pmatch[0].rm_so);
@@ -688,11 +721,6 @@ static meta *metafix(request_rec *r, con
                 }
             }
         }
-        else if (!strncasecmp(header, "Content-Type", 12)) {
-            ret = apr_palloc(r->pool, sizeof(meta));
-            ret->start = offs+pmatch[0].rm_so;
-            ret->end = offs+pmatch[0].rm_eo;
-        }
         if (header && content) {
 #ifndef GO_FASTER
             ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
@@ -817,8 +845,8 @@ static saxctxt *check_filter_init (ap_fi
             else if (!f->r->content_type) {
                 errmsg = "No content-type; bailing out of proxy-html filter";
             }
-            else if (strncasecmp(f->r->content_type, "text/html", 9) &&
-                     strncasecmp(f->r->content_type,
+            else if (ap_cstr_casecmpn(f->r->content_type, "text/html", 9) &&
+                     ap_cstr_casecmpn(f->r->content_type,
                                  "application/xhtml+xml", 21)) {
                 errmsg = "Non-HTML content; not inserting proxy-html filter";
             }
@@ -831,7 +859,6 @@ static saxctxt *check_filter_init (ap_fi
 #ifndef GO_FASTER
             ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, f->r, "%s", errmsg);
 #endif
-            ap_remove_output_filter(f);
             return NULL;
         }
 
@@ -840,6 +867,7 @@ static saxctxt *check_filter_init (ap_fi
         fctx->bb = apr_brigade_create(f->r->pool,
                                       f->r->connection->bucket_alloc);
         fctx->cfg = cfg;
+        fctx->etag = cfg->etag;
         apr_table_unset(f->r->headers_out, "Content-Length");
 
         if (cfg->interp)
@@ -866,41 +894,42 @@ static void prepend_rbuf(saxctxt *ctxt,
 
 static apr_status_t proxy_html_filter(ap_filter_t *f, apr_bucket_brigade *bb)
 {
-    apr_bucket* b;
-    meta *m = NULL;
     xmlCharEncoding enc;
-    const char *buf = 0;
-    apr_size_t bytes = 0;
+    const char *buf;
+    apr_size_t bytes;
 #ifndef USE_OLD_LIBXML2
     int xmlopts = XML_PARSE_RECOVER | XML_PARSE_NONET |
                   XML_PARSE_NOBLANKS | XML_PARSE_NOERROR | XML_PARSE_NOWARNING;
 #endif
 
     saxctxt *ctxt = check_filter_init(f);
-    if (!ctxt)
+    if (!ctxt) {
+        ap_remove_output_filter(f);
         return ap_pass_brigade(f->next, bb);
-    for (b = APR_BRIGADE_FIRST(bb);
-         b != APR_BRIGADE_SENTINEL(bb);
-         b = APR_BUCKET_NEXT(b)) {
+    }
+
+    while (!APR_BRIGADE_EMPTY(bb)) {
+        apr_bucket *b = APR_BRIGADE_FIRST(bb);
+
         if (APR_BUCKET_IS_METADATA(b)) {
             if (APR_BUCKET_IS_EOS(b)) {
                 if (ctxt->parser != NULL) {
                     consume_buffer(ctxt, "", 0, 1);
+                    APR_BRIGADE_PREPEND(bb, ctxt->bb);
                 }
                 else {
-                    prepend_rbuf(ctxt, ctxt->bb);
+                    prepend_rbuf(ctxt, bb);
                 }
-                APR_BRIGADE_INSERT_TAIL(ctxt->bb,
-                    apr_bucket_eos_create(ctxt->bb->bucket_alloc));
-                ap_pass_brigade(ctxt->f->next, ctxt->bb);
-                apr_brigade_cleanup(ctxt->bb);
+                ap_remove_output_filter(f);
+                return ap_pass_brigade(f->next, bb);
             }
             else if (APR_BUCKET_IS_FLUSH(b)) {
                 /* pass on flush, except at start where it would cause
                  * headers to be sent before doc sniffing
                  */
                 if (ctxt->parser != NULL) {
-                    ap_fflush(ctxt->f->next, ctxt->bb);
+                    ap_fflush(f->next, ctxt->bb);
+                    apr_brigade_cleanup(ctxt->bb);
                 }
             }
         }
@@ -917,6 +946,7 @@ static apr_status_t proxy_html_filter(ap
                 if (ctxt->rmin < sizeof(ctxt->rbuf)) {
                     memcpy(ctxt->rbuf + ctxt->rlen, buf, bytes);
                     ctxt->rlen += bytes;
+                    apr_bucket_delete(b);
                     continue;
                 }
                 if (ctxt->rlen && ctxt->rlen < sizeof(ctxt->rbuf)) {
@@ -980,27 +1010,28 @@ static apr_status_t proxy_html_filter(ap
                     ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, f->r, APLOGNO(01423)
                                   "Unsupported parser opts %x", xmlopts);
 #endif
-                if (ctxt->cfg->metafix)
-                    m = metafix(f->r, buf, bytes);
+                if (ctxt->cfg->metafix) {
+                    meta *m = metafix(f->r, buf, bytes);
                 if (m) {
                     consume_buffer(ctxt, buf, m->start, 0);
-                    consume_buffer(ctxt, buf+m->end, bytes-m->end, 0);
+                        buf += m->end;
+                        bytes -= m->end;
                 }
-                else {
-                    consume_buffer(ctxt, buf, bytes, 0);
                 }
             }
-            else {
                 consume_buffer(ctxt, buf, bytes, 0);
             }
-        }
         else {
             ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r, APLOGNO(01424)
                           "Error in bucket read");
         }
+
+        apr_bucket_delete(b);
     }
-    /*ap_fflush(ctxt->f->next, ctxt->bb);        // uncomment for debug */
-    apr_brigade_cleanup(bb);
+#if 0  /* uncomment for debug */
+    ap_fflush(f->next, ctxt->bb);
+    apr_brigade_cleanup(ctxt->bb);
+#endif
     return APR_SUCCESS;
 }
 
@@ -1167,7 +1198,10 @@ static const char *set_doctype(cmd_parms
                                const char *t, const char *l)
 {
     proxy_html_conf *cfg = (proxy_html_conf *)CFG;
-    if (!strcasecmp(t, "xhtml")) {
+    if (!strcasecmp(t, "auto")) {
+        cfg->doctype = DEFAULT_DOCTYPE; /* activates pinternalSubset */
+    }
+    else if (!strcasecmp(t, "xhtml")) {
         cfg->etag = xhtml_etag;
         if (l && !strcasecmp(l, "legacy"))
             cfg->doctype = fpi_xhtml_legacy;
@@ -1287,6 +1321,7 @@ static int mod_proxy_html(apr_pool_t *p,
     sax.characters = pcharacters;
     sax.comment = pcomment;
     sax.cdataBlock = pcdata;
+    sax.internalSubset = pinternalSubset;
     xml2enc_charset = APR_RETRIEVE_OPTIONAL_FN(xml2enc_charset);
     xml2enc_filter = APR_RETRIEVE_OPTIONAL_FN(xml2enc_filter);
     if (!xml2enc_charset) {

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_proxy_html.dsp
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_proxy_html.dsp?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_proxy_html.dsp (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_proxy_html.dsp Wed Sep 12 13:56:17 2018
@@ -79,7 +79,7 @@ PostBuild_Cmds=if exist $(TargetPath).ma
 # ADD BASE MTL /nologo /D "_DEBUG" /win32
 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
 # ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG" /i "../../include" /i "../../srclib/apr/include" /I "../../srclib/apr-util/include" /i "../../srclib/libxml2/include" /d BIN_NAME="mod_proxy_html.so" /d LONG_NAME="proxy_html_module for Apache" 
+# ADD RSC /l 0x409 /i /d "_DEBUG" "../../include" /i "../../srclib/apr/include" /I "../../srclib/apr-util/include" /i "../../srclib/libxml2/include" /d BIN_NAME="mod_proxy_html.so" /d LONG_NAME="proxy_html_module for Apache" 
 BSC32=bscmake.exe
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_sed.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_sed.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_sed.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_sed.c Wed Sep 12 13:56:17 2018
@@ -59,7 +59,7 @@ typedef struct sed_filter_ctxt
 module AP_MODULE_DECLARE_DATA sed_module;
 
 /* This function will be call back from libsed functions if there is any error
- * happend during execution of sed scripts
+ * happened during execution of sed scripts
  */
 static apr_status_t log_sed_errf(void *data, const char *error)
 {
@@ -268,7 +268,7 @@ static apr_status_t sed_response_filter(
                                         apr_bucket_brigade *bb)
 {
     apr_bucket *b;
-    apr_status_t status;
+    apr_status_t status = APR_SUCCESS;
     sed_config *cfg = ap_get_module_config(f->r->per_dir_config,
                                            &sed_module);
     sed_filter_ctxt *ctx = f->ctx;
@@ -293,9 +293,9 @@ static apr_status_t sed_response_filter(
              return status;
         ctx = f->ctx;
         apr_table_unset(f->r->headers_out, "Content-Length");
-    }
 
     ctx->bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);
+    }
 
     /* Here is the main logic. Iterate through all the buckets, read the
      * content of the bucket, call sed_eval_buffer on the data.
@@ -317,63 +317,51 @@ static apr_status_t sed_response_filter(
      * in sed's internal buffer which can't be flushed until new line
      * character is arrived.
      */
-    for (b = APR_BRIGADE_FIRST(bb); b != APR_BRIGADE_SENTINEL(bb);) {
-        const char *buf = NULL;
-        apr_size_t bytes = 0;
+    while (!APR_BRIGADE_EMPTY(bb)) {
+        b = APR_BRIGADE_FIRST(bb);
         if (APR_BUCKET_IS_EOS(b)) {
-            apr_bucket *b1 = APR_BUCKET_NEXT(b);
             /* Now clean up the internal sed buffer */
             sed_finalize_eval(&ctx->eval, ctx);
             status = flush_output_buffer(ctx);
             if (status != APR_SUCCESS) {
-                clear_ctxpool(ctx);
-                return status;
+                break;
             }
+            /* Move the eos bucket to ctx->bb brigade */
             APR_BUCKET_REMOVE(b);
-            /* Insert the eos bucket to ctx->bb brigade */
             APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
-            b = b1;
         }
         else if (APR_BUCKET_IS_FLUSH(b)) {
-            apr_bucket *b1 = APR_BUCKET_NEXT(b);
-            APR_BUCKET_REMOVE(b);
             status = flush_output_buffer(ctx);
             if (status != APR_SUCCESS) {
-                clear_ctxpool(ctx);
-                return status;
+                break;
             }
+            /* Move the flush bucket to ctx->bb brigade */
+            APR_BUCKET_REMOVE(b);
             APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
-            b = b1;
         }
-        else if (APR_BUCKET_IS_METADATA(b)) {
-            b = APR_BUCKET_NEXT(b);
+        else {
+            if (!APR_BUCKET_IS_METADATA(b)) {
+                const char *buf = NULL;
+                apr_size_t bytes = 0;
+
+                status = apr_bucket_read(b, &buf, &bytes, APR_BLOCK_READ);
+                if (status == APR_SUCCESS) {
+                    status = sed_eval_buffer(&ctx->eval, buf, bytes, ctx);
         }
-        else if (apr_bucket_read(b, &buf, &bytes, APR_BLOCK_READ)
-                 == APR_SUCCESS) {
-            apr_bucket *b1 = APR_BUCKET_NEXT(b);
-            status = sed_eval_buffer(&ctx->eval, buf, bytes, ctx);
             if (status != APR_SUCCESS) {
-                clear_ctxpool(ctx);
-                return status;
+                    break;
+            }
             }
-            APR_BUCKET_REMOVE(b);
             apr_bucket_delete(b);
-            b = b1;
         }
-        else {
-            apr_bucket *b1 = APR_BUCKET_NEXT(b);
-            APR_BUCKET_REMOVE(b);
-            b = b1;
         }
-    }
-    apr_brigade_cleanup(bb);
+    if (status == APR_SUCCESS) {
     status = flush_output_buffer(ctx);
-    if (status != APR_SUCCESS) {
-        clear_ctxpool(ctx);
-        return status;
     }
     if (!APR_BRIGADE_EMPTY(ctx->bb)) {
+        if (status == APR_SUCCESS) {
         status = ap_pass_brigade(f->next, ctx->bb);
+        }
         apr_brigade_cleanup(ctx->bb);
     }
     clear_ctxpool(ctx);

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_substitute.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_substitute.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_substitute.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_substitute.c Wed Sep 12 13:56:17 2018
@@ -30,6 +30,7 @@
 #include "util_varbuf.h"
 #include "apr_buckets.h"
 #include "http_request.h"
+#include "ap_expr.h"
 #define APR_WANT_STRFUNC
 #include "apr_want.h"
 
@@ -52,6 +53,7 @@ typedef struct subst_pattern_t {
     apr_size_t patlen;
     int flatten;
     const char *from;
+    ap_expr_info_t* expr_replacement;
 } subst_pattern_t;
 
 typedef struct {
@@ -69,6 +71,11 @@ typedef struct {
     apr_pool_t *tpool;
 } substitute_module_ctx;
 
+typedef struct { 
+    const char **expcache;
+    int *expcache_len;
+} subst_req_t;
+
 static void *create_substitute_dcfg(apr_pool_t *p, char *d)
 {
     subst_dir_conf *dcfg =
@@ -97,7 +104,7 @@ static void *merge_substitute_dcfg(apr_p
      * In later 2.2 and 2.4 versions, SubstituteInheritBefore may be toggled
      * 'on' to follow the corrected/expected behavior, without violating POLS.
      */
-    if (a->inherit_before == 1) {
+    if (a->inherit_before) {
         a->patterns = apr_array_append(p, base->patterns,
                                           over->patterns);
     }
@@ -137,11 +144,14 @@ static apr_status_t do_pattmatch(ap_filt
     struct ap_varbuf vb;
     apr_bucket *b;
     apr_bucket *tmp_b;
+    subst_pattern_t *script;
 
     subst_dir_conf *cfg =
     (subst_dir_conf *) ap_get_module_config(f->r->per_dir_config,
                                              &substitute_module);
-    subst_pattern_t *script;
+    subst_req_t *rconf = 
+    (subst_req_t*) ap_get_module_config(f->r->request_config, 
+                                        &substitute_module);
 
     APR_BRIGADE_INSERT_TAIL(mybb, inb);
     ap_varbuf_init(pool, &vb, 0);
@@ -155,6 +165,16 @@ static apr_status_t do_pattmatch(ap_filt
        force_quick = 1;
     }
     for (i = 0; i < cfg->patterns->nelts; i++) {
+        const char *replacement = script->replacement;
+        apr_size_t replen = script->replen;
+        if (script->expr_replacement) { 
+            if (!rconf) { 
+                rconf = apr_pcalloc(f->r->pool, sizeof(*rconf));
+                rconf->expcache     = apr_pcalloc(f->r->pool, sizeof(const char*) * cfg->patterns->nelts);
+                rconf->expcache_len = apr_pcalloc(f->r->pool, sizeof(int) * cfg->patterns->nelts);
+                ap_set_module_config(f->r->request_config, &substitute_module, rconf);
+            }
+        }
         for (b = APR_BRIGADE_FIRST(mybb);
              b != APR_BRIGADE_SENTINEL(mybb);
              b = APR_BUCKET_NEXT(b)) {
@@ -187,12 +207,26 @@ static apr_status_t do_pattmatch(ap_filt
                      * line length reaches max_line_length.
                      */
                     apr_size_t space_left = cfg->max_line_length;
-                    apr_size_t repl_len = strlen(script->replacement);
                     while ((repl = apr_strmatch(script->pattern, buff, bytes)))
                     {
+                        
+                        if (!have_match && script->expr_replacement) { 
+                            if (!rconf->expcache[i]) {
+                                const char *err = NULL;
+                                rconf->expcache[i] = ap_expr_str_exec(f->r, script->expr_replacement, &err);
+                                if (err) { 
+                                    ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r, "error evaluating expression: %s", err);
+                                    return APR_EINVAL;
+                                }
+                                rconf->expcache_len[i] = strlen(rconf->expcache[i]);
+                            }
+                            replacement = rconf->expcache[i];
+                            replen      = rconf->expcache_len[i];
+                        }
+
                         ap_log_rerror(APLOG_MARK, APLOG_TRACE8, 0, f->r,
                                       "Matching found, result: '%s'",
-                                      script->replacement);
+                                      replacement);
                         have_match = 1;
                         /* get offset into buff for pattern */
                         len = (apr_size_t) (repl - buff);
@@ -205,10 +239,10 @@ static apr_status_t do_pattmatch(ap_filt
                              * are constanting allocing space and copying
                              * strings.
                              */
-                            if (vb.strlen + len + repl_len > cfg->max_line_length)
+                            if (vb.strlen + len + replen > cfg->max_line_length)
                                 return APR_ENOMEM;
                             ap_varbuf_strmemcat(&vb, buff, len);
-                            ap_varbuf_strmemcat(&vb, script->replacement, repl_len);
+                            ap_varbuf_strmemcat(&vb, replacement, replen);
                         }
                         else {
                             /*
@@ -217,9 +251,9 @@ static apr_status_t do_pattmatch(ap_filt
                              * Check if we still have space for this string and
                              * the replacement string.
                              */
-                            if (space_left < len + repl_len)
+                            if (space_left < len + replen)
                                 return APR_ENOMEM;
-                            space_left -= len + repl_len;
+                            space_left -= len + replen;
                             /*
                              * We now split off the string before the match
                              * as its own bucket, then isolate the matched
@@ -230,8 +264,8 @@ static apr_status_t do_pattmatch(ap_filt
                              * Finally, we create a bucket that contains the
                              * replacement...
                              */
-                            tmp_b = apr_bucket_transient_create(script->replacement,
-                                      script->replen,
+                            tmp_b = apr_bucket_transient_create(replacement,
+                                      replen,
                                       f->r->connection->bucket_alloc);
                             /* ... and insert it */
                             APR_BUCKET_INSERT_BEFORE(b, tmp_b);
@@ -282,6 +316,20 @@ static apr_status_t do_pattmatch(ap_filt
                     while (!ap_regexec_len(script->regexp, pos, left,
                                        AP_MAX_REG_MATCH, regm, 0)) {
                         apr_status_t rv;
+                        if (!have_match && script->expr_replacement) {
+                            if (!rconf->expcache[i]) {
+                                const char *err = NULL;
+                                rconf->expcache[i] = ap_expr_str_exec(f->r, script->expr_replacement, &err);
+                                if (err) {
+                                    ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r, "error evaluating expression: %s", err);
+                                    return APR_EGENERAL;
+                                }
+                                rconf->expcache_len[i] = strlen(rconf->expcache[i]);
+                            }
+                            replacement = rconf->expcache[i];
+                            replen      = rconf->expcache_len[i];
+                        }
+
                         ap_log_rerror(APLOG_MARK, APLOG_TRACE8, 0, f->r,
                                       "Matching found");
                         have_match = 1;
@@ -296,7 +344,7 @@ static apr_status_t do_pattmatch(ap_filt
                             if (regm[0].rm_so > 0)
                                 ap_varbuf_strmemcat(&vb, pos, regm[0].rm_so);
                             /* add replacement string, last argument is unsigned! */
-                            rv = ap_varbuf_regsub(&vb, script->replacement, pos,
+                            rv = ap_varbuf_regsub(&vb, replacement, pos,
                                                   AP_MAX_REG_MATCH, regm,
                                                   cfg->max_line_length - vb.strlen);
                             if (rv != APR_SUCCESS)
@@ -311,7 +359,7 @@ static apr_status_t do_pattmatch(ap_filt
                                 return APR_ENOMEM;
                             space_left -= regm[0].rm_so;
                             rv = ap_pregsub_ex(pool, &repl,
-                                               script->replacement, pos,
+                                               replacement, pos,
                                                AP_MAX_REG_MATCH, regm,
                                                space_left);
                             if (rv != APR_SUCCESS)
@@ -463,6 +511,7 @@ static apr_status_t substitute_filter(ap
             }
             APR_BUCKET_REMOVE(b);
             APR_BRIGADE_INSERT_TAIL(ctx->passbb, b);
+            ap_remove_output_filter(f);
         }
         /*
          * No need to handle FLUSH buckets separately as we call
@@ -691,6 +740,18 @@ static const char *set_pattern(cmd_parms
 
     nscript->replacement = to;
     nscript->replen = strlen(to);
+
+    if (!strncasecmp(to, "expr=", 5)) { 
+        const char *err;
+        nscript->expr_replacement = ap_expr_parse_cmd(cmd, to+5,
+                                          AP_EXPR_FLAG_STRING_RESULT,
+                                          &err, NULL);
+        if (err) {
+            return apr_pstrcat(cmd->pool,
+                    "Can't parse value expression : ", err, NULL);
+        }
+    } 
+
     nscript->flatten = flatten;
 
     return NULL;

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_xml2enc.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_xml2enc.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_xml2enc.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_xml2enc.c Wed Sep 12 13:56:17 2018
@@ -245,7 +245,13 @@ static void sniff_encoding(request_rec*
         cfg = ap_get_module_config(r->per_dir_config, &xml2enc_module);
         if (!ctx->encoding) {
             ctx->encoding = cfg->default_charset?cfg->default_charset:"ISO-8859-1";
+            ctx->xml2enc = xmlParseCharEncoding(ctx->encoding);
         }
+    }
+    /* Test again: this fallback is only appropriate if we couldn't
+     * just fall back to the configuration default.
+     */
+    if (!HAVE_ENCODING(ctx->xml2enc)) {
         /* Unsupported charset. Can we get (iconv) support through apr_xlate? */
         ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01434)
                       "Charset %s not supported by libxml2; trying apr_xlate",

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_xml2enc.dsp
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_xml2enc.dsp?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_xml2enc.dsp (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/mod_xml2enc.dsp Wed Sep 12 13:56:17 2018
@@ -79,7 +79,7 @@ PostBuild_Cmds=if exist $(TargetPath).ma
 # ADD BASE MTL /nologo /D "_DEBUG" /win32
 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
 # ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG" /i "../../include" /i "../../srclib/apr/include" /i "../../srclib/apr-util/include" /i "../../srclib/libxml2/include" /d BIN_NAME="mod_xml2enc.so" /d LONG_NAME="xml2enc_module for Apache"
+# ADD RSC /l 0x409 /i /d "_DEBUG" "../../include" /i "../../srclib/apr/include" /i "../../srclib/apr-util/include" /i "../../srclib/libxml2/include" /d BIN_NAME="mod_xml2enc.so" /d LONG_NAME="xml2enc_module for Apache"
 BSC32=bscmake.exe
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/sed1.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/sed1.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/sed1.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/filters/sed1.c Wed Sep 12 13:56:17 2018
@@ -719,9 +719,11 @@ static apr_status_t command(sed_eval_t *
                 rv = wline(eval, ipc->re1, p1 - ipc->re1);
             }
             break;
+
         case DCOM:
             eval->delflag++;
             break;
+
         case CDCOM:
             p1 = eval->linebuf;
 
@@ -769,12 +771,11 @@ static apr_status_t command(sed_eval_t *
             eval->jflag = 1;
             break;
 
-
         case LCOM:
             p1 = eval->linebuf;
             p2 = eval->genbuf;
             eval->genbuf[72] = 0;
-            while(*p1)
+            while (*p1) {
                 if((unsigned char)*p1 >= 040) {
                     if(*p1 == 0177) {
                         p3 = rub;
@@ -853,6 +854,7 @@ static apr_status_t command(sed_eval_t *
                     p2--;
                     p1++;
                 }
+            }
             *p2 = 0;
             rv = wline(eval, eval->genbuf, strlen(eval->genbuf));
             break;
@@ -871,8 +873,8 @@ static apr_status_t command(sed_eval_t *
             }
             eval->lspend = eval->linebuf;
             eval->pending = ipc->next;
-
             break;
+
         case CNCOM:
             if(eval->aptr > eval->abuf) {
                 rv = arout(eval);
@@ -886,6 +888,7 @@ static apr_status_t command(sed_eval_t *
         case PCOM:
             rv = wline(eval, eval->linebuf, eval->lspend - eval->linebuf);
             break;
+
         case CPCOM:
             for (p1 = eval->linebuf; *p1 != '\n' && *p1 != '\0'; p1++);
             rv = wline(eval, eval->linebuf, p1 - eval->linebuf);
@@ -906,6 +909,7 @@ static apr_status_t command(sed_eval_t *
 
             eval->quitflag = 1;
             break;
+
         case RCOM:
             if(eval->aptr >= &eval->abuf[SED_ABUFSIZE]) {
                 eval_errf(eval, SEDERR_TMRMES, eval->lnum);
@@ -949,6 +953,7 @@ static apr_status_t command(sed_eval_t *
                 apr_file_printf(eval->fcode[ipc->findex], "%s\n",
                                 eval->linebuf);
             break;
+
         case XCOM:
             copy_to_genbuf(eval, eval->linebuf);
             copy_to_linebuf(eval, eval->holdbuf);

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUautoindex
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUautoindex?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUautoindex (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUautoindex Wed Sep 12 13:56:17 2018
@@ -18,8 +18,8 @@ endif
 XINCDIRS	+= \
 			$(APR)/include \
 			$(APRUTIL)/include \
-			$(AP_WORK)/include \
-			$(AP_WORK)/modules/http \
+			$(SRC)/include \
+			$(STDMOD)/http \
 			$(NWOS) \
 			$(EOLIST)
 

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUinfo
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUinfo?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUinfo (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUinfo Wed Sep 12 13:56:17 2018
@@ -18,7 +18,7 @@ endif
 XINCDIRS	+= \
 			$(APR)/include \
 			$(APRUTIL)/include \
-			$(AP_WORK)/include \
+			$(SRC)/include \
 			$(NWOS) \
 			$(EOLIST)
 

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUmod_asis
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUmod_asis?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUmod_asis (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUmod_asis Wed Sep 12 13:56:17 2018
@@ -18,8 +18,8 @@ endif
 XINCDIRS	+= \
 			$(APR)/include \
 			$(APRUTIL)/include \
-			$(AP_WORK)/include \
-			$(AP_WORK)/modules/http \
+			$(SRC)/include \
+			$(STDMOD)/http \
 			$(NWOS) \
 			$(EOLIST)
 

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUmod_cgi
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUmod_cgi?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUmod_cgi (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUmod_cgi Wed Sep 12 13:56:17 2018
@@ -18,9 +18,9 @@ endif
 XINCDIRS	+= \
 			$(APR)/include \
 			$(APRUTIL)/include \
-			$(AP_WORK)/include \
-			$(AP_WORK)/modules/http \
-			$(AP_WORK)/modules/filters \
+			$(SRC)/include \
+			$(STDMOD)/http \
+			$(STDMOD)/filters \
 			$(NWOS) \
 			$(EOLIST)
 

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUstatus
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUstatus?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUstatus (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/NWGNUstatus Wed Sep 12 13:56:17 2018
@@ -18,7 +18,7 @@ endif
 XINCDIRS	+= \
 			$(APR)/include \
 			$(APRUTIL)/include \
-			$(AP_WORK)/include \
+			$(SRC)/include \
 			$(NWOS) \
 			$(EOLIST)
 

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/config5.m4
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/config5.m4?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/config5.m4 (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/config5.m4 Wed Sep 12 13:56:17 2018
@@ -9,7 +9,7 @@ APACHE_MODULE(autoindex, directory listi
 APACHE_MODULE(asis, as-is filetypes, , , )
 APACHE_MODULE(info, server information, , , most)
 APACHE_MODULE(suexec, set uid and gid for spawned processes, , , no, [
-              other_targets=suexec ] )
+              other_targets="$other_targets suexec" ] )
 
 # Is mod_cgid needed?
 case $host in

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_autoindex.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_autoindex.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_autoindex.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_autoindex.c Wed Sep 12 13:56:17 2018
@@ -1070,7 +1070,7 @@ static void emit_head(request_rec *r, ch
                     emit_H1 = 1;
                 }
             }
-            else if (!strncasecmp("text/", rr->content_type, 5)) {
+            else if (!ap_cstr_casecmpn("text/", rr->content_type, 5)) {
                 /*
                  * If we can open the file, prefix it with the preamble
                  * regardless; since we'll be sending a <pre> block around
@@ -1165,7 +1165,7 @@ static void emit_tail(request_rec *r, ch
                     suppress_post = suppress_amble;
                 }
             }
-            else if (!strncasecmp("text/", rr->content_type, 5)) {
+            else if (!ap_cstr_casecmpn("text/", rr->content_type, 5)) {
                 /*
                  * If we can open the file, suppress the signature.
                  */

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_cgi.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_cgi.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_cgi.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_cgi.c Wed Sep 12 13:56:17 2018
@@ -92,6 +92,10 @@ typedef struct {
     apr_size_t  bufbytes;
 } cgi_server_conf;
 
+typedef struct {
+    apr_interval_time_t timeout;
+} cgi_dirconf;
+
 static void *create_cgi_config(apr_pool_t *p, server_rec *s)
 {
     cgi_server_conf *c =
@@ -112,6 +116,12 @@ static void *merge_cgi_config(apr_pool_t
     return overrides->logname ? overrides : base;
 }
 
+static void *create_cgi_dirconf(apr_pool_t *p, char *dummy)
+{
+    cgi_dirconf *c = (cgi_dirconf *) apr_pcalloc(p, sizeof(cgi_dirconf));
+    return c;
+}
+
 static const char *set_scriptlog(cmd_parms *cmd, void *dummy, const char *arg)
 {
     server_rec *s = cmd->server;
@@ -150,6 +160,17 @@ static const char *set_scriptlog_buffer(
     return NULL;
 }
 
+static const char *set_script_timeout(cmd_parms *cmd, void *dummy, const char *arg)
+{
+    cgi_dirconf *dc = dummy;
+
+    if (ap_timeout_parameter_parse(arg, &dc->timeout, "s") != APR_SUCCESS) {
+        return "CGIScriptTimeout has wrong format";
+    }
+
+    return NULL;
+}
+
 static const command_rec cgi_cmds[] =
 {
 AP_INIT_TAKE1("ScriptLog", set_scriptlog, NULL, RSRC_CONF,
@@ -158,6 +179,9 @@ AP_INIT_TAKE1("ScriptLogLength", set_scr
      "the maximum length (in bytes) of the script debug log"),
 AP_INIT_TAKE1("ScriptLogBuffer", set_scriptlog_buffer, NULL, RSRC_CONF,
      "the maximum size (in bytes) to record of a POST request"),
+AP_INIT_TAKE1("CGIScriptTimeout", set_script_timeout, NULL, RSRC_CONF | ACCESS_CONF,
+     "The amount of time to wait between successful reads from "
+     "the CGI script, in seconds."),
     {NULL}
 };
 
@@ -167,12 +191,11 @@ static int log_scripterror(request_rec *
     apr_file_t *f = NULL;
     apr_finfo_t finfo;
     char time_str[APR_CTIME_LEN];
-    int log_flags = rv ? APLOG_ERR : APLOG_ERR;
 
     /* Intentional no APLOGNO */
     /* Callee provides APLOGNO in error text */
-    ap_log_rerror(APLOG_MARK, log_flags, rv, r,
-                  "%s%s: %s", logno ? logno : "", error, r->filename);
+    ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
+                  "%sstderr from %s: %s", logno ? logno : "", r->filename, error);
 
     /* XXX Very expensive mainline case! Open, then getfileinfo! */
     if (!conf->logname ||
@@ -209,8 +232,14 @@ static apr_status_t log_script_err(reque
 
     while ((rv = apr_file_gets(argsbuffer, HUGE_STRING_LEN,
                                script_err)) == APR_SUCCESS) {
+
         newline = strchr(argsbuffer, '\n');
         if (newline) {
+            char *prev = newline - 1;
+            if (prev >= argsbuffer && *prev == '\r') {
+                newline = prev;
+            }
+
             *newline = '\0';
         }
         log_scripterror(r, conf, r->status, 0, APLOGNO(01215), argsbuffer);
@@ -466,23 +495,26 @@ static apr_status_t run_cgi_child(apr_fi
                           apr_filepath_name_get(r->filename));
         }
         else {
+            cgi_dirconf *dc = ap_get_module_config(r->per_dir_config, &cgi_module);
+            apr_interval_time_t timeout = dc->timeout > 0 ? dc->timeout : r->server->timeout;
+
             apr_pool_note_subprocess(p, procnew, APR_KILL_AFTER_TIMEOUT);
 
             *script_in = procnew->out;
             if (!*script_in)
                 return APR_EBADF;
-            apr_file_pipe_timeout_set(*script_in, r->server->timeout);
+            apr_file_pipe_timeout_set(*script_in, timeout);
 
             if (e_info->prog_type == RUN_AS_CGI) {
                 *script_out = procnew->in;
                 if (!*script_out)
                     return APR_EBADF;
-                apr_file_pipe_timeout_set(*script_out, r->server->timeout);
+                apr_file_pipe_timeout_set(*script_out, timeout);
 
                 *script_err = procnew->err;
                 if (!*script_err)
                     return APR_EBADF;
-                apr_file_pipe_timeout_set(*script_err, r->server->timeout);
+                apr_file_pipe_timeout_set(*script_err, timeout);
             }
         }
     }
@@ -679,11 +711,14 @@ static apr_status_t cgi_bucket_read(apr_
                                     apr_size_t *len, apr_read_type_e block)
 {
     struct cgi_bucket_data *data = b->data;
-    apr_interval_time_t timeout;
+    apr_interval_time_t timeout = 0;
     apr_status_t rv;
     int gotdata = 0;
+    cgi_dirconf *dc = ap_get_module_config(data->r->per_dir_config, &cgi_module);
 
-    timeout = block == APR_NONBLOCK_READ ? 0 : data->r->server->timeout;
+    if (block != APR_NONBLOCK_READ) {
+        timeout = dc->timeout > 0 ? dc->timeout : data->r->server->timeout;
+    }
 
     do {
         const apr_pollfd_t *results;
@@ -761,6 +796,8 @@ static int cgi_handler(request_rec *r)
     apr_status_t rv;
     cgi_exec_info_t e_info;
     conn_rec *c;
+    cgi_dirconf *dc = ap_get_module_config(r->per_dir_config, &cgi_module);
+    apr_interval_time_t timeout = dc->timeout > 0 ? dc->timeout : r->server->timeout;
 
     if (strcmp(r->handler, CGI_MAGIC_TYPE) && strcmp(r->handler, "cgi-script")) {
         return DECLINED;
@@ -980,7 +1017,7 @@ static int cgi_handler(request_rec *r)
              * stderr output, as normal. */
             discard_script_output(bb);
             apr_brigade_destroy(bb);
-            apr_file_pipe_timeout_set(script_err, r->server->timeout);
+            apr_file_pipe_timeout_set(script_err, timeout);
             log_script_err(r, script_err);
         }
 
@@ -1031,7 +1068,7 @@ static int cgi_handler(request_rec *r)
      * connection drops or we stopped sending output for some other
      * reason */
     if (rv == APR_SUCCESS && !r->connection->aborted) {
-        apr_file_pipe_timeout_set(script_err, r->server->timeout);
+        apr_file_pipe_timeout_set(script_err, timeout);
         log_script_err(r, script_err);
     }
 
@@ -1272,7 +1309,7 @@ static void register_hooks(apr_pool_t *p
 AP_DECLARE_MODULE(cgi) =
 {
     STANDARD20_MODULE_STUFF,
-    NULL,                        /* dir config creater */
+    create_cgi_dirconf,          /* dir config creater */
     NULL,                        /* dir merger --- default is to override */
     create_cgi_config,           /* server config */
     merge_cgi_config,            /* merge server config */

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_info.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_info.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_info.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_info.c Wed Sep 12 13:56:17 2018
@@ -80,9 +80,9 @@ typedef struct
 module AP_MODULE_DECLARE_DATA info_module;
 
 /* current file name when doing -DDUMP_CONFIG */
-const char *dump_config_fn_info;
+static const char *dump_config_fn_info;
 /* file handle when doing -DDUMP_CONFIG */
-apr_file_t *out = NULL;
+static apr_file_t *out = NULL;
 
 static void *create_info_config(apr_pool_t * p, server_rec * s)
 {
@@ -297,7 +297,7 @@ typedef struct
     hook_get_t get;
 } hook_lookup_t;
 
-static hook_lookup_t startup_hooks[] = {
+static const hook_lookup_t startup_hooks[] = {
     {"Pre-Config", ap_hook_get_pre_config},
     {"Check Configuration", ap_hook_get_check_config},
     {"Test Configuration", ap_hook_get_test_config},
@@ -311,7 +311,7 @@ static hook_lookup_t startup_hooks[] = {
     {NULL},
 };
 
-static hook_lookup_t request_hooks[] = {
+static const hook_lookup_t request_hooks[] = {
     {"Pre-Connection", ap_hook_get_pre_connection},
     {"Create Connection", ap_hook_get_create_connection},
     {"Process Connection", ap_hook_get_process_connection},
@@ -339,7 +339,7 @@ static hook_lookup_t request_hooks[] = {
     {NULL},
 };
 
-static hook_lookup_t other_hooks[] = {
+static const hook_lookup_t other_hooks[] = {
     {"Monitor", ap_hook_get_monitor},
     {"Child Status", ap_hook_get_child_status},
     {"End Generation", ap_hook_get_end_generation},
@@ -378,7 +378,7 @@ static int module_find_hook(module * mod
 
 static void module_participate(request_rec * r,
                                module * modp,
-                               hook_lookup_t * lookup, int *comma)
+                               const hook_lookup_t *lookup, int *comma)
 {
     if (module_find_hook(modp, lookup->get)) {
         if (*comma) {
@@ -454,6 +454,12 @@ static int show_server_settings(request_
                "<tt>%s</tt></dt>\n", APU_VERSION_STRING);
 #endif
     ap_rprintf(r,
+               "<dt><strong>Server loaded PCRE Version:</strong> "
+               "<tt>%s</tt></dt>\n", ap_pcre_version_string(AP_REG_PCRE_LOADED));
+    ap_rprintf(r,
+               "<dt><strong>Compiled with PCRE Version:</strong> "
+               "<tt>%s</tt></dt>\n", ap_pcre_version_string(AP_REG_PCRE_COMPILED));
+    ap_rprintf(r,
                "<dt><strong>Module Magic Number:</strong> "
                "<tt>%d:%d</tt></dt>\n", MODULE_MAGIC_NUMBER_MAJOR,
                MODULE_MAGIC_NUMBER_MINOR);
@@ -785,7 +791,7 @@ static int display_info(request_rec * r)
              "  <title>Server Information</title>\n" "</head>\n", r);
     ap_rputs("<body><h1 style=\"text-align: center\">"
              "Apache Server Information</h1>\n", r);
-    if (!r->args || strcasecmp(r->args, "list")) {
+    if (!r->args || ap_cstr_casecmp(r->args, "list")) {
         if (!r->args) {
             ap_rputs("<dl><dt><tt>Subpages:<br />", r);
             ap_rputs("<a href=\"?config\">Configuration Files</a>, "
@@ -819,19 +825,19 @@ static int display_info(request_rec * r)
             ap_rputs("</tt></dt></dl><hr />", r);
         }
 
-        if (!r->args || !strcasecmp(r->args, "server")) {
+        if (!r->args || !ap_cstr_casecmp(r->args, "server")) {
             show_server_settings(r);
         }
 
-        if (!r->args || !strcasecmp(r->args, "hooks")) {
+        if (!r->args || !ap_cstr_casecmp(r->args, "hooks")) {
             show_active_hooks(r);
         }
 
-        if (!r->args || !strcasecmp(r->args, "providers")) {
+        if (!r->args || !ap_cstr_casecmp(r->args, "providers")) {
             show_providers(r);
         }
 
-        if (r->args && 0 == strcasecmp(r->args, "config")) {
+        if (r->args && 0 == ap_cstr_casecmp(r->args, "config")) {
             ap_rputs("<dl><dt><strong>Configuration:</strong>\n", r);
             mod_info_module_cmds(r, NULL, ap_conftree, 0, 0);
             ap_rputs("</dl><hr />", r);
@@ -842,7 +848,7 @@ static int display_info(request_rec * r)
                  modules = get_sorted_modules(r->pool);
             for (i = 0; i < modules->nelts; i++) {
                 modp = APR_ARRAY_IDX(modules, i, module *);
-                if (!r->args || !strcasecmp(modp->name, r->args)) {
+                if (!r->args || !ap_cstr_casecmp(modp->name, r->args)) {
                     ap_rprintf(r,
                                "<dl><dt><a name=\"%s\"><strong>Module Name:</strong></a> "
                                "<font size=\"+1\"><tt><a href=\"?%s\">%s</a></tt></font></dt>\n",
@@ -940,7 +946,7 @@ static int display_info(request_rec * r)
                     }
                 }
             }
-            if (!modp && r->args && strcasecmp(r->args, "server")) {
+            if (!modp && r->args && ap_cstr_casecmp(r->args, "server")) {
                 ap_rputs("<p><b>No such module</b></p>\n", r);
             }
         }

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_status.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_status.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_status.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/generators/mod_status.c Wed Sep 12 13:56:17 2018
@@ -837,7 +837,7 @@ static int status_handler(request_rec *r
                     ap_rprintf(r,
                                " <i>%s {%s}</i> <i>(%s)</i> <b>[%s]</b><br />\n\n",
                                ap_escape_html(r->pool,
-                                              ws_record->client),
+                                              ws_record->client64),
                                ap_escape_html(r->pool,
                                               ap_escape_logitem(r->pool,
                                                                 ws_record->request)),
@@ -924,7 +924,7 @@ static int status_handler(request_rec *r
                     ap_rprintf(r, "</td><td>%s</td><td>%s</td><td nowrap>%s</td>"
                                   "<td nowrap>%s</td></tr>\n\n",
                                ap_escape_html(r->pool,
-                                              ws_record->client),
+                                              ws_record->client64),
                                ap_escape_html(r->pool,
                                               ws_record->protocol),
                                ap_escape_html(r->pool,

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/byterange_filter.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/byterange_filter.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/byterange_filter.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/byterange_filter.c Wed Sep 12 13:56:17 2018
@@ -100,22 +100,8 @@ static int ap_set_byterange(request_rec
         return 0;
     }
 
-    /*
-     * Check for Range request-header (HTTP/1.1) or Request-Range for
-     * backwards-compatibility with second-draft Luotonen/Franks
-     * byte-ranges (e.g. Netscape Navigator 2-3).
-     *
-     * We support this form, with Request-Range, and (farther down) we
-     * send multipart/x-byteranges instead of multipart/byteranges for
-     * Request-Range based requests to work around a bug in Netscape
-     * Navigator 2-3 and MSIE 3.
-     */
-
-    if (!(range = apr_table_get(r->headers_in, "Range"))) {
-        range = apr_table_get(r->headers_in, "Request-Range");
-    }
-
-    if (!range || strncasecmp(range, "bytes=", 6) || r->status != HTTP_OK) {
+    range = apr_table_get(r->headers_in, "Range");
+    if (!range || ap_cstr_casecmpn(range, "bytes=", 6) || r->status != HTTP_OK) {
         return 0;
     }
 
@@ -126,8 +112,7 @@ static int ap_set_byterange(request_rec
 
     /* is content already a multiple range? */
     if ((ct = apr_table_get(r->headers_out, "Content-Type"))
-        && (!strncasecmp(ct, "multipart/byteranges", 20)
-            || !strncasecmp(ct, "multipart/x-byteranges", 22))) {
+        && ap_cstr_casecmpn(ct, "multipart/byteranges", 20) == 0) {
             return 0;
         }
 
@@ -299,21 +284,6 @@ static int ap_set_byterange(request_rec
     return num_ranges;
 }
 
-/*
- * Here we try to be compatible with clients that want multipart/x-byteranges
- * instead of multipart/byteranges (also see above), as per HTTP/1.1. We
- * look for the Request-Range header (e.g. Netscape 2 and 3) as an indication
- * that the browser supports an older protocol. We also check User-Agent
- * for Microsoft Internet Explorer 3, which needs this as well.
- */
-static int use_range_x(request_rec *r)
-{
-    const char *ua;
-    return (apr_table_get(r->headers_in, "Request-Range")
-            || ((ua = apr_table_get(r->headers_in, "User-Agent"))
-                && ap_strstr_c(ua, "MSIE 3")));
-}
-
 #define BYTERANGE_FMT "%" APR_OFF_T_FMT "-%" APR_OFF_T_FMT "/%" APR_OFF_T_FMT
 
 static apr_status_t copy_brigade_range(apr_bucket_brigade *bb,
@@ -504,9 +474,8 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_
         /* Is ap_make_content_type required here? */
         const char *orig_ct = ap_make_content_type(r, r->content_type);
 
-        ap_set_content_type(r, apr_pstrcat(r->pool, "multipart",
-                                           use_range_x(r) ? "/x-" : "/",
-                                           "byteranges; boundary=",
+        ap_set_content_type(r, apr_pstrcat(r->pool,
+                                           "multipart/byteranges; boundary=",
                                            ap_multipart_boundary, NULL));
 
         if (orig_ct) {

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/chunk_filter.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/chunk_filter.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/chunk_filter.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/chunk_filter.c Wed Sep 12 13:56:17 2018
@@ -46,8 +46,6 @@ static char bad_gateway_seen;
 
 apr_status_t ap_http_chunk_filter(ap_filter_t *f, apr_bucket_brigade *b)
 {
-#define ASCII_CRLF  "\015\012"
-#define ASCII_ZERO  "\060"
     conn_rec *c = f->r->connection;
     apr_bucket_brigade *more, *tmp;
     apr_bucket *e;
@@ -73,9 +71,9 @@ apr_status_t ap_http_chunk_filter(ap_fil
                 eos = e;
                 break;
             }
-            if (AP_BUCKET_IS_ERROR(e)
-                && (((ap_bucket_error *)(e->data))->status
-                    == HTTP_BAD_GATEWAY)) {
+            if (AP_BUCKET_IS_ERROR(e) &&
+                (((ap_bucket_error *)(e->data))->status == HTTP_BAD_GATEWAY ||
+                 ((ap_bucket_error *)(e->data))->status == HTTP_GATEWAY_TIME_OUT)) {
                 /*
                  * We had a broken backend. Memorize this in the filter
                  * context.
@@ -145,7 +143,7 @@ apr_status_t ap_http_chunk_filter(ap_fil
              * Insert the end-of-chunk CRLF before an EOS or
              * FLUSH bucket, or appended to the brigade
              */
-            e = apr_bucket_immortal_create(ASCII_CRLF, 2, c->bucket_alloc);
+            e = apr_bucket_immortal_create(CRLF_ASCII, 2, c->bucket_alloc);
             if (eos != NULL) {
                 APR_BUCKET_INSERT_BEFORE(eos, e);
             }
@@ -179,9 +177,9 @@ apr_status_t ap_http_chunk_filter(ap_fil
          */
         if (eos && !f->ctx) {
             /* XXX: (2) trailers ... does not yet exist */
-            e = apr_bucket_immortal_create(ASCII_ZERO ASCII_CRLF
+            e = apr_bucket_immortal_create(ZERO_ASCII CRLF_ASCII
                                            /* <trailers> */
-                                           ASCII_CRLF, 5, c->bucket_alloc);
+                                           CRLF_ASCII, 5, c->bucket_alloc);
             APR_BUCKET_INSERT_BEFORE(eos, e);
         }
 

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/config.m4
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/config.m4?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/config.m4 (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/config.m4 Wed Sep 12 13:56:17 2018
@@ -2,7 +2,7 @@ dnl modules enabled in this directory by
 
 APACHE_MODPATH_INIT(http)
 
-http_objects="http_core.lo http_protocol.lo http_request.lo http_filters.lo chunk_filter.lo byterange_filter.lo http_etag.lo"
+http_objects="http_core.lo http_protocol.lo http_request.lo http_filters.lo chunk_filter.lo byterange_filter.lo"
 
 dnl mod_http should only be built as a static module for now.
 dnl this will hopefully be "fixed" at some point in the future by

Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_core.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_core.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_core.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_core.c Wed Sep 12 13:56:17 2018
@@ -134,22 +134,26 @@ static apr_port_t http_port(const reques
 
 static int ap_process_http_async_connection(conn_rec *c)
 {
-    request_rec *r;
+    request_rec *r = NULL;
     conn_state_t *cs = c->cs;
 
     AP_DEBUG_ASSERT(cs != NULL);
     AP_DEBUG_ASSERT(cs->state == CONN_STATE_READ_REQUEST_LINE);
 
-    while (cs->state == CONN_STATE_READ_REQUEST_LINE) {
+    if (cs->state == CONN_STATE_READ_REQUEST_LINE) {
         ap_update_child_status_from_conn(c->sbh, SERVER_BUSY_READ, c);
-
+        if (ap_extended_status) {
+            ap_set_conn_count(c->sbh, r, c->keepalives);
+        }
         if ((r = ap_read_request(c))) {
-
             c->keepalive = AP_CONN_UNKNOWN;
             /* process the request if it was read without error */
 
             if (r->status == HTTP_OK) {
                 cs->state = CONN_STATE_HANDLER;
+                if (ap_extended_status) {
+                    ap_set_conn_count(c->sbh, r, c->keepalives + 1);
+                }
                 ap_update_child_status(c->sbh, SERVER_BUSY_WRITE, r);
                 ap_process_async_request(r);
                 /* After the call to ap_process_request, the
@@ -254,6 +258,7 @@ static int ap_process_http_connection(co
 
 static int http_create_request(request_rec *r)
 {
+    /* FIXME: we must only add these filters if we are an HTTP request */
     if (!r->main && !r->prev) {
         ap_add_output_filter_handle(ap_byterange_filter_handle,
                                     NULL, r, r->connection);
@@ -263,6 +268,8 @@ static int http_create_request(request_r
                                     NULL, r, r->connection);
         ap_add_output_filter_handle(ap_http_outerror_filter_handle,
                                     NULL, r, r->connection);
+        ap_add_output_filter_handle(ap_request_core_filter_handle,
+                                    NULL, r, r->connection);
     }
 
     return OK;