Fossil SCM

Improved ETags caching information in replies, to help browser avoid unnecessary HTTP requests.

drh 2020-08-06 20:31 trunk merge
Commit ec5a063bdc1b711b029b75f52eb6df66c1fa9512f13e5707c0f79a3145c076a0
+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
+4 -1
--- src/etag.c
+++ src/etag.c
@@ -97,11 +97,14 @@
9797
const char *zIfNoneMatch;
9898
char zBuf[50];
9999
assert( zETag[0]==0 ); /* Only call this routine once! */
100100
101101
if( etagCancelled ) return;
102
- iMaxAge = 86400;
102
+
103
+ /* By default, ETagged URLs never expire since the ETag will change
104
+ * when the content changes. Approximate this policy as 10 years. */
105
+ iMaxAge = 10 * 365 * 24 * 60 * 60;
103106
md5sum_init();
104107
105108
/* Always include the executable ID as part of the hash */
106109
md5sum_step_text("exe-id: ", -1);
107110
md5sum_step_text(fossil_exe_id(), -1);
108111
--- src/etag.c
+++ src/etag.c
@@ -97,11 +97,14 @@
97 const char *zIfNoneMatch;
98 char zBuf[50];
99 assert( zETag[0]==0 ); /* Only call this routine once! */
100
101 if( etagCancelled ) return;
102 iMaxAge = 86400;
 
 
 
103 md5sum_init();
104
105 /* Always include the executable ID as part of the hash */
106 md5sum_step_text("exe-id: ", -1);
107 md5sum_step_text(fossil_exe_id(), -1);
108
--- src/etag.c
+++ src/etag.c
@@ -97,11 +97,14 @@
97 const char *zIfNoneMatch;
98 char zBuf[50];
99 assert( zETag[0]==0 ); /* Only call this routine once! */
100
101 if( etagCancelled ) return;
102
103 /* By default, ETagged URLs never expire since the ETag will change
104 * when the content changes. Approximate this policy as 10 years. */
105 iMaxAge = 10 * 365 * 24 * 60 * 60;
106 md5sum_init();
107
108 /* Always include the executable ID as part of the hash */
109 md5sum_step_text("exe-id: ", -1);
110 md5sum_step_text(fossil_exe_id(), -1);
111
--- src/style.c
+++ src/style.c
@@ -1026,10 +1026,11 @@
10261026
Blob css = empty_blob;
10271027
int i;
10281028
const char * zDefaults;
10291029
10301030
cgi_set_content_type("text/css");
1031
+ etag_check(0, 0);
10311032
/* Emit all default rules... */
10321033
zDefaults = (const char*)builtin_file("default.css", &i);
10331034
blob_append(&css, zDefaults, i);
10341035
/* Page-specific CSS, if any... */
10351036
page_style_css_append_page_style(&css);
10361037
--- src/style.c
+++ src/style.c
@@ -1026,10 +1026,11 @@
1026 Blob css = empty_blob;
1027 int i;
1028 const char * zDefaults;
1029
1030 cgi_set_content_type("text/css");
 
1031 /* Emit all default rules... */
1032 zDefaults = (const char*)builtin_file("default.css", &i);
1033 blob_append(&css, zDefaults, i);
1034 /* Page-specific CSS, if any... */
1035 page_style_css_append_page_style(&css);
1036
--- src/style.c
+++ src/style.c
@@ -1026,10 +1026,11 @@
1026 Blob css = empty_blob;
1027 int i;
1028 const char * zDefaults;
1029
1030 cgi_set_content_type("text/css");
1031 etag_check(0, 0);
1032 /* Emit all default rules... */
1033 zDefaults = (const char*)builtin_file("default.css", &i);
1034 blob_append(&css, zDefaults, i);
1035 /* Page-specific CSS, if any... */
1036 page_style_css_append_page_style(&css);
1037

Keyboard Shortcuts

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