Merge branch 'master' of git://github.com/guox191/anyproxy into guox191-master

This commit is contained in:
xiaofeng.mxf
2019-03-25 14:00:59 +08:00
8 changed files with 141 additions and 53 deletions

View File

@@ -247,18 +247,16 @@ class Recorder extends events.EventEmitter {
bodyContent = iconv.decode(bodyContent, currentCharset);
}
result.mime = contentType;
result.content = bodyContent.toString();
result.type = contentType && /application\/json/i.test(contentType) ? 'json' : 'text';
} else if (contentType && /image/i.test(contentType)) {
result.type = 'image';
result.mime = contentType;
result.content = bodyContent;
} else {
result.type = contentType;
result.mime = contentType;
result.content = bodyContent.toString();
}
result.mime = contentType;
result.fileName = path.basename(record.path);
result.statusCode = record.statusCode;
} catch (e) {

View File

@@ -120,7 +120,7 @@ function fetchRemoteResponse(protocol, options, reqData, config) {
// only do unzip when there is res data
if (ifServerGzipped && originContentLen) {
refactContentEncoding();
zlib.gunzip(serverResData, (err, buff) => { // TODO test case to cover
zlib.gunzip(serverResData, (err, buff) => {
if (err) {
rejectParsing(err);
} else {
@@ -129,7 +129,7 @@ function fetchRemoteResponse(protocol, options, reqData, config) {
});
} else if (isServerDeflated && originContentLen) {
refactContentEncoding();
zlib.inflateRaw(serverResData, (err, buff) => { // TODO test case to cover
zlib.inflateRaw(serverResData, (err, buff) => {
if (err) {
rejectParsing(err);
} else {

View File

@@ -146,10 +146,8 @@ class webInterface extends events.EventEmitter {
if (err || !result) {
res.json({});
} else if (result.statusCode === 200 && result.mime) {
if (result.type === 'json' ||
result.mime.indexOf('text') === 0 ||
// deal with 'application/x-javascript' and 'application/javascript'
result.mime.indexOf('javascript') > -1) {
// deal with 'application/x-javascript' and 'application/javascript'
if (/json|text|javascript/.test(result.mime)) {
_resContent();
} else if (result.type === 'image') {
_resDownload(false);