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].
Commit
174091aa6fa5ed408fa8a37ce8f9491bfa75ea6e74a4f94eb7f9bfdd7d56e27a
Parent
56795263f7b5a53…
1 file changed
+11
-3
+11
-3
| --- src/etag.c | ||
| +++ src/etag.c | ||
| @@ -94,10 +94,12 @@ | ||
| 94 | 94 | ** Generate an ETag |
| 95 | 95 | */ |
| 96 | 96 | void etag_check(unsigned eFlags, const char *zHash){ |
| 97 | 97 | const char *zIfNoneMatch; |
| 98 | 98 | char zBuf[50]; |
| 99 | + const int cchETag = 32; /* Not including NULL terminator. */ | |
| 100 | + int cch; /* Length of zIfNoneMatch header. */ | |
| 99 | 101 | assert( zETag[0]==0 ); /* Only call this routine once! */ |
| 100 | 102 | |
| 101 | 103 | if( etagCancelled ) return; |
| 102 | 104 | |
| 103 | 105 | /* By default, ETagged URLs never expire since the ETag will change |
| @@ -157,17 +159,23 @@ | ||
| 157 | 159 | md5sum_step_text("\n", 1); |
| 158 | 160 | } |
| 159 | 161 | } |
| 160 | 162 | |
| 161 | 163 | /* Generate the ETag */ |
| 162 | - memcpy(zETag, md5sum_finish(0), 33); | |
| 164 | + memcpy(zETag, md5sum_finish(0), cchETag+1); | |
| 163 | 165 | |
| 164 | 166 | /* 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. */ | |
| 166 | 169 | zIfNoneMatch = P("HTTP_IF_NONE_MATCH"); |
| 167 | 170 | 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 | + } | |
| 169 | 177 | |
| 170 | 178 | /* If we get this far, it means that the content has |
| 171 | 179 | ** not changed and we can do a 304 reply */ |
| 172 | 180 | cgi_reset_content(); |
| 173 | 181 | cgi_set_status(304, "Not Modified"); |
| 174 | 182 |
| --- 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 |