Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
terra.render(sourceFile, function(error, body){
if(error) return next(error)
if(!body) return next() // 404
var outputType = terraform.helpers.outputType(sourceFile)
var mimeType = helpers.mimeType(outputType)
var charset = mime.charsets.lookup(mimeType)
rsp.statusCode = 200
rsp.setHeader('Content-Type', mimeType + (charset ? '; charset=' + charset : ''))
rsp.setHeader('Content-Length', Buffer.byteLength(body, charset));
rsp.end(body)
})
function parseContentType(contentType) {
let safeValue = contentType.trim();
if (safeValue.endsWith(';')) {
safeValue = safeValue.slice(0, -1);
}
const {type, parameters} = ct.parse(safeValue);
// may some one will set content tyoe application/octet-stream; charset=UTF-8.
// so when the mime not the text type, we use mimeLib.charsets.lookup to get charset
const charset = isText(type) && parameters.charset || mimeLib.charsets.lookup(type);
return {type, charset, parameters};
}
terraform.root(__dirname + "/templates").render("404.jade", locals, function(err, body){
var type = helpers.mimeType("html")
var charset = mime.charsets.lookup(type)
rsp.setHeader('Content-Type', type + (charset ? '; charset=' + charset : ''));
rsp.statusCode = 404
rsp.setHeader('Content-Length', Buffer.byteLength(body, charset));
rsp.end(body)
})
}
utils.contentType = function(p) {
const type = mimeTypes.lookup(p);
if (overrideMimeTypes[type]) return overrideMimeTypes[type];
if (type) {
const charset = mimeTypes.charsets.lookup(type);
return type + (charset ? "; charset=" + charset : "");
} else {
try {
return isbinaryfile.isBinaryFileSync(p) ? "application/octet-stream" : "text/plain";
} catch (err) {
return "application/octet-stream";
}
}
};