all files / modules/middleware/ charset.js

100% Statements 9/9
83.33% Branches 5/6
100% Functions 3/3
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21                       
/**
 * A middleware that sets a default character set in the Content-Type
 * header of the response if none is already specified.
 */
const {isNil} = require("ramda");
function charset(app, defaultCharset) {
    defaultCharset = defaultCharset || "utf-8";
 
    return function (conn) {
        return conn.call(app).then(function () {
            const response = conn.response;
 
            if (response.contentType && isNil(response.charset)) {
                response.charset = defaultCharset;
            }
        });
    };
}
 
module.exports = charset;