diff --git a/CHANGELOG b/CHANGELOG index 8e60dcd..7499b19 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +22 Jan 2015: anyproxy 3.1.1: + + * convert GBK to UTF8 in web interface + 22 Jan 2015: anyproxy 3.1.0: * will NOT intercept https request by default. Use ``anyproxy --intercept`` to turn on this feature. diff --git a/lib/recorder.js b/lib/recorder.js index a2f546c..99b3257 100644 --- a/lib/recorder.js +++ b/lib/recorder.js @@ -73,15 +73,16 @@ function Recorder(option){ if(!id || !info.resBody) return; //add to body map - //do not save image data + //ignore image data if(/image/.test(info.resHeader['content-type'])){ self.recordBodyMap[id] = "(image)"; }else{ - self.recordBodyMap[id] = info.resBody.toString(); + self.recordBodyMap[id] = info.resBody; } }; + self.getBody = function(id){ if(id < 0){ return ""; @@ -90,6 +91,10 @@ function Recorder(option){ return self.recordBodyMap[id] || ""; }; + self.getSingleRecord = function(id,cb){ + db.find({_id:parseInt(id)},cb); + } + self.getSummaryList = function(cb){ db.find({},cb); }; diff --git a/package.json b/package.json index 968034a..d0a4710 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "anyproxy", - "version": "3.1.0", + "version": "3.1.1", "description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.", "main": "proxy.js", "bin": { @@ -11,8 +11,9 @@ "async-task-mgr": ">=1.1.0", "colorful": "^2.1.0", "commander": "~2.3.0", - "entities": "^1.1.1", + "ent": "^2.2.0", "express": "^4.8.5", + "iconv-lite": "^0.4.6", "ip": "^0.3.2", "juicer": "^0.6.6-stable", "nedb": "^0.11.0", diff --git a/proxy.js b/proxy.js index 9c6e414..547ff3c 100644 --- a/proxy.js +++ b/proxy.js @@ -21,8 +21,9 @@ var http = require('http'), express = require("express"), ip = require("ip"), fork = require("child_process").fork, - ThrottleGroup = require("stream-throttle").ThrottleGroup; - + ThrottleGroup = require("stream-throttle").ThrottleGroup, + iconv = require('iconv-lite'), + Buffer = require('buffer').Buffer; var T_TYPE_HTTP = 0, T_TYPE_HTTPS = 1, @@ -146,10 +147,32 @@ function proxyServer(option){ var child_webServer = fork(path.join(__dirname,"./webServer.js"),args); child_webServer.on("message",function(data){ if(data.type == "reqBody" && data.id){ - child_webServer.send({ - type : "body", - id : data.id, - body : GLOBAL.recorder.getBody(data.id) + + GLOBAL.recorder.getSingleRecord(data.id,function(err,doc){ + var result; + try{ + var record = doc[0], + resHeader = record['resHeader'] || {}, + bodyContent = GLOBAL.recorder.getBody(data.id); + + result = bodyContent; + if(/charset=gbk/i.test(JSON.stringify(resHeader))){ + result = iconv.decode(bodyContent, 'GBK'); + } + + child_webServer.send({ + type : "body", + id : data.id, + body : result.toString() + }); + }catch(e){ + child_webServer.send({ + type : "body", + id : null, + body : null, + error:e.toString() + }); + } }); } }); diff --git a/web/css/page.css b/web/css/page.css index 2a79127..3590d0c 100644 --- a/web/css/page.css +++ b/web/css/page.css @@ -194,6 +194,7 @@ body{ padding: 10px; border: 1px solid #99baca; background: #f5fbfe; + word-wrap:break-word; } .subTitle{ diff --git a/web/detail.js b/web/detail.js index e29a9dd..d7a550e 100644 --- a/web/detail.js +++ b/web/detail.js @@ -35,7 +35,7 @@ define("./detail",['$', 'gallery/underscore/1.6.0/underscore.js'],function(requi '
'+ '

response body

'+ '
'+ - '
'+ + '
'+
 		'			
'+ '
'+ ' <% } %>'; diff --git a/web/list.js b/web/list.js index e6a4a23..e1aaaf3 100644 --- a/web/list.js +++ b/web/list.js @@ -166,10 +166,8 @@ seajs.use(['$', 'Underscore', 'Backbone',"Handlebars","Popup","./detail"], funct }); })(); - //render custom menu + //[test]render custom menu var customMenu = $("#customMenu").val().split("@@@"); - console.log(customMenu); - //data via web socket if(!WebSocket){ diff --git a/webServer.js b/webServer.js index 1843f55..a348d8b 100644 --- a/webServer.js +++ b/webServer.js @@ -6,7 +6,7 @@ var express = require("express"), certMgr = require("./lib/certMgr"), events = require("events"), inherits = require("util").inherits, - entities = require("entities"), + ent = require("ent"), qrCode = require('qrcode-npm'), WebSocketServer = require('ws').Server; @@ -38,14 +38,13 @@ function proxyWebServer(port,webSocketPort,proxyConfigPort,ruleSummary,ipAddress // }); app.get("/body",function(req,res){ - var reqQuery = url.parse(req.url,true); - var id = reqQuery.query.id; + var id = req.query.id; res.setHeader("Content-Type","text/html"); res.writeHead(200); fetchBody(id,function(body){ - res.end(entities.encodeHTML(body)); + res.end(ent.encode(body)); }); });