add support for charsets other than gbk

This commit is contained in:
OttoMao 2015-01-28 16:22:48 +08:00
parent 3dc255e4de
commit 631b6307ce
4 changed files with 17 additions and 6 deletions

View File

@ -1,4 +1,8 @@
22 Jan 2015: anyproxy 3.1.1: 28 Jan 2015: anyproxy 3.1.2:
* thanks to iconv-lite, almost webpage with any charset can be correctly decoded in web interface.
28 Jan 2015: anyproxy 3.1.1:
* convert GBK to UTF8 in web interface * convert GBK to UTF8 in web interface

View File

@ -31,7 +31,7 @@ Feature
* work as http or https proxy * work as http or https proxy
* fully configurable, you can modify a request at any stage by your own javascript code * fully configurable, you can modify a request at any stage by your own javascript code
* when working as https proxy, it can generate and intercept https requests for any domain without complaint by browser (after you trust its root CA) * when working as https proxy, it can generate and intercept https requests for any domain without complaint by browser (after you trust its root CA)
* a web interface is availabe for you to view request details * a web interface for you to watch realtime request details, where html string with (almost) any charset could be shown correctly
* (beta)a web UI interface for you to replace some remote response with local data * (beta)a web UI interface for you to replace some remote response with local data
![screenshot](http://gtms01.alicdn.com/tps/i1/TB1IdgqGXXXXXa9apXXLExM2pXX-854-480.gif) ![screenshot](http://gtms01.alicdn.com/tps/i1/TB1IdgqGXXXXXa9apXXLExM2pXX-854-480.gif)

View File

@ -1,6 +1,6 @@
{ {
"name": "anyproxy", "name": "anyproxy",
"version": "3.1.1", "version": "3.1.2",
"description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.", "description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.",
"main": "proxy.js", "main": "proxy.js",
"bin": { "bin": {

View File

@ -156,9 +156,16 @@ function proxyServer(option){
bodyContent = GLOBAL.recorder.getBody(data.id); bodyContent = GLOBAL.recorder.getBody(data.id);
result = bodyContent; result = bodyContent;
if(/charset=gbk/i.test(JSON.stringify(resHeader))){ //detect charset and convert to utf8 for web interface
result = iconv.decode(bodyContent, 'GBK'); try{
var charsetMatch = JSON.stringify(resHeader).match(/charset="?([a-zA-Z0-9\-]+)"?/);
if(charsetMatch && charsetMatch.length > 1){
var currentCharset = charsetMatch[1].toLowerCase();
if(currentCharset != "utf-8" && iconv.encodingExists(currentCharset)){
result = iconv.decode(bodyContent, currentCharset);
} }
}
}catch(e){}
child_webServer.send({ child_webServer.send({
type : "body", type : "body",