71 lines
5.2 KiB
JavaScript
71 lines
5.2 KiB
JavaScript
"use strict";
|
|
|
|
/**
|
|
* Return the mime type for the given `str`.
|
|
*
|
|
* @param {String} str
|
|
* @return {String}
|
|
* @api private
|
|
*/
|
|
exports.type = function (str) {
|
|
return str.split(/ *; */).shift();
|
|
};
|
|
/**
|
|
* Return header field parameters.
|
|
*
|
|
* @param {String} str
|
|
* @return {Object}
|
|
* @api private
|
|
*/
|
|
|
|
|
|
exports.params = function (str) {
|
|
return str.split(/ *; */).reduce(function (obj, str) {
|
|
var parts = str.split(/ *= */);
|
|
var key = parts.shift();
|
|
var val = parts.shift();
|
|
if (key && val) obj[key] = val;
|
|
return obj;
|
|
}, {});
|
|
};
|
|
/**
|
|
* Parse Link header fields.
|
|
*
|
|
* @param {String} str
|
|
* @return {Object}
|
|
* @api private
|
|
*/
|
|
|
|
|
|
exports.parseLinks = function (str) {
|
|
return str.split(/ *, */).reduce(function (obj, str) {
|
|
var parts = str.split(/ *; */);
|
|
var url = parts[0].slice(1, -1);
|
|
var rel = parts[1].split(/ *= */)[1].slice(1, -1);
|
|
obj[rel] = url;
|
|
return obj;
|
|
}, {});
|
|
};
|
|
/**
|
|
* Strip content related fields from `header`.
|
|
*
|
|
* @param {Object} header
|
|
* @return {Object} header
|
|
* @api private
|
|
*/
|
|
|
|
|
|
exports.cleanHeader = function (header, changesOrigin) {
|
|
delete header['content-type'];
|
|
delete header['content-length'];
|
|
delete header['transfer-encoding'];
|
|
delete header.host; // secuirty
|
|
|
|
if (changesOrigin) {
|
|
delete header.authorization;
|
|
delete header.cookie;
|
|
}
|
|
|
|
return header;
|
|
};
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy91dGlscy5qcyJdLCJuYW1lcyI6WyJleHBvcnRzIiwidHlwZSIsInN0ciIsInNwbGl0Iiwic2hpZnQiLCJwYXJhbXMiLCJyZWR1Y2UiLCJvYmoiLCJw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