Skip to content
Myr

Use media-typer to alter content-type charset

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 7d6208e · Browse files · 3 files+9 added−20 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+9 added−20 removed

  • other:+9 added−20 removed

3 files+9 added−20 removed

modified:lib/utils.js+7 added-20 removed
5 unmodified lines
6var mime = require('connect').mime7 , proxyaddr = require('proxy-addr')8 , crc32 = require('buffer-crc32')9 , crypto = require('crypto');10var typer = require('media-typer');1112/**13 * toString ref.14 */1516var toString = {}.toString;1718/**18 * Simple detection of charset parameter in content-type19 */20var charsetRegExp = /;\s*charset\s*=/;2122/**19 * Return strong ETag for `body`.20 *21 * @param {String|Buffer} body22 * @param {String} [encoding]
383 unmodified lines
406407exports.setCharset = function(type, charset){408 if (!type || !charset) return type;409414 var exists = charsetRegExp.test(type);410 // parse type411 var parsed = typer.parse(type);412416 // removing existing charset417 if (exists) {418 var parts = type.split(';');413 // set charset414 parsed.parameters.charset = charset;415420 for (var i = 1; i < parts.length; i++) {421 if (charsetRegExp.test(';' + parts[i])) {422 parts.splice(i, 1);423 break;424 }425 }426427 type = parts.join(';');428 }429430 return type + '; charset=' + charset;416 // format type417 return typer.format(parsed);418};
modified:History.md+1 added
1unreleased2==========34 * use `media-typer` to alter content-type charset5 * deps: connect@2.21.06 - deprecate `connect(middleware)` -- use `app.use(middleware)` instead7 - deprecate `connect.createServer()` -- use `connect()` instead8 - fix `res.setHeader()` patch to work with with get -> append -> set pattern
1474 unmodified lines
modified:package.json+1 added