Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
Unable to get the response when content-encoding is not specified

I'm trying to testcafe RequestLogger and then get the api response logged. But it looks like I'm missing something, when the content-encoding is not specified.

It doesn't return anything in the 'else' section in the 'getLoggerBody' method, even after waiting for long.

Here's my code:

import { RequestLogger } from 'testcafe';
import { get } from "lodash";
import zlib from "zlib";

export const getLogger = (url, method = 'GET') => RequestLogger(url, { logResponseBody: true, logResponseHeaders: true });

export const getLoggerResponseBody = logger => {
  const request = logger.requests[0];
  const contentEncoding = get(request, ['response', 'headers', 'content-encoding']);
  if (contentEncoding && contentEncoding === 'gzip') {
    const unzippedBody = zlib.gunzipSync(request.response.body);
    return JSON.parse(unzippedBody.toString());
  } else {
    return JSON.parse(request.response.body.toString());
  }
};

The 'request.response.body' looks like a buffer as shown in the snippet below.

<Buffer 7b 22 6d 65 73 73 61 67 65 ... 4973 more bytes>

Could you help me fix this? What am I doing wrong here?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I tried to use your simplified code on the simple website. It looks like everything works as expected. It's expected that the request.response.body contains Buffer content. Please take a look at the https://testcafe.io/documentation/402769/reference/test-api/requestlogger/constructor#header article and pay attention to the logResponseBody and stringifyResponseBody sections.

I prepared a sample which demonstrates that your approach is correct in general case. Please see it:

import { RequestLogger } from 'testcafe';

export const getLogger = (url, method = 'GET') => RequestLogger(url, { logResponseBody: true, logResponseHeaders: true });

export const getLoggerResponseBody = logger => {
    const request = logger.requests[0];

    return request.response.body.toString();
};

const logger = getLogger(/.*/)

fixture `f`
    .page `http://example.com`
    .requestHooks(logger);

test('test', async t => {
    await t.click('h1');

    console.log(getLoggerResponseBody(logger));
});

If you would like the TestCafe Team to research your issue further, please create a sample that reproduces the issue at the following link: https://github.com/DevExpress/testcafe/issues/new?assignees=&labels=TYPE%3A+bug&template=bug_report.yaml

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda