mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-24 16:51:29 +00:00
the fixes are: 1. add "content-type" in headers for when dealing with localresponse 2. make a more accurate tip for throttle rate when lower than 1 3. make the crtMgr funcionality a more independent one 4. uppercase the request header before sending it out update the tip
58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
/*
|
|
* test for rule shouldUseLocal
|
|
*
|
|
*/
|
|
|
|
const ProxyServerUtil = require('./util/ProxyServerUtil.js');
|
|
const { proxyGet, generateUrl } = require('./util/HttpUtil.js');
|
|
const Server = require('./server/server.js');
|
|
const { printLog } = require('./util/CommonUtil.js');
|
|
|
|
const rule = require('./test_rules/shouldUseLocalResponseRule.js');
|
|
const expectedLocalBody = 'handled_in_local_response';
|
|
|
|
|
|
testWrapper('http');
|
|
testWrapper('https');
|
|
|
|
function testWrapper(protocol, ) {
|
|
describe('Rule shouldUseLocalResponse should be working in :' + protocol, () => {
|
|
let proxyServer ;
|
|
let serverInstance ;
|
|
|
|
beforeAll((done) => {
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000000;
|
|
printLog('Start server for rule_shouldUseLocalResponse_spec');
|
|
|
|
serverInstance = new Server();
|
|
|
|
proxyServer = ProxyServerUtil.proxyServerWithRule(rule);
|
|
|
|
setTimeout(function() {
|
|
done();
|
|
}, 2000);
|
|
});
|
|
|
|
afterAll(() => {
|
|
serverInstance && serverInstance.close();
|
|
proxyServer && proxyServer.close();
|
|
printLog('Close server for rule_shouldUseLocalResponse_spec');
|
|
|
|
});
|
|
|
|
it('Should use local response if the assertion is true', done => {
|
|
const url = generateUrl(protocol, '/test/uselocal');
|
|
proxyGet(url, {})
|
|
.then(res => {
|
|
expect(res.body).toEqual(expectedLocalBody);
|
|
expect(res.headers['via-proxy-local']).toEqual('true');
|
|
done();
|
|
}, error => {
|
|
console.log('error happened in proxy get for shouldUseLocal: ',error);
|
|
done.fail('error happened when test shouldUseLocal rule');
|
|
});
|
|
|
|
});
|
|
});
|
|
}
|