UNPKG

strata

Version:

A modular, streaming HTTP server

20 lines (16 loc) 475 B
/** * A middleware that sets a default Content-Type header in case one hasn't * already been set in a downstream app. */ module.exports = function (app, defaultType) { defaultType = defaultType || 'text/html'; function contentType(env, callback) { app(env, function (status, headers, body) { if (!headers['Content-Type']) { headers['Content-Type'] = defaultType; } callback(status, headers, body); }); } return contentType; };