mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-08-04 21:39:04 +00:00
update to 4.0
This commit is contained in:
24
rule_sample/sample_modify_request_path.js
Normal file
24
rule_sample/sample_modify_request_path.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
sample:
|
||||
redirect all https://httpbin.org/user-agent requests to http://localhost:8008/index.html
|
||||
test:
|
||||
curl https://httpbin.org/user-agent --proxy http://127.0.0.1:8001
|
||||
expected response:
|
||||
'hello world' from 127.0.0.1:8001/index.html
|
||||
*/
|
||||
module.exports = {
|
||||
*beforeSendRequest(requestDetail) {
|
||||
if (requestDetail.url.indexOf('https://httpbin.org/user-agent') === 0) {
|
||||
const newRequestOptions = requestDetail.requestOptions;
|
||||
requestDetail.protocol = 'http';
|
||||
newRequestOptions.hostname = '127.0.0.1'
|
||||
newRequestOptions.port = '8008';
|
||||
newRequestOptions.path = '/index.html';
|
||||
newRequestOptions.method = 'GET';
|
||||
return requestDetail;
|
||||
}
|
||||
},
|
||||
*beforeDealHttpsRequest(requestDetail) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user