Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

@@ -243,7 +243,9 @@ function parseHeader(str) {
*/
function isJSON(mime) {
return /[\/+]json\b/.test(mime);
// should match /json or +json
// but not /json-seq
return /[\/+]json($|[^-\w])/.test(mime);
}
/**

View File

@@ -164,7 +164,7 @@ RequestBase(Request.prototype);
*
* ``` js
* request.post('http://localhost/upload')
* .attach(new Buffer('<b>Hello world</b>'), 'hello.html')
* .attach('field', Buffer.from('<b>Hello world</b>'), 'hello.html')
* .end(callback);
* ```
*
@@ -688,20 +688,23 @@ Request.prototype.callback = function(err, res){
if (!err) {
try {
if (this._isResponseOK(res)) {
return fn(err, res);
if (!this._isResponseOK(res)) {
let msg = 'Unsuccessful HTTP response';
if (res) {
msg = http.STATUS_CODES[res.status] || msg;
}
err = new Error(msg);
err.status = res ? res.status : undefined;
}
let msg = 'Unsuccessful HTTP response';
if (res) {
msg = http.STATUS_CODES[res.status] || msg;
}
err = new Error(msg);
err.status = res ? res.status : undefined;
} catch (new_err) {
err = new_err;
}
}
// It's important that the callback is called outside try/catch
// to avoid double callback
if (!err) {
return fn(null, res);
}
err.response = res;
if (this._maxRetries) err.retries = this._retries - 1;
@@ -1064,7 +1067,9 @@ function isImageOrVideo(mime) {
*/
function isJSON(mime) {
return /[\/+]json\b/.test(mime);
// should match /json or +json
// but not /json-seq
return /[\/+]json($|[^-\w])/.test(mime);
}
/**