Fossil SCM
Improved ETags caching information in replies, to help browser avoid unnecessary HTTP requests.
Commit
ec5a063bdc1b711b029b75f52eb6df66c1fa9512f13e5707c0f79a3145c076a0
Parent
02c3080bb24f2d7…
4 files changed
+2
-4
+8
-8
+4
-1
+1
+2
-4
| --- src/builtin.c | ||
| +++ src/builtin.c | ||
| @@ -190,13 +190,12 @@ | ||
| 190 | 190 | if( zM ){ |
| 191 | 191 | if( zId && (nId = (int)strlen(zId))>=8 |
| 192 | 192 | && strncmp(zId,fossil_exe_id(),nId)==0 |
| 193 | 193 | ){ |
| 194 | 194 | g.isConst = 1; |
| 195 | - }else{ | |
| 196 | - etag_check(0,0); | |
| 197 | 195 | } |
| 196 | + etag_check(0,0); | |
| 198 | 197 | builtin_deliver_multiple_js_files(zM, zType); |
| 199 | 198 | return; |
| 200 | 199 | } |
| 201 | 200 | cgi_set_status(404, "Not Found"); |
| 202 | 201 | @ File "%h(zName)" not found |
| @@ -213,13 +212,12 @@ | ||
| 213 | 212 | if( zId |
| 214 | 213 | && (nId = (int)strlen(zId))>=8 |
| 215 | 214 | && strncmp(zId,fossil_exe_id(),nId)==0 |
| 216 | 215 | ){ |
| 217 | 216 | g.isConst = 1; |
| 218 | - }else{ | |
| 219 | - etag_check(0,0); | |
| 220 | 217 | } |
| 218 | + etag_check(0,0); | |
| 221 | 219 | blob_init(&out, zTxt, -1); |
| 222 | 220 | cgi_set_content(&out); |
| 223 | 221 | } |
| 224 | 222 | |
| 225 | 223 | /* Variables controlling the JS cache. |
| 226 | 224 |
| --- src/builtin.c | |
| +++ src/builtin.c | |
| @@ -190,13 +190,12 @@ | |
| 190 | if( zM ){ |
| 191 | if( zId && (nId = (int)strlen(zId))>=8 |
| 192 | && strncmp(zId,fossil_exe_id(),nId)==0 |
| 193 | ){ |
| 194 | g.isConst = 1; |
| 195 | }else{ |
| 196 | etag_check(0,0); |
| 197 | } |
| 198 | builtin_deliver_multiple_js_files(zM, zType); |
| 199 | return; |
| 200 | } |
| 201 | cgi_set_status(404, "Not Found"); |
| 202 | @ File "%h(zName)" not found |
| @@ -213,13 +212,12 @@ | |
| 213 | if( zId |
| 214 | && (nId = (int)strlen(zId))>=8 |
| 215 | && strncmp(zId,fossil_exe_id(),nId)==0 |
| 216 | ){ |
| 217 | g.isConst = 1; |
| 218 | }else{ |
| 219 | etag_check(0,0); |
| 220 | } |
| 221 | blob_init(&out, zTxt, -1); |
| 222 | cgi_set_content(&out); |
| 223 | } |
| 224 | |
| 225 | /* Variables controlling the JS cache. |
| 226 |
| --- src/builtin.c | |
| +++ src/builtin.c | |
| @@ -190,13 +190,12 @@ | |
| 190 | if( zM ){ |
| 191 | if( zId && (nId = (int)strlen(zId))>=8 |
| 192 | && strncmp(zId,fossil_exe_id(),nId)==0 |
| 193 | ){ |
| 194 | g.isConst = 1; |
| 195 | } |
| 196 | etag_check(0,0); |
| 197 | builtin_deliver_multiple_js_files(zM, zType); |
| 198 | return; |
| 199 | } |
| 200 | cgi_set_status(404, "Not Found"); |
| 201 | @ File "%h(zName)" not found |
| @@ -213,13 +212,12 @@ | |
| 212 | if( zId |
| 213 | && (nId = (int)strlen(zId))>=8 |
| 214 | && strncmp(zId,fossil_exe_id(),nId)==0 |
| 215 | ){ |
| 216 | g.isConst = 1; |
| 217 | } |
| 218 | etag_check(0,0); |
| 219 | blob_init(&out, zTxt, -1); |
| 220 | cgi_set_content(&out); |
| 221 | } |
| 222 | |
| 223 | /* Variables controlling the JS cache. |
| 224 |
+8
-8
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -303,24 +303,24 @@ | ||
| 303 | 303 | fprintf(g.httpOut, "X-UA-Compatible: IE=edge\r\n"); |
| 304 | 304 | }else{ |
| 305 | 305 | assert( rangeEnd==0 ); |
| 306 | 306 | fprintf(g.httpOut, "Status: %d %s\r\n", iReplyStatus, zReplyStatus); |
| 307 | 307 | } |
| 308 | - if( g.isConst ){ | |
| 308 | + if( etag_tag()[0]!=0 ){ | |
| 309 | + fprintf(g.httpOut, "ETag: %s\r\n", etag_tag()); | |
| 310 | + fprintf(g.httpOut, "Cache-Control: max-age=%d\r\n", etag_maxage()); | |
| 311 | + if( etag_mtime()>0 ){ | |
| 312 | + fprintf(g.httpOut, "Last-Modified: %s\r\n", | |
| 313 | + cgi_rfc822_datestamp(etag_mtime())); | |
| 314 | + } | |
| 315 | + }else if( g.isConst ){ | |
| 309 | 316 | /* isConst means that the reply is guaranteed to be invariant, even |
| 310 | 317 | ** after configuration changes and/or Fossil binary recompiles. */ |
| 311 | 318 | fprintf(g.httpOut, "Cache-Control: max-age=31536000\r\n"); |
| 312 | - }else if( etag_tag()[0]!=0 ){ | |
| 313 | - fprintf(g.httpOut, "ETag: %s\r\n", etag_tag()); | |
| 314 | - fprintf(g.httpOut, "Cache-Control: max-age=%d\r\n", etag_maxage()); | |
| 315 | 319 | }else{ |
| 316 | 320 | fprintf(g.httpOut, "Cache-control: no-cache\r\n"); |
| 317 | 321 | } |
| 318 | - if( etag_mtime()>0 ){ | |
| 319 | - fprintf(g.httpOut, "Last-Modified: %s\r\n", | |
| 320 | - cgi_rfc822_datestamp(etag_mtime())); | |
| 321 | - } | |
| 322 | 322 | |
| 323 | 323 | if( blob_size(&extraHeader)>0 ){ |
| 324 | 324 | fprintf(g.httpOut, "%s", blob_buffer(&extraHeader)); |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -303,24 +303,24 @@ | |
| 303 | fprintf(g.httpOut, "X-UA-Compatible: IE=edge\r\n"); |
| 304 | }else{ |
| 305 | assert( rangeEnd==0 ); |
| 306 | fprintf(g.httpOut, "Status: %d %s\r\n", iReplyStatus, zReplyStatus); |
| 307 | } |
| 308 | if( g.isConst ){ |
| 309 | /* isConst means that the reply is guaranteed to be invariant, even |
| 310 | ** after configuration changes and/or Fossil binary recompiles. */ |
| 311 | fprintf(g.httpOut, "Cache-Control: max-age=31536000\r\n"); |
| 312 | }else if( etag_tag()[0]!=0 ){ |
| 313 | fprintf(g.httpOut, "ETag: %s\r\n", etag_tag()); |
| 314 | fprintf(g.httpOut, "Cache-Control: max-age=%d\r\n", etag_maxage()); |
| 315 | }else{ |
| 316 | fprintf(g.httpOut, "Cache-control: no-cache\r\n"); |
| 317 | } |
| 318 | if( etag_mtime()>0 ){ |
| 319 | fprintf(g.httpOut, "Last-Modified: %s\r\n", |
| 320 | cgi_rfc822_datestamp(etag_mtime())); |
| 321 | } |
| 322 | |
| 323 | if( blob_size(&extraHeader)>0 ){ |
| 324 | fprintf(g.httpOut, "%s", blob_buffer(&extraHeader)); |
| 325 | } |
| 326 | |
| 327 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -303,24 +303,24 @@ | |
| 303 | fprintf(g.httpOut, "X-UA-Compatible: IE=edge\r\n"); |
| 304 | }else{ |
| 305 | assert( rangeEnd==0 ); |
| 306 | fprintf(g.httpOut, "Status: %d %s\r\n", iReplyStatus, zReplyStatus); |
| 307 | } |
| 308 | if( etag_tag()[0]!=0 ){ |
| 309 | fprintf(g.httpOut, "ETag: %s\r\n", etag_tag()); |
| 310 | fprintf(g.httpOut, "Cache-Control: max-age=%d\r\n", etag_maxage()); |
| 311 | if( etag_mtime()>0 ){ |
| 312 | fprintf(g.httpOut, "Last-Modified: %s\r\n", |
| 313 | cgi_rfc822_datestamp(etag_mtime())); |
| 314 | } |
| 315 | }else if( g.isConst ){ |
| 316 | /* isConst means that the reply is guaranteed to be invariant, even |
| 317 | ** after configuration changes and/or Fossil binary recompiles. */ |
| 318 | fprintf(g.httpOut, "Cache-Control: max-age=31536000\r\n"); |
| 319 | }else{ |
| 320 | fprintf(g.httpOut, "Cache-control: no-cache\r\n"); |
| 321 | } |
| 322 | |
| 323 | if( blob_size(&extraHeader)>0 ){ |
| 324 | fprintf(g.httpOut, "%s", blob_buffer(&extraHeader)); |
| 325 | } |
| 326 | |
| 327 |
+4
-1
| --- src/etag.c | ||
| +++ src/etag.c | ||
| @@ -97,11 +97,14 @@ | ||
| 97 | 97 | const char *zIfNoneMatch; |
| 98 | 98 | char zBuf[50]; |
| 99 | 99 | assert( zETag[0]==0 ); /* Only call this routine once! */ |
| 100 | 100 | |
| 101 | 101 | if( etagCancelled ) return; |
| 102 | - iMaxAge = 86400; | |
| 102 | + | |
| 103 | + /* By default, ETagged URLs never expire since the ETag will change | |
| 104 | + * when the content changes. Approximate this policy as 10 years. */ | |
| 105 | + iMaxAge = 10 * 365 * 24 * 60 * 60; | |
| 103 | 106 | md5sum_init(); |
| 104 | 107 | |
| 105 | 108 | /* Always include the executable ID as part of the hash */ |
| 106 | 109 | md5sum_step_text("exe-id: ", -1); |
| 107 | 110 | md5sum_step_text(fossil_exe_id(), -1); |
| 108 | 111 |
| --- src/etag.c | |
| +++ src/etag.c | |
| @@ -97,11 +97,14 @@ | |
| 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); |
| 107 | md5sum_step_text(fossil_exe_id(), -1); |
| 108 |
| --- src/etag.c | |
| +++ src/etag.c | |
| @@ -97,11 +97,14 @@ | |
| 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 |
| 104 | * when the content changes. Approximate this policy as 10 years. */ |
| 105 | iMaxAge = 10 * 365 * 24 * 60 * 60; |
| 106 | md5sum_init(); |
| 107 | |
| 108 | /* Always include the executable ID as part of the hash */ |
| 109 | md5sum_step_text("exe-id: ", -1); |
| 110 | md5sum_step_text(fossil_exe_id(), -1); |
| 111 |
+1
| --- src/style.c | ||
| +++ src/style.c | ||
| @@ -1026,10 +1026,11 @@ | ||
| 1026 | 1026 | Blob css = empty_blob; |
| 1027 | 1027 | int i; |
| 1028 | 1028 | const char * zDefaults; |
| 1029 | 1029 | |
| 1030 | 1030 | cgi_set_content_type("text/css"); |
| 1031 | + etag_check(0, 0); | |
| 1031 | 1032 | /* Emit all default rules... */ |
| 1032 | 1033 | zDefaults = (const char*)builtin_file("default.css", &i); |
| 1033 | 1034 | blob_append(&css, zDefaults, i); |
| 1034 | 1035 | /* Page-specific CSS, if any... */ |
| 1035 | 1036 | page_style_css_append_page_style(&css); |
| 1036 | 1037 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -1026,10 +1026,11 @@ | |
| 1026 | Blob css = empty_blob; |
| 1027 | int i; |
| 1028 | const char * zDefaults; |
| 1029 | |
| 1030 | cgi_set_content_type("text/css"); |
| 1031 | /* Emit all default rules... */ |
| 1032 | zDefaults = (const char*)builtin_file("default.css", &i); |
| 1033 | blob_append(&css, zDefaults, i); |
| 1034 | /* Page-specific CSS, if any... */ |
| 1035 | page_style_css_append_page_style(&css); |
| 1036 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -1026,10 +1026,11 @@ | |
| 1026 | Blob css = empty_blob; |
| 1027 | int i; |
| 1028 | const char * zDefaults; |
| 1029 | |
| 1030 | cgi_set_content_type("text/css"); |
| 1031 | etag_check(0, 0); |
| 1032 | /* Emit all default rules... */ |
| 1033 | zDefaults = (const char*)builtin_file("default.css", &i); |
| 1034 | blob_append(&css, zDefaults, i); |
| 1035 | /* Page-specific CSS, if any... */ |
| 1036 | page_style_css_append_page_style(&css); |
| 1037 |