BBlack has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/274083

Change subject: normalize_path: move to own include file
......................................................................

normalize_path: move to own include file

Bug: T127387
Change-Id: I8813059c5f1fe55d0899b03b83ee7bb7e9257832
---
M modules/role/manifests/cache/text.pp
A templates/varnish/normalize_path.inc.vcl.erb
M templates/varnish/text-frontend.inc.vcl.erb
3 files changed, 84 insertions(+), 84 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/83/274083/1

diff --git a/modules/role/manifests/cache/text.pp 
b/modules/role/manifests/cache/text.pp
index 66d37fd..dba9522 100644
--- a/modules/role/manifests/cache/text.pp
+++ b/modules/role/manifests/cache/text.pp
@@ -181,7 +181,7 @@
     varnish::instance { 'text-frontend':
         name               => 'frontend',
         vcl                => 'text-frontend',
-        extra_vcl          => ['text-common', 'zero'],
+        extra_vcl          => ['text-common', 'zero', 'normalize_path'],
         ports              => [ 80 ],
         admin_port         => 6082,
         runtime_parameters => ['default_ttl=2592000'],
diff --git a/templates/varnish/normalize_path.inc.vcl.erb 
b/templates/varnish/normalize_path.inc.vcl.erb
new file mode 100644
index 0000000..b314042
--- /dev/null
+++ b/templates/varnish/normalize_path.inc.vcl.erb
@@ -0,0 +1,82 @@
+C{
+       #include <string.h>
+}C
+sub normalize_path {
+       /* Rewrite the path part of the URL, replacing unnecessarily escaped
+        * punctuation with the actual characters. The character list is from
+        * MediaWiki's wfUrlencode(), so the URLs produced here will be the 
same as
+        * the ones produced by MediaWiki in href attributes. Doing this reduces
+        * cache fragmentation and fixes T29935, i.e. stale cache entries due to
+        * MediaWiki purging only the wfUrlencode'd version of the URL.
+        */
+       C{
+               /* DIY hexadecimal conversion, since it is simple enough for a 
fixed
+                * width, and all the relevant standard C library functions 
promise to
+                * malfunction if the locale is set to anything other than "C"
+                */
+               #define NP_HEX_DIGIT(c) ( \
+                       (c) >= '0' && (c) <= '9' ? (c) - '0' : ( \
+                               (c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 0x0a : ( 
\
+                                       (c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 
0x0a : -1 ) ) )
+               #define NP_IS_HEX(c) (NP_HEX_DIGIT(c) != -1)
+               #define NP_HEXCHAR(c1, c2) (char)( (NP_HEX_DIGIT(c1) << 4) | 
NP_HEX_DIGIT(c2) )
+               const char * url = VRT_r_req_url(sp);
+               size_t i, outPos;
+               const size_t urlLength = strlen(url);
+                // index for the last position %XX can start at:
+               const size_t lastConvertIdx = urlLength > 2 ? urlLength - 3 : 0;
+               char c;
+               int dirty = 0;
+
+               /* Allocate destination memory from the stack using the C99
+                * variable-length automatic feature. We know the length in 
advance
+                * because this function can only shorten the input string.
+                */
+               char destBuffer[urlLength + 1];
+               if (url) {
+                       for (i = 0, outPos = 0; i < urlLength; i++) {
+                               if (i <= lastConvertIdx && url[i] == '%' && 
NP_IS_HEX(url[i+1]) && NP_IS_HEX(url[i+2])) {
+                                       c = NP_HEXCHAR(url[i+1], url[i+2]);
+                                       if (c == ';'
+                                               || c == '@'
+                                               || c == '$'
+                                               || c == '!'
+                                               || c == '*'
+                                               || c == '('
+                                               || c == ')'
+                                               || c == ','
+                                               || c == '/'
+                                               || c == ':')
+                                       {
+                                               destBuffer[outPos++] = c;
+                                               dirty = 1;
+                                               i += 2;
+                                       } else {
+                                               destBuffer[outPos++] = url[i];
+                                       }
+                               } else if (url[i] == '?') {
+                                       /* Reached the query part. Just copy 
the rest of the URL
+                                        * to the destination.
+                                        */
+                                       memcpy(destBuffer + outPos, url + i, 
sizeof(char) * (urlLength - i));
+                                       outPos += urlLength - i;
+                                       i = urlLength;
+                               } else {
+                                       destBuffer[outPos++] = url[i];
+                               }
+                       }
+                       destBuffer[outPos] = '\0';
+
+                       /* Set req.url. This will copy our stack buffer into 
the workspace.
+                        * VRT_l_req_url() is varadic, and concatenates its 
arguments. The
+                        * vrt_magic_string_end marks the end of the list.
+                        */
+                       if (dirty) {
+                               VRT_l_req_url(sp, destBuffer, 
vrt_magic_string_end);
+                       }
+               }
+               #undef NP_IS_HEX
+               #undef NP_HEX_DIGIT
+               #undef NP_HEXCHAR
+       }C
+}
diff --git a/templates/varnish/text-frontend.inc.vcl.erb 
b/templates/varnish/text-frontend.inc.vcl.erb
index 5ae41f0..cfdc299 100644
--- a/templates/varnish/text-frontend.inc.vcl.erb
+++ b/templates/varnish/text-frontend.inc.vcl.erb
@@ -3,6 +3,7 @@
 include "text-common.inc.vcl";
 include "zero.inc.vcl";
 include "geoip.inc.vcl";
+include "normalize_path.inc.vcl";
 
 // Note that analytics.inc.vcl will set an X-Analytics value of proxy=IORG
 // without inspecting whether there's an existing proxy=<proxy> key-
@@ -44,89 +45,6 @@
                }
                unset req.http.MobileHost;
        }
