Fossil SCM
Adjust the /builtin page such that if a filename contains "-v12345689" as part of its name right before a ".", where the digits can vary, then that part of the name is ignored. We can thus give semi-random names to built-in resources (ex: extsrc/pikchr-v12345678.wasm) to defeat aggressive browser caches. This is experimental.
Commit
a9f4bbb09fa148cc7096e1eaa65917db90ba5573236a94fe7be31c5bc7ae7ba5
Parent
6382e25428ddca1…
1 file changed
+15
+15
| --- src/builtin.c | ||
| +++ src/builtin.c | ||
| @@ -52,17 +52,32 @@ | ||
| 52 | 52 | return -1; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /* |
| 56 | 56 | ** Return a pointer to built-in content |
| 57 | +** | |
| 58 | +** If the filename contains "-vNNNNNNNN" just before the final file | |
| 59 | +** suffix, where each N is a random digit, then omit that part of the | |
| 60 | +** filename before doing the lookup. The extra -vNNNNNNNN was added | |
| 61 | +** to defeat overly aggressive caching by web browsers. | |
| 57 | 62 | */ |
| 58 | 63 | const unsigned char *builtin_file(const char *zFilename, int *piSize){ |
| 59 | 64 | int i = builtin_file_index(zFilename); |
| 60 | 65 | if( i>=0 ){ |
| 61 | 66 | if( piSize ) *piSize = aBuiltinFiles[i].nByte; |
| 62 | 67 | return aBuiltinFiles[i].pData; |
| 63 | 68 | }else{ |
| 69 | + char *zV = strstr(zFilename, "-v"); | |
| 70 | + if( zV!=0 ){ | |
| 71 | + for(i=0; i<8 && fossil_isdigit(zV[i+2]); i++){} | |
| 72 | + if( i==8 && zV[10]=='.' ){ | |
| 73 | + char *zNew = mprintf("%.*s%s", (int)(zV-zFilename), zFilename, zV+10); | |
| 74 | + const unsigned char *pRes = builtin_file(zNew, piSize); | |
| 75 | + fossil_free(zNew); | |
| 76 | + return pRes; | |
| 77 | + } | |
| 78 | + } | |
| 64 | 79 | if( piSize ) *piSize = 0; |
| 65 | 80 | return 0; |
| 66 | 81 | } |
| 67 | 82 | } |
| 68 | 83 | const char *builtin_text(const char *zFilename){ |
| 69 | 84 |
| --- src/builtin.c | |
| +++ src/builtin.c | |
| @@ -52,17 +52,32 @@ | |
| 52 | return -1; |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | ** Return a pointer to built-in content |
| 57 | */ |
| 58 | const unsigned char *builtin_file(const char *zFilename, int *piSize){ |
| 59 | int i = builtin_file_index(zFilename); |
| 60 | if( i>=0 ){ |
| 61 | if( piSize ) *piSize = aBuiltinFiles[i].nByte; |
| 62 | return aBuiltinFiles[i].pData; |
| 63 | }else{ |
| 64 | if( piSize ) *piSize = 0; |
| 65 | return 0; |
| 66 | } |
| 67 | } |
| 68 | const char *builtin_text(const char *zFilename){ |
| 69 |
| --- src/builtin.c | |
| +++ src/builtin.c | |
| @@ -52,17 +52,32 @@ | |
| 52 | return -1; |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | ** Return a pointer to built-in content |
| 57 | ** |
| 58 | ** If the filename contains "-vNNNNNNNN" just before the final file |
| 59 | ** suffix, where each N is a random digit, then omit that part of the |
| 60 | ** filename before doing the lookup. The extra -vNNNNNNNN was added |
| 61 | ** to defeat overly aggressive caching by web browsers. |
| 62 | */ |
| 63 | const unsigned char *builtin_file(const char *zFilename, int *piSize){ |
| 64 | int i = builtin_file_index(zFilename); |
| 65 | if( i>=0 ){ |
| 66 | if( piSize ) *piSize = aBuiltinFiles[i].nByte; |
| 67 | return aBuiltinFiles[i].pData; |
| 68 | }else{ |
| 69 | char *zV = strstr(zFilename, "-v"); |
| 70 | if( zV!=0 ){ |
| 71 | for(i=0; i<8 && fossil_isdigit(zV[i+2]); i++){} |
| 72 | if( i==8 && zV[10]=='.' ){ |
| 73 | char *zNew = mprintf("%.*s%s", (int)(zV-zFilename), zFilename, zV+10); |
| 74 | const unsigned char *pRes = builtin_file(zNew, piSize); |
| 75 | fossil_free(zNew); |
| 76 | return pRes; |
| 77 | } |
| 78 | } |
| 79 | if( piSize ) *piSize = 0; |
| 80 | return 0; |
| 81 | } |
| 82 | } |
| 83 | const char *builtin_text(const char *zFilename){ |
| 84 |