<commit_before>define(['conf', 'requirejs', 'mime', 'path', 'fs', 'fileCache'], function(conf, requirejs, mime, path, fs, fileCache) {
    mime.define({
        'text/css': ['less'],
        'text/html': ['hb'],
        'text/plain': ['md']
    });

	return {
		title: '',
		pageletCount: 1,
		handle: function(request, response) {
			var contentType = mime.lookup(request.url);

			if (conf.file.allowedMimes.indexOf(contentType) > -1) {
                // the request.url has the form of /js/main.js
                // since this script is being executed relative to
                // the root directory, we simply add '.' to
                // indicate the root directory.
				var filePath = path.join('.', request.url),
                    fileExtension = path.extname(filePath),
                    fileHandlerStatCallback = function (err, stat) {
                        if (err) {
                            requirejs(['error_handler'], function(error_handler){
                                error_handler.handle(request, response, err);
                            });
                        }
                        else {
                            var etag = stat.ino + '-' + stat.size + '-' + Date.parse(stat.mtime);
                            response.setHeader('Last-Modified', stat.mtime);

                            if (request.headers['if-none-match'] === etag) {
                                response.statusCode = 304;
                                response.end();
                            }
                            else {
                                response.setHeader('Content-Type', contentType);
                                response.setHeader('ETag', etag);
                                response.statusCode = 200;

                                fs.createReadStream(filePath).pipe(response);
                            }
                        }
                    },
                    fileHandlerPath = path.resolve(path.join(conf.app.engine, 'fileHandlers', fileExtension.replace(/\./, '') + '.js'));

                fs.exists(fileHandlerPath, function (exists) {
                    if (exists) {
                        requirejs([fileHandlerPath], function(processFile){
                            processFile(request, response, conf.file.handlerOptions[fileExtension]);
                        });
                    }
                    else{
                        fileCache.stats.get(filePath, fileHandlerStatCallback);
                    }
                });
			}
			else{
				requirejs(['error_handler'], function(error_handler){
					error_handler.handle(request, response, {errno: 403});
				});
			}
		}
	};
});<commit_msg>Don't allow directories to be requested. Return 403 Forbidden error.<commit_after>define(['conf', 'requirejs', 'mime', 'path', 'fs', 'fileCache', 'error_handler'], function(conf, requirejs, mime, path, fs, fileCache, error_handler) {
    mime.define({
        'text/css': ['less'],
        'text/html': ['hb'],
        'text/plain': ['md']
    });

	return {
		title: '',
		pageletCount: 1,
		handle: function(request, response) {
			var contentType = mime.lookup(request.url);
            // Is this type of file allowed to be served?
			if (conf.file.allowedMimes.indexOf(contentType) > -1) {
                // Make sure user doesn't try to access restricted areas
                // using "../" relative path. Then prepend ".", indicating
                // that the file lookup should be relative to the app root
                // directory.
                var filePath = path.join('.', request.url.replace(/\.\.\//g, '')),
                    fileExtension = path.extname(filePath);
                // If no file extension is found, this should be a directory,
                // and directory lookup is not permitted in Pulsr.
                if (!fileExtension) {
                    error_handler.handle(request, response, {errno: 403});
                }
                else{
                    var fileHandlerPath = path.resolve(path.join(conf.app.engine, 'fileHandlers', fileExtension.replace(/\./, '') + '.js'));

                    fs.exists(fileHandlerPath, function (exists) {
                        if (exists) {
                            requirejs([fileHandlerPath], function(processFile){
                                processFile(request, response, conf.file.handlerOptions[fileExtension]);
                            });
                        }
                        else{
                            fileCache.stats.get(filePath, function (err, stat) {
                                if (err) {
                                    error_handler.handle(request, response, err);
                                }
                                else {
                                    var etag = stat.ino + '-' + stat.size + '-' + Date.parse(stat.mtime);
                                    response.setHeader('Last-Modified', stat.mtime);

                                    if (request.headers['if-none-match'] === etag) {
                                        response.statusCode = 304;
                                        response.end();
                                    }
                                    else {
                                        response.setHeader('Content-Type', contentType);
                                        response.setHeader('ETag', etag);
                                        response.statusCode = 200;

                                        fs.createReadStream(filePath).pipe(response);
                                    }
                                }
                            });
                        }
                    });
                }
			}
			else{
                error_handler.handle(request, response, {errno: 403});
			}
		}
	};
});
{'fraction_non_alphanumeric': 0.11596180081855388, 'fraction_numerical': 0.0047748976807639835, 'mean_word_length': 1.1350564251911175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1638283', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1313, 'n_words': 286}