Fossil SCM
Rearranged the order and conditional status of paths leading to ETag HTTP header generation to cause them to be generated in more cases. This improves caching in my testing, but it needs to be vetted before it can be merged down to trunk. The main risk is that it causes over-aggressive caching, resulting in stale data delivery.
Commit
bc0b20356a0b508eb3d97a9da3f6c899d415c384497244b0e4f5e00d1cc47a58
Parent
7913bba6109d8a1…
2 files changed
+2
-4
+8
-8
+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 |