-}
-
-C{
-       #include <string.h>
-}C
-sub normalize_path {
-       /* Rewrite the path part of the URL, replacing unnecessarily escaped
-        * punctuation with the actual characters. The character list is from
-        * MediaWiki's wfUrlencode(), so the URLs produced here will be the 
same as
-        * the ones produced by MediaWiki in href attributes. Doing this reduces
-        * cache fragmentation and fixes T29935, i.e. stale cache entries due to
-        * MediaWiki purging only the wfUrlencode'd version of the URL.
-        */
-       C{
-               /* DIY hexadecimal conversion, since it is simple enough for a 
fixed
-                * width, and all the relevant standard C library functions 
promise to
-                * malfunction if the locale is set to anything other than "C"
-                */
-               #define NP_HEX_DIGIT(c) ( \
-                       (c) >= '0' && (c) <= '9' ? (c) - '0' : ( \
-                               (c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 0x0a : ( 
\
-                                       (c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 
0x0a : -1 ) ) )
-               #define NP_IS_HEX(c) (NP_HEX_DIGIT(c) != -1)
-               #define NP_HEXCHAR(c1, c2) (char)( (NP_HEX_DIGIT(c1) << 4) | 
NP_HEX_DIGIT(c2) )
-               const char * url = VRT_r_req_url(sp);
-               size_t i, outPos;
-               const size_t urlLength = strlen(url);
-                // index for the last position %XX can start at:
-               const size_t lastConvertIdx = urlLength > 2 ? urlLength - 3 : 0;
-               char c;
-               int dirty = 0;
-
-               /* Allocate destination memory from the stack using the C99
-                * variable-length automatic feature. We know the length in 
advance
-                * because this function can only shorten the input string.
-                */
-               char destBuffer[urlLength + 1];
-               if (url) {
-                       for (i = 0, outPos = 0; i < urlLength; i++) {
-                               if (i <= lastConvertIdx && url[i] == '%' && 
NP_IS_HEX(url[i+1]) && NP_IS_HEX(url[i+2])) {
-                                       c = NP_HEXCHAR(url[i+1], url[i+2]);
-                                       if (c == ';'
-                                               || c == '@'
-                                               || c == '$'
-                                               || c == '!'
-                                               || c == '*'
-                                               || c == '('
-                                               || c == ')'
-                                               || c == ','
-                                               || c == '/'
-                                               || c == ':')
-                                       {
-                                               destBuffer[outPos++] = c;
-                                               dirty = 1;
-                                               i += 2;
-                                       } else {
-                                               destBuffer[outPos++] = url[i];
-                                       }
-                               } else if (url[i] == '?') {
-                                       /* Reached the query part. Just copy 
the rest of the URL
-                                        * to the destination.
-                                        */
-                                       memcpy(destBuffer + outPos, url + i, 
sizeof(char) * (urlLength - i));
-                                       outPos += urlLength - i;
-                                       i = urlLength;
-                               } else {
-                                       destBuffer[outPos++] = url[i];
-                               }
-                       }
-                       destBuffer[outPos] = '\0';
-
-                       /* Set req.url. This will copy our stack buffer into 
the workspace.
-                        * VRT_l_req_url() is varadic, and concatenates its 
arguments. The
-                        * vrt_magic_string_end marks the end of the list.
-                        */
-                       if (dirty) {
-                               VRT_l_req_url(sp, destBuffer, 
vrt_magic_string_end);
-                       }
-               }
-               #undef NP_IS_HEX
-               #undef NP_HEX_DIGIT
-               #undef NP_HEXCHAR
-       }C
 }
 
 sub cluster_fe_recv_pre_purge {

-- 
To view, visit https://gerrit.wikimedia.org/r/274083
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8813059c5f1fe55d0899b03b83ee7bb7e9257832
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: BBlack <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to