mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-06-24 12:18:54 +00:00
test deflate content
This commit is contained in:
parent
763bdc07a2
commit
3a310b0c0e
@ -120,7 +120,7 @@ function fetchRemoteResponse(protocol, options, reqData, config) {
|
|||||||
// only do unzip when there is res data
|
// only do unzip when there is res data
|
||||||
if (ifServerGzipped && originContentLen) {
|
if (ifServerGzipped && originContentLen) {
|
||||||
refactContentEncoding();
|
refactContentEncoding();
|
||||||
zlib.gunzip(serverResData, (err, buff) => { // TODO test case to cover
|
zlib.gunzip(serverResData, (err, buff) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
rejectParsing(err);
|
rejectParsing(err);
|
||||||
} else {
|
} else {
|
||||||
@ -129,7 +129,7 @@ function fetchRemoteResponse(protocol, options, reqData, config) {
|
|||||||
});
|
});
|
||||||
} else if (isServerDeflated && originContentLen) {
|
} else if (isServerDeflated && originContentLen) {
|
||||||
refactContentEncoding();
|
refactContentEncoding();
|
||||||
zlib.inflateRaw(serverResData, (err, buff) => { // TODO test case to cover
|
zlib.inflateRaw(serverResData, (err, buff) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
rejectParsing(err);
|
rejectParsing(err);
|
||||||
} else {
|
} else {
|
||||||
|
@ -264,6 +264,13 @@ KoaServer.prototype.constructRouter = function () {
|
|||||||
this.response.body = bufStream.pipe(zlib.createGzip());
|
this.response.body = bufStream.pipe(zlib.createGzip());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/test/deflate', this.logRequest, function *(next) {
|
||||||
|
this.status = 200;
|
||||||
|
this.response.set('Content-Encoding', 'deflate');
|
||||||
|
this.response.set('Content-Type', 'application/json');
|
||||||
|
this.response.body = zlib.deflateRawSync('{"type":"deflate","message":"This is a deflate encoding response"}');
|
||||||
|
});
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ describe('AnyProxy.proxyServer high order test', () => {
|
|||||||
.catch(done);
|
.catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should deal well with the gzip encoding compressed response', done => {
|
it('should deal well with the gzip encoding response', done => {
|
||||||
proxyGet(generateUrl('https', '/test/gzip'), {}, {})
|
proxyGet(generateUrl('https', '/test/gzip'), {}, {})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
expect(res && res.statusCode === 200).toBe(true);
|
expect(res && res.statusCode === 200).toBe(true);
|
||||||
@ -101,7 +101,17 @@ describe('AnyProxy.proxyServer high order test', () => {
|
|||||||
.catch(done);
|
.catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should deal well with the brotli encoding compressed response', done => {
|
it('should deal well with the deflate encoding response', done => {
|
||||||
|
proxyGet(generateUrl('https', '/test/deflate'), {}, {})
|
||||||
|
.then(res => {
|
||||||
|
expect(res && res.statusCode === 200).toBe(true);
|
||||||
|
expect(JSON.parse(res.body).type).toBe('deflate');
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should deal well with the brotli encoding response', done => {
|
||||||
proxyGet(generateUrl('https', '/test/brotli'), {}, {})
|
proxyGet(generateUrl('https', '/test/brotli'), {}, {})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
expect(res && res.statusCode === 200).toBe(true);
|
expect(res && res.statusCode === 200).toBe(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user