From bf0b0cde07b6b65b18601aa3f43f976f4150c1f2 Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Sun, 12 Apr 2020 17:59:12 +0200 Subject: [PATCH] Test response body compresssion on HTTP error --- test/gzip.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/gzip.ts b/test/gzip.ts index 2b14e35e2..8f556dd24 100644 --- a/test/gzip.ts +++ b/test/gzip.ts @@ -3,6 +3,7 @@ import zlib = require('zlib'); import test from 'ava'; import getStream = require('get-stream'); import withServer from './helpers/with-server'; +import {HTTPError} from '../source'; const testContent = 'Compressible response content.\n'; const testContentUncompressed = 'Uncompressed response content.\n'; @@ -21,6 +22,18 @@ test('decompress content', withServer, async (t, server, got) => { t.is((await got('')).body, testContent); }); +test('decompress content on error', withServer, async (t, server, got) => { + server.get('/', (_request, response) => { + response.setHeader('Content-Encoding', 'gzip'); + response.status(404); + response.end(gzipData); + }); + + const error = await t.throwsAsync(got('')); + + t.is(error.response.body, testContent); +}); + test('decompress content - stream', withServer, async (t, server, got) => { server.get('/', (_request, response) => { response.setHeader('Content-Encoding', 'gzip');