I emailed the IETF HTTP group about my timeout header idea1, and a few people said that RFC 72402's "wait" preference3 does what I want. I'm not entirely convinced that this is what was intended by that spec, but it's close enough. In response, I've updated my Express middleware4 to support the "Prefer" header and "wait" preference.
While I was at it, I also added some tests5, using Mocha6 and SuperTest7.
Existing file
✓ responds immediately
✓ waits for etag to change before responding if If-None-Match sent (2013ms)
Non-existing file
✓ responds immediately with 404 without header
✓ responds with 404 if timeout expires (4006ms)
✓ responds with 200 if file is created before timeout expires (2003ms)
✓ ignores non-integer waits
✓ responds with 404 if server timeout expires (1003ms)
✓ responds with 404 if client timeout expires (1002ms)
Existing index files
✓ responds immediately for index existing-index.html
Non-existing index files
✓ responds immediately with 404 without header
✓ responds with 404 if timeout expires (4006ms)
✓ responds with 200 if file is created before timeout expires (2007ms)
Prefer Header Parsing
✓ handles no Prefer header
✓ handles non-matching preference with no value
✓ handles non-matching preference with value
✓ handles matching preference with no value
✓ handles matching preference with value
✓ handles matching preference with value and other preferences
✓ handles duplicate preference with one value
✓ handles duplicate preference with multiple values
20 passing (16s)
The "wait" preference is in seconds, which makes the tests much slower. But, it's a small price to pay to use pre-existing functionality (since the whole point of this proposal is to avoid reinventing wheels).
My testing kick also extended to the MPEG-TS media segment DASH conformance tests, and I'll post about that sometime soon.
https://www.brendanlong.com/http-timeout-header-for-requesting-resources-from-the-future.html - "HTTP "Timeout" header for requesting resources from the future"
http://tools.ietf.org/html/rfc7240 - "RFC 7240 - Prefer Header for HTTP"
http://tools.ietf.org/html/rfc7240#section-4.3 - "RFC 7240 - Prefer Header for HTTP"
https://github.com/brendanlong/express-prefer-wait - "GitHub - brendanlong/express-prefer-wait: Express middleware for handling HTTP 'Prefer: wait' header for static files"
https://github.com/brendanlong/express-prefer-wait/blob/master/test.js - "express-prefer-wait/test.js at master · brendanlong/express-prefer-wait · GitHub"
http://mochajs.org/ - "Mocha | Classic, reliable, trusted. ☕"
https://github.com/visionmedia/supertest - "GitHub - forwardemail/supertest: 🕷 Super-agent driven library for testing node.js HTTP servers using a fluent API. Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs."