Skip to content

Commit 44fadf9

Browse files
committed
fix: fixed content-type case-sensitivity (closes #1572)
1 parent e88a13f commit 44fadf9

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ function parseHeader(str) {
275275
function isJSON(mime) {
276276
// should match /json or +json
277277
// but not /json-seq
278-
return /[/+]json($|[^-\w])/.test(mime);
278+
return /[/+]json($|[^-\w])/i.test(mime);
279279
}
280280

281281
/**

src/node/index.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,8 @@ Request.prototype._end = function() {
10141014

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

13321333
function isText(mime) {
13331334
const parts = mime.split('/');
1334-
const type = parts[0];
1335-
const subtype = parts[1];
1335+
let type = parts[0];
1336+
if (type) type = type.toLowerCase().trim();
1337+
let subtype = parts[1];
1338+
if (subtype) subtype = subtype.toLowerCase().trim();
13361339

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

13401343
function isImageOrVideo(mime) {
1341-
const type = mime.split('/')[0];
1344+
let type = mime.split('/')[0];
1345+
if (type) type = type.toLowerCase().trim();
13421346

13431347
return type === 'image' || type === 'video';
13441348
}
@@ -1354,7 +1358,7 @@ function isImageOrVideo(mime) {
13541358
function isJSON(mime) {
13551359
// should match /json or +json
13561360
// but not /json-seq
1357-
return /[/+]json($|[^-\w])/.test(mime);
1361+
return /[/+]json($|[^-\w])/i.test(mime);
13581362
}
13591363

13601364
/**

src/request-base.js

+1
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ RequestBase.prototype.send = function(data) {
623623
// default to x-www-form-urlencoded
624624
if (!type) this.type('form');
625625
type = this._header['content-type'];
626+
if (type) type = type.toLowerCase().trim();
626627
if (type === 'application/x-www-form-urlencoded') {
627628
this._data = this._data ? `${this._data}&${data}` : data;
628629
} else {

0 commit comments

Comments
 (0)