mod_xsendfile is a small Apache2 module that processes X-SENDFILE headers output handlers might have registered.
If it encounters the presence of such header it will discard all output and send the file specified by that header instead using Apache internals including all optimizations like caching-headers and sendfile or mmap if configured.
It is useful for processing script-output of e.g. php, perl, python or any *cgi.
Yep, it is useful.
apxs -cia mod_xsendfile.c
apxs2 -cia mod_xsendfile.c
apxs -cia -Wc,"-arch i386 -arch x86_64" -Wl,"-arch i386 -arch x86_64" mod_xsendfile.c
X-SENDFILE
- Send the file referenced by this headers instead of the current response bodyX-SENDFILE-TEMPORARY
- Like X-SENDFILE
, but the file will be deleted afterwards. The file must originate from a path that has the AllowFileDelete
flag set.Description Enables or disables header processing
Syntax XSendFile on | off
Default XSendFile off
Context Server config, virtual host, directory, .htaccess
Setting XSendFile on
will enable processing
The file specified in X-SENDFILE
header will be sent instead of the handler output.
The value (file name) given by the header is assmumed to be url-encoded, i.e. unescaping/url-decoding will be performed. See XSendFileUnescape. If you happen to store files using already url-encoded file names, you must “double” encode the names… %20 -> %2520
If the response lacks the X-SENDFILE
header the module will not perform any processing.
Description Ignore script provided Etag headers
Syntax XSendFileIgnoreEtag on | off
Default XSendFileIgnoreEtag off
Context Server config, virtual host, directory, .htaccess
Setting XSendFileIgnoreEtag on
will ignore all ETag headers the original output handler may have set. This is helpful for applications that will generate such headers even for empty content.
Description Ignore script provided LastModified headers
Syntax XSendFileIgnoreLastModified on | off
Default XSendFileIgnoreLastModified off
Context Server config, virtual host, directory, .htaccess
Setting XSendFileIgnoreLastModified on
will ignore all Last-Modified headers the original output handler may have set. This is helpful for applications that will generate such headers even for empty content.