Fossil SCM

Rearranged the order and conditional status of paths leading to ETag HTTP header generation to cause them to be generated in more cases. This improves caching in my testing, but it needs to be vetted before it can be merged down to trunk. The main risk is that it causes over-aggressive caching, resulting in stale data delivery.

wyoung 2020-08-03 22:54 trunk
Commit bc0b20356a0b508eb3d97a9da3f6c899d415c384497244b0e4f5e00d1cc47a58
2 files changed +2 -4 +8 -8
+2 -4
--- src/builtin.c
+++ src/builtin.c
@@ -190,13 +190,12 @@
190190
if( zM ){
191191
if( zId && (nId = (int)strlen(zId))>=8
192192
&& strncmp(zId,fossil_exe_id(),nId)==0
193193
){
194194
g.isConst = 1;
195
- }else{
196
- etag_check(0,0);
197195
}
196
+ etag_check(0,0);
198197
builtin_deliver_multiple_js_files(zM, zType);
199198
return;
200199
}
201200
cgi_set_status(404, "Not Found");
202201
@ File "%h(zName)" not found
@@ -213,13 +212,12 @@
213212
if( zId
214213
&& (nId = (int)strlen(zId))>=8
215214
&& strncmp(zId,fossil_exe_id(),nId)==0
216215
){
217216
g.isConst = 1;
218
- }else{
219
- etag_check(0,0);
220217
}
218
+ etag_check(0,0);
221219
blob_init(&out, zTxt, -1);
222220
cgi_set_content(&out);
223221
}
224222
225223
/* Variables controlling the JS cache.
226224
--- src/builtin.c
+++ src/builtin.c
@@ -190,13 +190,12 @@
190 if( zM ){
191 if( zId && (nId = (int)strlen(zId))>=8
192 && strncmp(zId,fossil_exe_id(),nId)==0
193 ){
194 g.isConst = 1;
195 }else{
196 etag_check(0,0);
197 }
 
198 builtin_deliver_multiple_js_files(zM, zType);
199 return;
200 }
201 cgi_set_status(404, "Not Found");
202 @ File "%h(zName)" not found
@@ -213,13 +212,12 @@
213 if( zId
214 && (nId = (int)strlen(zId))>=8
215 && strncmp(zId,fossil_exe_id(),nId)==0
216 ){
217 g.isConst = 1;
218 }else{
219 etag_check(0,0);
220 }
 
221 blob_init(&out, zTxt, -1);
222 cgi_set_content(&out);
223 }
224
225 /* Variables controlling the JS cache.
226
--- src/builtin.c
+++ src/builtin.c
@@ -190,13 +190,12 @@
190 if( zM ){
191 if( zId && (nId = (int)strlen(zId))>=8
192 && strncmp(zId,fossil_exe_id(),nId)==0
193 ){
194 g.isConst = 1;
 
 
195 }
196 etag_check(0,0);
197 builtin_deliver_multiple_js_files(zM, zType);
198 return;
199 }
200 cgi_set_status(404, "Not Found");
201 @ File "%h(zName)" not found
@@ -213,13 +212,12 @@
212 if( zId
213 && (nId = (int)strlen(zId))>=8
214 && strncmp(zId,fossil_exe_id(),nId)==0
215 ){
216 g.isConst = 1;
 
 
217 }
218 etag_check(0,0);
219 blob_init(&out, zTxt, -1);
220 cgi_set_content(&out);
221 }
222
223 /* Variables controlling the JS cache.
224
+8 -8
--- src/cgi.c
+++ src/cgi.c
@@ -303,24 +303,24 @@
303303
fprintf(g.httpOut, "X-UA-Compatible: IE=edge\r\n");
304304
}else{
305305
assert( rangeEnd==0 );
306306
fprintf(g.httpOut, "Status: %d %s\r\n", iReplyStatus, zReplyStatus);
307307
}
308
- if( g.isConst ){
308
+ if( etag_tag()[0]!=0 ){
309
+ fprintf(g.httpOut, "ETag: %s\r\n", etag_tag());
310
+ fprintf(g.httpOut, "Cache-Control: max-age=%d\r\n", etag_maxage());
311
+ if( etag_mtime()>0 ){
312
+ fprintf(g.httpOut, "Last-Modified: %s\r\n",
313
+ cgi_rfc822_datestamp(etag_mtime()));
314
+ }
315
+ }else if( g.isConst ){
309316
/* isConst means that the reply is guaranteed to be invariant, even
310317
** after configuration changes and/or Fossil binary recompiles. */
311318
fprintf(g.httpOut, "Cache-Control: max-age=31536000\r\n");
312
- }else if( etag_tag()[0]!=0 ){
313
- fprintf(g.httpOut, "ETag: %s\r\n", etag_tag());
314
- fprintf(g.httpOut, "Cache-Control: max-age=%d\r\n", etag_maxage());
315319
}else{
316320
fprintf(g.httpOut, "Cache-control: no-cache\r\n");
317321
}
318
- if( etag_mtime()>0 ){
319
- fprintf(g.httpOut, "Last-Modified: %s\r\n",
320
- cgi_rfc822_datestamp(etag_mtime()));
321
- }
322322
323323
if( blob_size(&extraHeader)>0 ){
324324
fprintf(g.httpOut, "%s", blob_buffer(&extraHeader));
325325
}
326326
327327
--- src/cgi.c
+++ src/cgi.c
@@ -303,24 +303,24 @@
303 fprintf(g.httpOut, "X-UA-Compatible: IE=edge\r\n");
304 }else{
305 assert( rangeEnd==0 );
306 fprintf(g.httpOut, "Status: %d %s\r\n", iReplyStatus, zReplyStatus);
307 }
308 if( g.isConst ){
 
 
 
 
 
 
 
309 /* isConst means that the reply is guaranteed to be invariant, even
310 ** after configuration changes and/or Fossil binary recompiles. */
311 fprintf(g.httpOut, "Cache-Control: max-age=31536000\r\n");
312 }else if( etag_tag()[0]!=0 ){
313 fprintf(g.httpOut, "ETag: %s\r\n", etag_tag());
314 fprintf(g.httpOut, "Cache-Control: max-age=%d\r\n", etag_maxage());
315 }else{
316 fprintf(g.httpOut, "Cache-control: no-cache\r\n");
317 }
318 if( etag_mtime()>0 ){
319 fprintf(g.httpOut, "Last-Modified: %s\r\n",
320 cgi_rfc822_datestamp(etag_mtime()));
321 }
322
323 if( blob_size(&extraHeader)>0 ){
324 fprintf(g.httpOut, "%s", blob_buffer(&extraHeader));
325 }
326
327
--- src/cgi.c
+++ src/cgi.c
@@ -303,24 +303,24 @@
303 fprintf(g.httpOut, "X-UA-Compatible: IE=edge\r\n");
304 }else{
305 assert( rangeEnd==0 );
306 fprintf(g.httpOut, "Status: %d %s\r\n", iReplyStatus, zReplyStatus);
307 }
308 if( etag_tag()[0]!=0 ){
309 fprintf(g.httpOut, "ETag: %s\r\n", etag_tag());
310 fprintf(g.httpOut, "Cache-Control: max-age=%d\r\n", etag_maxage());
311 if( etag_mtime()>0 ){
312 fprintf(g.httpOut, "Last-Modified: %s\r\n",
313 cgi_rfc822_datestamp(etag_mtime()));
314 }
315 }else if( g.isConst ){
316 /* isConst means that the reply is guaranteed to be invariant, even
317 ** after configuration changes and/or Fossil binary recompiles. */
318 fprintf(g.httpOut, "Cache-Control: max-age=31536000\r\n");
 
 
 
319 }else{
320 fprintf(g.httpOut, "Cache-control: no-cache\r\n");
321 }
 
 
 
 
322
323 if( blob_size(&extraHeader)>0 ){
324 fprintf(g.httpOut, "%s", blob_buffer(&extraHeader));
325 }
326
327

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button