Fossil SCM

Proof-of-concept ETag caching for the /timeline page. Seems to work. Most other webpages could easily add ETag caching now.

drh 2020-05-10 12:58 trunk
Commit 7eaeceddc49be2019cdec2e7f267481a937a08ce1ab4a1a8dde8cd0f12b2ae7c
2 files changed +13 +1
+13
--- src/etag.c
+++ src/etag.c
@@ -60,10 +60,11 @@
6060
*/
6161
#define ETAG_CONFIG 0x01 /* Output depends on the CONFIG table */
6262
#define ETAG_DATA 0x02 /* Output depends on the EVENT table */
6363
#define ETAG_COOKIE 0x04 /* Output depends on a display cookie value */
6464
#define ETAG_HASH 0x08 /* Output depends on a hash */
65
+#define ETAG_QUERY 0x10 /* Output depends on PATH_INFO and QUERY_STRING */
6566
#endif
6667
6768
static char zETag[33]; /* The generated ETag */
6869
static int iMaxAge = 0; /* The max-age parameter in the reply */
6970
static sqlite3_int64 iEtagMtime = 0; /* Last-Modified time */
@@ -111,10 +112,22 @@
111112
md5sum_step_text("display-cookie: ", -1);
112113
md5sum_step_text(PD(DISPLAY_SETTINGS_COOKIE,""), -1);
113114
md5sum_step_text("\n", 1);
114115
iMaxAge = 0;
115116
}
117
+
118
+ /* Output depends on PATH_INFO and QUERY_STRING */
119
+ if( eFlags & ETAG_QUERY ){
120
+ const char *zQS = P("QUERY_STRING");
121
+ md5sum_step_text("query: ", -1);
122
+ md5sum_step_text(PD("PATH_INFO",""), -1);
123
+ if( zQS ){
124
+ md5sum_step_text("?", 1);
125
+ md5sum_step_text(zQS, -1);
126
+ }
127
+ md5sum_step_text("\n",1);
128
+ }
116129
117130
/* Generate the ETag */
118131
memcpy(zETag, md5sum_finish(0), 33);
119132
120133
/* Check to see if the generated ETag matches If-None-Match and
121134
--- src/etag.c
+++ src/etag.c
@@ -60,10 +60,11 @@
60 */
61 #define ETAG_CONFIG 0x01 /* Output depends on the CONFIG table */
62 #define ETAG_DATA 0x02 /* Output depends on the EVENT table */
63 #define ETAG_COOKIE 0x04 /* Output depends on a display cookie value */
64 #define ETAG_HASH 0x08 /* Output depends on a hash */
 
65 #endif
66
67 static char zETag[33]; /* The generated ETag */
68 static int iMaxAge = 0; /* The max-age parameter in the reply */
69 static sqlite3_int64 iEtagMtime = 0; /* Last-Modified time */
@@ -111,10 +112,22 @@
111 md5sum_step_text("display-cookie: ", -1);
112 md5sum_step_text(PD(DISPLAY_SETTINGS_COOKIE,""), -1);
113 md5sum_step_text("\n", 1);
114 iMaxAge = 0;
115 }
 
 
 
 
 
 
 
 
 
 
 
 
116
117 /* Generate the ETag */
118 memcpy(zETag, md5sum_finish(0), 33);
119
120 /* Check to see if the generated ETag matches If-None-Match and
121
--- src/etag.c
+++ src/etag.c
@@ -60,10 +60,11 @@
60 */
61 #define ETAG_CONFIG 0x01 /* Output depends on the CONFIG table */
62 #define ETAG_DATA 0x02 /* Output depends on the EVENT table */
63 #define ETAG_COOKIE 0x04 /* Output depends on a display cookie value */
64 #define ETAG_HASH 0x08 /* Output depends on a hash */
65 #define ETAG_QUERY 0x10 /* Output depends on PATH_INFO and QUERY_STRING */
66 #endif
67
68 static char zETag[33]; /* The generated ETag */
69 static int iMaxAge = 0; /* The max-age parameter in the reply */
70 static sqlite3_int64 iEtagMtime = 0; /* Last-Modified time */
@@ -111,10 +112,22 @@
112 md5sum_step_text("display-cookie: ", -1);
113 md5sum_step_text(PD(DISPLAY_SETTINGS_COOKIE,""), -1);
114 md5sum_step_text("\n", 1);
115 iMaxAge = 0;
116 }
117
118 /* Output depends on PATH_INFO and QUERY_STRING */
119 if( eFlags & ETAG_QUERY ){
120 const char *zQS = P("QUERY_STRING");
121 md5sum_step_text("query: ", -1);
122 md5sum_step_text(PD("PATH_INFO",""), -1);
123 if( zQS ){
124 md5sum_step_text("?", 1);
125 md5sum_step_text(zQS, -1);
126 }
127 md5sum_step_text("\n",1);
128 }
129
130 /* Generate the ETag */
131 memcpy(zETag, md5sum_finish(0), 33);
132
133 /* Check to see if the generated ETag matches If-None-Match and
134
--- src/timeline.c
+++ src/timeline.c
@@ -1742,10 +1742,11 @@
17421742
|| (bisectLocal && !g.perm.Setup)
17431743
){
17441744
login_needed(g.anon.Read && g.anon.RdTkt && g.anon.RdWiki);
17451745
return;
17461746
}
1747
+ etag_check(ETAG_QUERY|ETAG_COOKIE|ETAG_DATA, 0);
17471748
cookie_read_parameter("y","y");
17481749
zType = P("y");
17491750
if( zType==0 ){
17501751
zType = g.perm.Read ? "ci" : "all";
17511752
cgi_set_parameter("y", zType);
17521753
--- src/timeline.c
+++ src/timeline.c
@@ -1742,10 +1742,11 @@
1742 || (bisectLocal && !g.perm.Setup)
1743 ){
1744 login_needed(g.anon.Read && g.anon.RdTkt && g.anon.RdWiki);
1745 return;
1746 }
 
1747 cookie_read_parameter("y","y");
1748 zType = P("y");
1749 if( zType==0 ){
1750 zType = g.perm.Read ? "ci" : "all";
1751 cgi_set_parameter("y", zType);
1752
--- src/timeline.c
+++ src/timeline.c
@@ -1742,10 +1742,11 @@
1742 || (bisectLocal && !g.perm.Setup)
1743 ){
1744 login_needed(g.anon.Read && g.anon.RdTkt && g.anon.RdWiki);
1745 return;
1746 }
1747 etag_check(ETAG_QUERY|ETAG_COOKIE|ETAG_DATA, 0);
1748 cookie_read_parameter("y","y");
1749 zType = P("y");
1750 if( zType==0 ){
1751 zType = g.perm.Read ? "ci" : "all";
1752 cgi_set_parameter("y", zType);
1753

Keyboard Shortcuts

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