mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-05-10 14:58:27 +00:00
fix case letter problem with allow-xx
This commit is contained in:
parent
722f38ecf6
commit
1377ea2326
@ -1,11 +1,14 @@
|
|||||||
anyproxy
|
anyproxy
|
||||||
==========
|
==========
|
||||||
|
another proxy written in NodeJS, which can handle HTTPS requests and CORS perfectly. Produced by Alipay-ct-wd.
|
||||||
|
Anyproxy是支付宝-创新终端技术部推出的一款基于NodeJS的web代理工具,用来解决HTTPS代理、跨域请求(CORS)等移动端调试中的常见问题。
|
||||||
|
|
||||||
|
|
||||||
Feature
|
Feature
|
||||||
------------
|
------------
|
||||||
* work as http or https proxy
|
* work as http or https proxy
|
||||||
* generate and intercept https requests for any domain without complaint by browser (after you trust its root CA)
|
* generate and intercept https requests for any domain without complaint by browser (after you trust its root CA)
|
||||||
* support CROS-related http header, you could use make cross-domain requests via this proxy
|
* support CORS-related http header, you could use make cross-domain requests via this proxy
|
||||||
* can be used globally or as a nodejs module
|
* can be used globally or as a nodejs module
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ function userRequestHandler(req,userRes){
|
|||||||
|
|
||||||
if(req.method == "OPTIONS"){
|
if(req.method == "OPTIONS"){
|
||||||
console.log("==>OPTIONS req for CROS, will allow all");
|
console.log("==>OPTIONS req for CROS, will allow all");
|
||||||
userRes.writeHead(200,mergeCROSHeader(req.headers)); //remove any cache related header, add crossdomain headers
|
userRes.writeHead(200,mergeCORSHeader(req.headers)); //remove any cache related header, add crossdomain headers
|
||||||
userRes.end();
|
userRes.end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -94,7 +94,9 @@ function userRequestHandler(req,userRes){
|
|||||||
};
|
};
|
||||||
|
|
||||||
var proxyReq = (ifHttps ? https : http).request(options, function(res) {
|
var proxyReq = (ifHttps ? https : http).request(options, function(res) {
|
||||||
userRes.writeHead(res.statusCode,mergeCROSHeader(req.headers,res.headers));
|
console.log(res.headers);
|
||||||
|
console.log(mergeCORSHeader(req.headers,res.headers));
|
||||||
|
userRes.writeHead(res.statusCode,mergeCORSHeader(req.headers,res.headers));
|
||||||
res.pipe(userRes);
|
res.pipe(userRes);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -184,13 +186,13 @@ function setRules(newRule){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
|
||||||
function mergeCROSHeader(reqHeader,originHeader){
|
function mergeCORSHeader(reqHeader,originHeader){
|
||||||
var targetObj = originHeader || {};
|
var targetObj = originHeader || {};
|
||||||
|
|
||||||
targetObj["Access-Control-Allow-Credentials"] = "true";
|
targetObj["access-control-allow-credentials"] = "true";
|
||||||
targetObj["Access-Control-Allow-Origin"] = reqHeader['origin'] || "-___-||";
|
targetObj["access-control-allow-origin"] = reqHeader['origin'] || "-___-||";
|
||||||
targetObj["Access-Control-Allow-Methods"] = "GET, POST, PUT";
|
targetObj["access-control-allow-methods"] = "GET, POST, PUT";
|
||||||
targetObj["Access-Control-Allow-Headers"] = reqHeader['access-control-request-headers'] || "-___-||";
|
targetObj["access-control-allow-headers"] = reqHeader['access-control-request-headers'] || "-___-||";
|
||||||
|
|
||||||
return targetObj;
|
return targetObj;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "anyproxy",
|
"name": "anyproxy",
|
||||||
"version": "1.2.2",
|
"version": "1.2.3",
|
||||||
"description": "another proxy written in NODEJS, which can handle HTTPS requests and CROS perfectly",
|
"description": "another proxy written in NODEJS, which can handle HTTPS requests and CROS perfectly",
|
||||||
"main": "proxy.js",
|
"main": "proxy.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user