Fossil SCM
Proof-of-concept ETag caching for the /timeline page. Seems to work. Most other webpages could easily add ETag caching now.
Commit
7eaeceddc49be2019cdec2e7f267481a937a08ce1ab4a1a8dde8cd0f12b2ae7c
Parent
a6003f1df0f905a…
2 files changed
+13
+1
+13
| --- src/etag.c | ||
| +++ src/etag.c | ||
| @@ -60,10 +60,11 @@ | ||
| 60 | 60 | */ |
| 61 | 61 | #define ETAG_CONFIG 0x01 /* Output depends on the CONFIG table */ |
| 62 | 62 | #define ETAG_DATA 0x02 /* Output depends on the EVENT table */ |
| 63 | 63 | #define ETAG_COOKIE 0x04 /* Output depends on a display cookie value */ |
| 64 | 64 | #define ETAG_HASH 0x08 /* Output depends on a hash */ |
| 65 | +#define ETAG_QUERY 0x10 /* Output depends on PATH_INFO and QUERY_STRING */ | |
| 65 | 66 | #endif |
| 66 | 67 | |
| 67 | 68 | static char zETag[33]; /* The generated ETag */ |
| 68 | 69 | static int iMaxAge = 0; /* The max-age parameter in the reply */ |
| 69 | 70 | static sqlite3_int64 iEtagMtime = 0; /* Last-Modified time */ |
| @@ -111,10 +112,22 @@ | ||
| 111 | 112 | md5sum_step_text("display-cookie: ", -1); |
| 112 | 113 | md5sum_step_text(PD(DISPLAY_SETTINGS_COOKIE,""), -1); |
| 113 | 114 | md5sum_step_text("\n", 1); |
| 114 | 115 | iMaxAge = 0; |
| 115 | 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 | + } | |
| 116 | 129 | |
| 117 | 130 | /* Generate the ETag */ |
| 118 | 131 | memcpy(zETag, md5sum_finish(0), 33); |
| 119 | 132 | |
| 120 | 133 | /* Check to see if the generated ETag matches If-None-Match and |
| 121 | 134 |
| --- 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 |
+1
| --- src/timeline.c | ||
| +++ src/timeline.c | ||
| @@ -1742,10 +1742,11 @@ | ||
| 1742 | 1742 | || (bisectLocal && !g.perm.Setup) |
| 1743 | 1743 | ){ |
| 1744 | 1744 | login_needed(g.anon.Read && g.anon.RdTkt && g.anon.RdWiki); |
| 1745 | 1745 | return; |
| 1746 | 1746 | } |
| 1747 | + etag_check(ETAG_QUERY|ETAG_COOKIE|ETAG_DATA, 0); | |
| 1747 | 1748 | cookie_read_parameter("y","y"); |
| 1748 | 1749 | zType = P("y"); |
| 1749 | 1750 | if( zType==0 ){ |
| 1750 | 1751 | zType = g.perm.Read ? "ci" : "all"; |
| 1751 | 1752 | cgi_set_parameter("y", zType); |
| 1752 | 1753 |
| --- 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 |