mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-23 20:31:25 +00:00
Merge branch 'remove_cors'
This commit is contained in:
commit
5fb212d8d4
@ -74,7 +74,7 @@ setTimeout(function(){
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
summary:function(){
|
summary:function(){
|
||||||
var tip = "the default rule for AnyProxy which supports CORS.";
|
var tip = "the default rule for AnyProxy.";
|
||||||
if(!isRootCAFileExists){
|
if(!isRootCAFileExists){
|
||||||
tip += "\nRoot CA does not exist, will not intercept any https requests.";
|
tip += "\nRoot CA does not exist, will not intercept any https requests.";
|
||||||
}
|
}
|
||||||
@ -83,27 +83,21 @@ module.exports = {
|
|||||||
|
|
||||||
shouldUseLocalResponse : function(req,reqBody){
|
shouldUseLocalResponse : function(req,reqBody){
|
||||||
//intercept all options request
|
//intercept all options request
|
||||||
if(req.method == "OPTIONS"){
|
var simpleUrl = (req.headers.host || "") + (req.url || "");
|
||||||
return true;
|
mapConfig.map(function(item){
|
||||||
}else{
|
var key = item.keyword;
|
||||||
var simpleUrl = (req.headers.host || "") + (req.url || "");
|
if(simpleUrl.indexOf(key) >= 0){
|
||||||
mapConfig.map(function(item){
|
req.anyproxy_map_local = item.local;
|
||||||
var key = item.keyword;
|
return false;
|
||||||
if(simpleUrl.indexOf(key) >= 0){
|
}
|
||||||
req.anyproxy_map_local = item.local;
|
});
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
return !!req.anyproxy_map_local;
|
return !!req.anyproxy_map_local;
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
dealLocalResponse : function(req,reqBody,callback){
|
dealLocalResponse : function(req,reqBody,callback){
|
||||||
if(req.method == "OPTIONS"){
|
if(req.anyproxy_map_local){
|
||||||
callback(200,mergeCORSHeader(req.headers),"");
|
|
||||||
}else if(req.anyproxy_map_local){
|
|
||||||
fs.readFile(req.anyproxy_map_local,function(err,buffer){
|
fs.readFile(req.anyproxy_map_local,function(err,buffer){
|
||||||
if(err){
|
if(err){
|
||||||
callback(200, {}, "[AnyProxy failed to load local file] " + err);
|
callback(200, {}, "[AnyProxy failed to load local file] " + err);
|
||||||
@ -127,7 +121,6 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
replaceResponseHeader: function(req,res,header){
|
replaceResponseHeader: function(req,res,header){
|
||||||
return mergeCORSHeader(req.headers, header);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
@ -190,21 +183,4 @@ module.exports = {
|
|||||||
// }
|
// }
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function mergeCORSHeader(reqHeader,originHeader){
|
|
||||||
var targetObj = originHeader || {};
|
|
||||||
|
|
||||||
delete targetObj["Access-Control-Allow-Credentials"];
|
|
||||||
delete targetObj["Access-Control-Allow-Origin"];
|
|
||||||
delete targetObj["Access-Control-Allow-Methods"];
|
|
||||||
delete targetObj["Access-Control-Allow-Headers"];
|
|
||||||
|
|
||||||
targetObj["access-control-allow-credentials"] = "true";
|
|
||||||
targetObj["access-control-allow-origin"] = reqHeader['origin'] || reqHeader['Origin'] || "-___-||";
|
|
||||||
targetObj["access-control-allow-methods"] = "GET, POST, PUT";
|
|
||||||
targetObj["access-control-allow-headers"] = reqHeader['access-control-request-headers'] || "-___-||";
|
|
||||||
|
|
||||||
return targetObj;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user