Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,12 @@
'use strict';
module.exports = (res, fn) => {
const data = []; // Binary data needs binary storage
res.on('data', chunk => {
data.push(chunk);
});
res.on('end', () => {
fn(null, Buffer.concat(data));
});
};

View File

@@ -0,0 +1,10 @@
'use strict';
exports['application/x-www-form-urlencoded'] = require('./urlencoded');
exports['application/json'] = require('./json');
exports.text = require('./text');
const binary = require('./image');
exports['application/octet-stream'] = binary;
exports['application/pdf'] = binary;
exports.image = binary;

View File

@@ -0,0 +1,22 @@
'use strict';
module.exports = function parseJSON(res, fn){
res.text = '';
res.setEncoding('utf8');
res.on('data', chunk => {
res.text += chunk;
});
res.on('end', () => {
try {
var body = res.text && JSON.parse(res.text);
} catch (e) {
var err = e;
// issue #675: return the raw response if the response parsing fails
err.rawResponse = res.text || null;
// issue #876: return the http status code if the response parsing fails
err.statusCode = res.statusCode;
} finally {
fn(err, body);
}
});
};

View File

@@ -0,0 +1,10 @@
'use strict';
module.exports = function(res, fn){
res.text = '';
res.setEncoding('utf8');
res.on('data', chunk => {
res.text += chunk;
});
res.on('end', fn);
};

View File

@@ -0,0 +1,22 @@
'use strict';
/**
* Module dependencies.
*/
const qs = require('qs');
module.exports = function(res, fn){
res.text = '';
res.setEncoding('ascii');
res.on('data', chunk => {
res.text += chunk;
});
res.on('end', () => {
try {
fn(null, qs.parse(res.text));
} catch (err) {
fn(err);
}
});
};