Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var Utils = require("utils"),
Mime = require("mime").Mime;
var Jack_File = exports.File = function(root) {
return function(env) {
var pathInfo = Utils.unescape(env["PATH_INFO"]);
if (pathInfo.indexOf("..") >= 0)
return Jack_File.forbidden();
var path = pathInfo ? File.join(root, pathInfo) : root; // don't want to append a "/" if PATH_INFO is empty
try {
if (File.isReadable(path)) {
// efficiently serve files if the server supports "X-Sendfile"
if (false && env["HTTP_X_ALLOW_SENDFILE"]) {
return [200, {
"X-Sendfile" : path,
* @since 0.1.0
* @requires accepts
* @requires mime
* @requires mime/types
* @requires mout/array/intersection
*/
var accepts = require( 'accepts' )
, mime = require( 'mime' )
, intersection = require( 'mout/array/intersection' )
, types = require('mime/types')
;
const EMPTY_STRING = '';
class Mime extends mime.Mime {
constructor(){
super();
this.default_type = null;
this.define( types );
}
lookup( format, fallback ){
return super.lookup( format || EMPTY_STRING, fallback );
}
extension( ext ){
return super.extension( ext || EMPTY_STRING );
}
/**
* best guess determination of request mime type from Accept header