mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
integration tests: circumvent broken CE gzip handling ✅
This commit is contained in:
parent
63013d8306
commit
198d50e260
1 changed files with 18 additions and 0 deletions
|
@ -3,6 +3,7 @@ import {ok, AssertionError} from 'assert'
|
|||
import {DateTime} from 'luxon'
|
||||
import * as a from 'assert'
|
||||
import {createRequire} from 'module'
|
||||
import {gunzipSync} from 'zlib'
|
||||
|
||||
const hour = 60 * 60 * 1000
|
||||
const day = 24 * hour
|
||||
|
@ -44,6 +45,23 @@ if (process.env.VCR_MODE && !process.env.VCR_OFF) {
|
|||
const FSPersister = require('@pollyjs/persister-fs')
|
||||
const tap = require('tap')
|
||||
|
||||
// monkey-patch NodeHttpAdapter to handle gzipped responses properly
|
||||
// todo: submit a PR
|
||||
// related: https://github.com/Netflix/pollyjs/issues/256
|
||||
// related: https://github.com/Netflix/pollyjs/issues/463
|
||||
// related: https://github.com/Netflix/pollyjs/issues/207
|
||||
const _getBodyFromChunks = NodeHttpAdapter.prototype.getBodyFromChunks
|
||||
NodeHttpAdapter.prototype.getBodyFromChunks = function getBodyFromChunksWithGunzip (chunks, headers) {
|
||||
if (headers['content-encoding'] === 'gzip') {
|
||||
const concatenated = Buffer.concat(chunks)
|
||||
chunks = [gunzipSync(concatenated)]
|
||||
// todo: this is ugly, find a better way
|
||||
delete headers['content-encoding']
|
||||
headers['content-length'] = chunks[0].length
|
||||
}
|
||||
return _getBodyFromChunks.call(this, chunks, headers)
|
||||
}
|
||||
|
||||
Polly.register(NodeHttpAdapter)
|
||||
Polly.register(FSPersister)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue