Fossil SCM

Fix etag processing so that no etag header is issued for pages which encounter errors or warnings.

drh 2020-06-21 12:59 trunk
Commit 517fb01b9ca8b29055213e91c795ca049780190a137a45437f811d1fae26118f
+14 -2
--- src/etag.c
+++ src/etag.c
@@ -69,10 +69,11 @@
6969
#endif
7070
7171
static char zETag[33]; /* The generated ETag */
7272
static int iMaxAge = 0; /* The max-age parameter in the reply */
7373
static sqlite3_int64 iEtagMtime = 0; /* Last-Modified time */
74
+static int etagCancelled = 0; /* Never send an etag */
7475
7576
/*
7677
** Return a hash that changes every time the Fossil source code is
7778
** rebuilt.
7879
**
@@ -95,10 +96,11 @@
9596
void etag_check(unsigned eFlags, const char *zHash){
9697
const char *zIfNoneMatch;
9798
char zBuf[50];
9899
assert( zETag[0]==0 ); /* Only call this routine once! */
99100
101
+ if( etagCancelled ) return;
100102
iMaxAge = 86400;
101103
md5sum_init();
102104
103105
/* Always include the executable ID as part of the hash */
104106
md5sum_step_text("exe-id: ", -1);
@@ -108,18 +110,20 @@
108110
if( (eFlags & ETAG_HASH)!=0 && zHash ){
109111
md5sum_step_text("hash: ", -1);
110112
md5sum_step_text(zHash, -1);
111113
md5sum_step_text("\n", 1);
112114
iMaxAge = 0;
113
- }else if( eFlags & ETAG_DATA ){
115
+ }
116
+ if( eFlags & ETAG_DATA ){
114117
int iKey = db_int(0, "SELECT max(rcvid) FROM rcvfrom");
115118
sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",iKey);
116119
md5sum_step_text("data: ", -1);
117120
md5sum_step_text(zBuf, -1);
118121
md5sum_step_text("\n", 1);
119122
iMaxAge = 60;
120
- }else if( eFlags & ETAG_CONFIG ){
123
+ }
124
+ if( eFlags & ETAG_CONFIG ){
121125
int iKey = db_int(0, "SELECT value FROM config WHERE name='cfgcnt'");
122126
sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",iKey);
123127
md5sum_step_text("config: ", -1);
124128
md5sum_step_text(zBuf, -1);
125129
md5sum_step_text("\n", 1);
@@ -245,5 +249,13 @@
245249
zHash = find_option("hash",0,1);
246250
if( zKey ) iKey = atoi(zKey);
247251
etag_check(iKey, zHash);
248252
fossil_print("%s\n", etag_tag());
249253
}
254
+
255
+/*
256
+** Cancel the ETag.
257
+*/
258
+void etag_cancel(void){
259
+ etagCancelled = 1;
260
+ zETag[0] = 0;
261
+}
250262
--- src/etag.c
+++ src/etag.c
@@ -69,10 +69,11 @@
69 #endif
70
71 static char zETag[33]; /* The generated ETag */
72 static int iMaxAge = 0; /* The max-age parameter in the reply */
73 static sqlite3_int64 iEtagMtime = 0; /* Last-Modified time */
 
74
75 /*
76 ** Return a hash that changes every time the Fossil source code is
77 ** rebuilt.
78 **
@@ -95,10 +96,11 @@
95 void etag_check(unsigned eFlags, const char *zHash){
96 const char *zIfNoneMatch;
97 char zBuf[50];
98 assert( zETag[0]==0 ); /* Only call this routine once! */
99
 
