mjackson/mach

View on GitHub
modules/middleware/charset.js

Summary

Maintainability
A
0 mins
Test Coverage
/**
 * A middleware that sets a default character set in the Content-Type
 * header of the response if none is already specified.
 */
function charset(app, defaultCharset) {
  defaultCharset = defaultCharset || 'utf-8';

  return function (conn) {
    return conn.call(app).then(function () {
      var response = conn.response;

      if (response.contentType && response.charset == null)
        response.charset = defaultCharset;
    });
  };
}

module.exports = charset;