[PATCH] X-Sendfile-Range header support
I've implemented an X-Sendfile-Range header to be used in conjunction with the X-Sendfile/X-LIGHTTPD-send-file headers that allows for specifying the range of bytes to serve from the file specified by the X-Sendfile header. This header is extremely useful. As one example, it makes pseudo-streaming and FLV from within a FastCGI application trivial, without having to jump through hoops with mod_magnet (as there is no response headers magnet yet in 1.4,) or upgrade to 1.5. This is very important, in my opinion, due to the conflicts with luasocket function names in lighttpd, disallowing the use of something like LUA's memcache module to pass information between the FastCGI app and mod_magnet.
My implementation requires the following header field definition:
X-Sendfile-Range: x y
Where, in this case, x is the first byte to serve (zero-based,) and y is the final byte to serve + 1.
X-Sendfile-Range: 5 7000
If the X-Sendfile-Range header is absent, functionality is identical in that the entire file is served by default. If it is present, it is parsed and its values are applied to the http_chunk_append_file function. The dynamically defined Content-Length header is also updated with the appropriate Content-Length based on the range given. Finally, the X-Sendfile-Range header is removed after being processed, so that it never makes it to the client.
I've tested this very much locally, and hope to have the attached patch pushed in an upcoming 1.4.x release. The attached patch is against r2522 of the lighttpd-1.4.x branch. Please let me know if you've any questions or concerns. Thanks!
Add X-Sendfile-Range feature (fixes #2005)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2531 152afb58-edef-0310-8abb-c4023f1b3aa9
Also available in: Atom