Fossil SCM

Also accept a single ETag enclosed in double quotes when checking the If-Modified-Since HTTP header. Suggested in [forum:/forumpost/058cd829f9|Forum Post 058cd829f9].

florian 2025-05-26 14:08 trunk
Commit 174091aa6fa5ed408fa8a37ce8f9491bfa75ea6e74a4f94eb7f9bfdd7d56e27a
1 file changed +11 -3
+11 -3
--- src/etag.c
+++ src/etag.c
@@ -94,10 +94,12 @@
9494
** Generate an ETag
9595
*/
9696
void etag_check(unsigned eFlags, const char *zHash){
9797
const char *zIfNoneMatch;
9898
char zBuf[50];
99
+ const int cchETag = 32; /* Not including NULL terminator. */
100
+ int cch; /* Length of zIfNoneMatch header. */
99101
assert( zETag[0]==0 ); /* Only call this routine once! */
100102
101103
if( etagCancelled ) return;
102104
103105
/* By default, ETagged URLs never expire since the ETag will change
@@ -157,17 +159,23 @@
157159
md5sum_step_text("\n", 1);
158160
}
159161
}
160162
161163
/* Generate the ETag */
162
- memcpy(zETag, md5sum_finish(0), 33);
164
+ memcpy(zETag, md5sum_finish(0), cchETag+1);
163165
164166
/* Check to see if the generated ETag matches If-None-Match and
165
- ** generate a 304 reply if it does. */
167
+ ** generate a 304 reply if it does. Test both with and without
168
+ ** double quotes. */
166169
zIfNoneMatch = P("HTTP_IF_NONE_MATCH");
167170
if( zIfNoneMatch==0 ) return;
168
- if( strcmp(zIfNoneMatch,zETag)!=0 ) return;
171
+ cch = strlen(zIfNoneMatch);
172
+ if( cch==cchETag+2 && zIfNoneMatch[0]=='"' && zIfNoneMatch[cch-1]=='"' ){
173
+ if( memcmp(&zIfNoneMatch[1],zETag,cchETag)!=0 ) return;
174
+ }else{
175
+ if( strcmp(zIfNoneMatch,zETag)!=0 ) return;
176
+ }
169177
170178
/* If we get this far, it means that the content has
171179
** not changed and we can do a 304 reply */
172180
cgi_reset_content();
173181
cgi_set_status(304, "Not Modified");
174182
--- src/etag.c
+++ src/etag.c
@@ -94,10 +94,12 @@
94 ** Generate an ETag
95 */
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
103 /* By default, ETagged URLs never expire since the ETag will change
@@ -157,17 +159,23 @@
157 md5sum_step_text("\n", 1);
158 }
159 }
160
161 /* Generate the ETag */
162 memcpy(zETag, md5sum_finish(0), 33);
163
164 /* Check to see if the generated ETag matches If-None-Match and
165 ** generate a 304 reply if it does. */
 
166 zIfNoneMatch = P("HTTP_IF_NONE_MATCH");
167 if( zIfNoneMatch==0 ) return;
168 if( strcmp(zIfNoneMatch,zETag)!=0 ) return;
 
 
 
 
 
169
170 /* If we get this far, it means that the content has
171 ** not changed and we can do a 304 reply */
172 cgi_reset_content();
173 cgi_set_status(304, "Not Modified");
174
--- src/etag.c
+++ src/etag.c
@@ -94,10 +94,12 @@
94 ** Generate an ETag
95 */
96 void etag_check(unsigned eFlags, const char *zHash){
97 const char *zIfNoneMatch;
98 char zBuf[50];
99 const int cchETag = 32; /* Not including NULL terminator. */
100 int cch; /* Length of zIfNoneMatch header. */
101 assert( zETag[0]==0 ); /* Only call this routine once! */
102
103 if( etagCancelled ) return;
104
105 /* By default, ETagged URLs never expire since the ETag will change
@@ -157,17 +159,23 @@
159 md5sum_step_text("\n", 1);
160 }
161 }
162
163 /* Generate the ETag */
164 memcpy(zETag, md5sum_finish(0), cchETag+1);
165
166 /* Check to see if the generated ETag matches If-None-Match and
167 ** generate a 304 reply if it does. Test both with and without
168 ** double quotes. */
169 zIfNoneMatch = P("HTTP_IF_NONE_MATCH");
170 if( zIfNoneMatch==0 ) return;
171 cch = strlen(zIfNoneMatch);
172 if( cch==cchETag+2 && zIfNoneMatch[0]=='"' && zIfNoneMatch[cch-1]=='"' ){
173 if( memcmp(&zIfNoneMatch[1],zETag,cchETag)!=0 ) return;
174 }else{
175 if( strcmp(zIfNoneMatch,zETag)!=0 ) return;
176 }
177
178 /* If we get this far, it means that the content has
179 ** not changed and we can do a 304 reply */
180 cgi_reset_content();
181 cgi_set_status(304, "Not Modified");
182

Keyboard Shortcuts

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