Merge branch 'master' into ws-proxy

This commit is contained in:
砚然
2018-01-21 19:43:02 +08:00
24 changed files with 312 additions and 149 deletions

View File

@@ -8,6 +8,6 @@
"../node_modules/babel-register/lib/node.js",
"../node_modules/babel-polyfill/dist/polyfill.js"
],
"stopSpecOnExpectationFailure": true,
"stopSpecOnExpectationFailure": false,
"random": false
}

View File

@@ -103,6 +103,11 @@ KoaServer.prototype.constructRouter = function () {
});
});
router.get('/test/response/304', this.logRequest, function *(next) {
this.response.set('Content-Encoding', 'gzip');
this.status = 304;
});
router.get('/test/response/303', function *(next) {
printLog('now to redirect 303');
this.redirect('/test');

View File

@@ -212,6 +212,31 @@ function testRequest(protocol = 'http') {
});
});
it('304 should work as direct without proxy rules', (done) => {
const url = constructUrl('/test/response/304');
proxyGet(url, CommonRequestHeader)
.then(proxyRes => {
directGet(url, CommonRequestHeader)
.then(directRes => {
expect(directRes.statusCode).toEqual(304);
expect(directRes.body).toEqual('');
expect(directRes.statusCode).toEqual(proxyRes.statusCode);
expect(isCommonResHeaderEqual(directRes.headers, proxyRes.headers, url)).toBe(true);
expect(directRes.body).toEqual(proxyRes.body);
expect(isCommonReqEqual(url, serverInstance)).toBe(true);
done();
}, error => {
console.error('error happened in direct 304 request:', error);
done.fail('error happened in direct 304 request');
});
}, error => {
console.error('error happened in proxy 304 request:', error);
done.fail('error happened in proxy 304 request');
});
})
describe('Response code should be honored as direct without proxy rules', () => {
[301, 302, 303].forEach(code => {
testRedirect(code);

View File

@@ -130,13 +130,6 @@ function isCommonReqEqual(url, serverInstance) {
isEqual = isEqual && proxyReqObj.headers['via-proxy'] === 'true';
delete proxyReqObj.headers['via-proxy'];
// exclued accept-encoding from comparing, since the proxy will remove it before sending it out
delete directReqObj.headers['accept-encoding'];
// TODO: 我这里proxy出去的options里没有accept-encoding, 但node自己加上了。Why ?
// By 加里 2017.1.31
delete proxyReqObj.headers['accept-encoding'];
directReqObj.headers['content-type'] = trimFormContentType(directReqObj.headers['content-type']);
proxyReqObj.headers['content-type'] = trimFormContentType(proxyReqObj.headers['content-type']);