mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-24 04:01:27 +00:00
conv gbk to utf on webInterface
This commit is contained in:
parent
de3ba93a61
commit
3dc255e4de
@ -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.
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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",
|
||||
|
35
proxy.js
35
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()
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -194,6 +194,7 @@ body{
|
||||
padding: 10px;
|
||||
border: 1px solid #99baca;
|
||||
background: #f5fbfe;
|
||||
word-wrap:break-word;
|
||||
}
|
||||
|
||||
.subTitle{
|
||||
|
@ -35,7 +35,7 @@ define("./detail",['$', 'gallery/underscore/1.6.0/underscore.js'],function(requi
|
||||
' <section class="resBody">'+
|
||||
' <h4 class="subTitle">response body</h4>'+
|
||||
' <div class="detail">'+
|
||||
' <div class="J_responseBody resBodyContent"></div>'+
|
||||
' <pre class="J_responseBody resBodyContent"></pre>'+
|
||||
' </div>'+
|
||||
' </section>'+
|
||||
' <% } %>';
|
||||
|
@ -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){
|
||||
|
@ -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));
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user