100 iMaxAge = 86400;
101 md5sum_init();
102
103 /* Always include the executable ID as part of the hash */
104 md5sum_step_text("exe-id: ", -1);
@@ -108,18 +110,20 @@
108 if( (eFlags & ETAG_HASH)!=0 && zHash ){
109 md5sum_step_text("hash: ", -1);
110 md5sum_step_text(zHash, -1);
111 md5sum_step_text("\n", 1);
112 iMaxAge = 0;
113 }else if( eFlags & ETAG_DATA ){
 
114 int iKey = db_int(0, "SELECT max(rcvid) FROM rcvfrom");
115 sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",iKey);
116 md5sum_step_text("data: ", -1);
117 md5sum_step_text(zBuf, -1);
118 md5sum_step_text("\n", 1);
119 iMaxAge = 60;
120 }else if( eFlags & ETAG_CONFIG ){
 
121 int iKey = db_int(0, "SELECT value FROM config WHERE name='cfgcnt'");
122 sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",iKey);
123 md5sum_step_text("config: ", -1);
124 md5sum_step_text(zBuf, -1);
125 md5sum_step_text("\n", 1);
@@ -245,5 +249,13 @@
245 zHash = find_option("hash",0,1);
246 if( zKey ) iKey = atoi(zKey);
247 etag_check(iKey, zHash);
248 fossil_print("%s\n", etag_tag());
249 }
 
 
 
 
 
 
 
 
250
--- src/etag.c
+++ src/etag.c
@@ -69,10 +69,11 @@
69 #endif
70
71 static char zETag[33]; /* The generated ETag */
72 static int iMaxAge = 0; /* The max-age parameter in the reply */
73 static sqlite3_int64 iEtagMtime = 0; /* Last-Modified time */
74 static int etagCancelled = 0; /* Never send an etag */
75
76 /*
77 ** Return a hash that changes every time the Fossil source code is
78 ** rebuilt.
79 **
@@ -95,10 +96,11 @@
96 void etag_check(unsigned eFlags, const char *zHash){
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);
@@ -108,18 +110,20 @@
110 if( (eFlags & ETAG_HASH)!=0 && zHash ){
111 md5sum_step_text("hash: ", -1);
112 md5sum_step_text(zHash, -1);
113 md5sum_step_text("\n", 1);
114 iMaxAge = 0;
115 }
116 if( eFlags & ETAG_DATA ){
117 int iKey = db_int(0, "SELECT max(rcvid) FROM rcvfrom");
118 sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",iKey);
119 md5sum_step_text("data: ", -1);
120 md5sum_step_text(zBuf, -1);
121 md5sum_step_text("\n", 1);
122 iMaxAge = 60;
123 }
124 if( eFlags & ETAG_CONFIG ){
125 int iKey = db_int(0, "SELECT value FROM config WHERE name='cfgcnt'");
126 sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",iKey);
127 md5sum_step_text("config: ", -1);
128 md5sum_step_text(zBuf, -1);
129 md5sum_step_text("\n", 1);
@@ -245,5 +249,13 @@
249 zHash = find_option("hash",0,1);
250 if( zKey ) iKey = atoi(zKey);
251 etag_check(iKey, zHash);
252 fossil_print("%s\n", etag_tag());
253 }
254
255 /*
256 ** Cancel the ETag.
257 */
258 void etag_cancel(void){
259 etagCancelled = 1;
260 zETag[0] = 0;
261 }
262
--- src/printf.c
+++ src/printf.c
@@ -1098,10 +1098,11 @@
10981098
if( g.cgiOutput==1 && g.db ){
10991099
g.cgiOutput = 2;
11001100
cgi_reset_content();
11011101
cgi_set_content_type("text/html");
11021102
style_header("Bad Request");
1103
+ etag_cancel();
11031104
@ <p class="generalError">%h(z)</p>
11041105
cgi_set_status(400, "Bad Request");
11051106
style_footer();
11061107
cgi_reply();
11071108
}else if( !g.fQuiet ){
@@ -1212,10 +1213,11 @@
12121213
json_warn( FSL_JSON_W_UNKNOWN, "%s", z );
12131214
}else
12141215
#endif
12151216
{
12161217
if( g.cgiOutput==1 ){
1218
+ etag_cancel();
12171219
cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z);
12181220
}else{
12191221
fossil_force_newline();
12201222
fossil_trace("%s\n", z);
12211223
}
12221224
--- src/printf.c
+++ src/printf.c
@@ -1098,10 +1098,11 @@
1098 if( g.cgiOutput==1 && g.db ){
1099 g.cgiOutput = 2;
1100 cgi_reset_content();
1101 cgi_set_content_type("text/html");
1102 style_header("Bad Request");
 
1103 @ <p class="generalError">%h(z)</p>
1104 cgi_set_status(400, "Bad Request");
1105 style_footer();
1106 cgi_reply();
1107 }else if( !g.fQuiet ){
@@ -1212,10 +1213,11 @@
1212 json_warn( FSL_JSON_W_UNKNOWN, "%s", z );
1213 }else
1214 #endif
1215 {
1216 if( g.cgiOutput==1 ){
 
1217 cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z);
1218 }else{
1219 fossil_force_newline();
1220 fossil_trace("%s\n", z);
1221 }
1222
--- src/printf.c
+++ src/printf.c
@@ -1098,10 +1098,11 @@
1098 if( g.cgiOutput==1 && g.db ){
1099 g.cgiOutput = 2;
1100 cgi_reset_content();
1101 cgi_set_content_type("text/html");
1102 style_header("Bad Request");
1103 etag_cancel();
1104 @ <p class="generalError">%h(z)</p>
1105 cgi_set_status(400, "Bad Request");
1106 style_footer();
1107 cgi_reply();
1108 }else if( !g.fQuiet ){
@@ -1212,10 +1213,11 @@
1213 json_warn( FSL_JSON_W_UNKNOWN, "%s", z );
1214 }else
1215 #endif
1216 {
1217 if( g.cgiOutput==1 ){
1218 etag_cancel();
1219 cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z);
1220 }else{
1221 fossil_force_newline();
1222 fossil_trace("%s\n", z);
1223 }
1224
--- src/security_audit.c
+++ src/security_audit.c
@@ -686,11 +686,11 @@
686686
@ <p>The server error log at "%h(g.zErrlog)" is %,lld(szFile) bytes in size.
687687
style_submenu_element("Download", "%R/errorlog?download");
688688
style_submenu_element("Truncate", "%R/errorlog?truncate");
689689
in = fossil_fopen(g.zErrlog, "rb");
690690
if( in==0 ){
691
- @ <p class='generalError'>Unable top open that file for reading!</p>
691
+ @ <p class='generalError'>Unable to open that file for reading!</p>
692692
style_footer();
693693
return;
694694
}
695695
if( szFile>MXSHOWLOG && P("all")==0 ){
696696
@ <form action="%R/errorlog" method="POST">
697697
--- src/security_audit.c
+++ src/security_audit.c
@@ -686,11 +686,11 @@
686 @ <p>The server error log at "%h(g.zErrlog)" is %,lld(szFile) bytes in size.
687 style_submenu_element("Download", "%R/errorlog?download");
688 style_submenu_element("Truncate", "%R/errorlog?truncate");
689 in = fossil_fopen(g.zErrlog, "rb");
690 if( in==0 ){
691 @ <p class='generalError'>Unable top open that file for reading!</p>
692 style_footer();
693 return;
694 }
695 if( szFile>MXSHOWLOG && P("all")==0 ){
696 @ <form action="%R/errorlog" method="POST">
697
--- src/security_audit.c
+++ src/security_audit.c
@@ -686,11 +686,11 @@
686 @ <p>The server error log at "%h(g.zErrlog)" is %,lld(szFile) bytes in size.
687 style_submenu_element("Download", "%R/errorlog?download");
688 style_submenu_element("Truncate", "%R/errorlog?truncate");
689 in = fossil_fopen(g.zErrlog, "rb");
690 if( in==0 ){
691 @ <p class='generalError'>Unable to open that file for reading!</p>
692 style_footer();
693 return;
694 }
695 if( szFile>MXSHOWLOG && P("all")==0 ){
696 @ <form action="%R/errorlog" method="POST">
697
+1 -1
--- src/timeline.c
+++ src/timeline.c
@@ -1743,11 +1743,11 @@
17431743
|| (bisectLocal && !g.perm.Setup)
17441744
){
17451745
login_needed(g.anon.Read && g.anon.RdTkt && g.anon.RdWiki);
17461746
return;
17471747
}
1748
- etag_check(ETAG_QUERY|ETAG_COOKIE|ETAG_DATA, 0);
1748
+ etag_check(ETAG_QUERY|ETAG_COOKIE|ETAG_DATA|ETAG_CONFIG, 0);
17491749
cookie_read_parameter("y","y");
17501750
zType = P("y");
17511751
if( zType==0 ){
17521752
zType = g.perm.Read ? "ci" : "all";
17531753
cgi_set_parameter("y", zType);
17541754
--- src/timeline.c
+++ src/timeline.c
@@ -1743,11 +1743,11 @@
1743 || (bisectLocal && !g.perm.Setup)
1744 ){
1745 login_needed(g.anon.Read && g.anon.RdTkt && g.anon.RdWiki);
1746 return;
1747 }
1748 etag_check(ETAG_QUERY|ETAG_COOKIE|ETAG_DATA, 0);
1749 cookie_read_parameter("y","y");
1750 zType = P("y");
1751 if( zType==0 ){
1752 zType = g.perm.Read ? "ci" : "all";
1753 cgi_set_parameter("y", zType);
1754
--- src/timeline.c
+++ src/timeline.c
@@ -1743,11 +1743,11 @@
1743 || (bisectLocal && !g.perm.Setup)
1744 ){
1745 login_needed(g.anon.Read && g.anon.RdTkt && g.anon.RdWiki);
1746 return;
1747 }
1748 etag_check(ETAG_QUERY|ETAG_COOKIE|ETAG_DATA|ETAG_CONFIG, 0);
1749 cookie_read_parameter("y","y");
1750 zType = P("y");
1751 if( zType==0 ){
1752 zType = g.perm.Read ? "ci" : "all";
1753 cgi_set_parameter("y", zType);
1754

Keyboard Shortcuts

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