Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}), function (foundAsset, cb) {
if (!foundAsset.isLoaded || foundAsset === asset || !foundAsset.url) {
return setImmediate(cb);
}
var headers = {
// 'cache-control': 'max-age=0, must-revalidate',
'content-type': mime.types[foundAsset.extension.substr(1) || 'application/octet-stream'],
etag: '"' + foundAsset.md5Hex + '"'
},
path = foundAsset.url.replace(assetGraph.root, '/'),
stream = res.push(path, headers),
hasEnded = false;
stream
.on('error', function (err) {
err.message = path + ': push stream emitted error - ' + err.message;
console.error(err);
if (!hasEnded) {
hasEnded = true;
cb();
}
})
.on('acknowledge', function () {
}
}
function response (view, opts) {
return new Response(view, opts)
}
var typemap = {};
typemap['txt'] = function(view) {
return (typeof view != 'string') ? view.toString() : view
}
typemap['json'] = function(view) {
return JSON.stringify(view)
}
Object.keys(mime.types).forEach(function (mimeName) {
// set mime convenience methods
function _response (view, opts) {
view = (typemap[mimeName]) ? typemap[mimeName](view) : view
var r = response(view, opts)
r.setHeader('content-type', mime.types[mimeName])
return r
}
response[mimeName] = _response
// set mime methods
Response.prototype[mimeName] = function (view) {
view = (typemap[mimeName]) ? typemap[mimeName](view) : view
var self = this
self.setHeader('content-type', mime.types[mimeName])
process.nextTick(function () {
self.end(view)
function getRandomType () {
var type = mime.types[keys[Math.floor(Math.random() * keys.length)]]
return type + mime.charsets.lookup(type)
}
var add_mime = function(){
var len = Object.keys(mime.types).length;
var types = mime.types;
var types_keys = Object.keys(mime.types);
var mime_name_array = [];
var mime_type_array = [];
for(var i=0;i
var add_mime = function(){
var len = Object.keys(mime.types).length;
var types = mime.types;
var types_keys = Object.keys(mime.types);
var mime_name_array = [];
var mime_type_array = [];
for(var i=0;i
var assert = require('assert')
, Benchmark = require('benchmark')
, suite = new Benchmark.Suite
, mime = require('mime')
, keys = Object.keys(mime.types)
, compressible = require('./index.js')
, benchmarks = require('beautify-benchmark')
function getRandomType () {
var type = mime.types[keys[Math.floor(Math.random() * keys.length)]]
return type + mime.charsets.lookup(type)
}
function legacy (type) {
if (!type || typeof type !== "string") return false
var spec = compressible.specs[type.split(';')]
return spec ? spec.compressible : compressible.regex.test(type)
}
function previous (type) {
if (!type || typeof type !== "string") return false
function sendAsset(asset, req, res, next) {
var contentType = mime.types[asset.extension.substr(1) || 'application/octet-stream'],
etag = '"' + asset.md5Hex + '"',
ifNoneMatchHeaderValue = req.headers['if-none-match'];
if (ifNoneMatchHeaderValue && ifNoneMatchHeaderValue.indexOf(etag) !== -1) {
return res.send(304);
}
res.setHeader('Content-Type', contentType);
res.setHeader('ETag', etag);
if (req.isSpdy && contentType === 'text/html') {
res.write(asset.rawSrc);
async.each(assetGraph.collectAssetsPreOrder(asset, {
type: query.not(['HtmlAnchor', 'JavaScriptSourceMappingUrl', 'JavaScriptSourceUrl']),
to: {
function _response (view, opts) {
view = (typemap[mimeName]) ? typemap[mimeName](view) : view
var r = response(view, opts)
r.setHeader('content-type', mime.types[mimeName])
return r
}
response[mimeName] = _response
function getRandomType () {
var type = mime.types[keys[Math.floor(Math.random() * keys.length)]]
return type + mime.charsets.lookup(type)
}