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:
20
rule_sample/sample_use_local_response.js
Normal file
20
rule_sample/sample_use_local_response.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
sample:
|
||||
intercept all requests toward httpbin.org, use a local response
|
||||
test:
|
||||
curl http://httpbin.org/user-agent --proxy http://127.0.0.1:8001
|
||||
*/
|
||||
module.exports = {
|
||||
*beforeSendRequest(requestDetail) {
|
||||
const localResponse = {
|
||||
statusCode: 200,
|
||||
header: { 'Content-Type': 'application/json' },
|
||||
body: '{"hello": "this is local response"}'
|
||||
};
|
||||
if (requestDetail.url.indexOf('http://httpbin.org') === 0) {
|
||||
return {
|
||||
response: localResponse
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user