Skip to content

Commit

Permalink
fix: fixed content-type case-sensitivity (closes #1572)
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Aug 8, 2020
1 parent e88a13f commit 44fadf9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function parseHeader(str) {
function isJSON(mime) {
// should match /json or +json
// but not /json-seq
return /[/+]json($|[^-\w])/.test(mime);
return /[/+]json($|[^-\w])/i.test(mime);
}

/**
Expand Down
14 changes: 9 additions & 5 deletions src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,8 @@ Request.prototype._end = function() {

const max = this._maxRedirects;
const mime = utils.type(res.headers['content-type'] || '') || 'text/plain';
const type = mime.split('/')[0];
let type = mime.split('/')[0];
if (type) type = type.toLowerCase().trim();
const multipart = type === 'multipart';
const redirect = isRedirect(res.statusCode);
const responseType = this._responseType;
Expand Down Expand Up @@ -1331,14 +1332,17 @@ methods.forEach(method => {

function isText(mime) {
const parts = mime.split('/');
const type = parts[0];
const subtype = parts[1];
let type = parts[0];
if (type) type = type.toLowerCase().trim();
let subtype = parts[1];
if (subtype) subtype = subtype.toLowerCase().trim();

return type === 'text' || subtype === 'x-www-form-urlencoded';
}

function isImageOrVideo(mime) {
const type = mime.split('/')[0];
let type = mime.split('/')[0];
if (type) type = type.toLowerCase().trim();

return type === 'image' || type === 'video';
}
Expand All @@ -1354,7 +1358,7 @@ function isImageOrVideo(mime) {
function isJSON(mime) {
// should match /json or +json
// but not /json-seq
return /[/+]json($|[^-\w])/.test(mime);
return /[/+]json($|[^-\w])/i.test(mime);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/request-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ RequestBase.prototype.send = function(data) {
// default to x-www-form-urlencoded
if (!type) this.type('form');
type = this._header['content-type'];
if (type) type = type.toLowerCase().trim();
if (type === 'application/x-www-form-urlencoded') {
this._data = this._data ? `${this._data}&${data}` : data;
} else {
Expand Down

0 comments on commit 44fadf9

Please sign in to comment.