How to use the mime-types.charsets function in mime-types

To help you get started, we’ve selected a few mime-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sintaxi / harp / lib / index.js View on Github external
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)
    })
github wenshin / http-proxy-stream / lib / mime.js View on Github external
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};
}
github sintaxi / harp / lib / middleware.js View on Github external
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)
  })
}
github silverwind / droppy / server / utils.js View on Github external
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";
    }
  }
};