testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

TestCafe hangs or does not display a descriptive message when tested website sends headers with some invalid characters

Open AndreyBelym opened this issue 5 years ago • 1 comments

Given the following server:

http
    .createServer((req, res) => {
        res._headers={'inva lid': 'x' };
        res.end();
    })
    .listen(1337);

TestCafe hangs when using localhost:1337 as a page URL, or thows unhandled exception when using localhost:1337 as a resource URL (i.e. `

   1) Unhandled promise rejection:

 

      TypeError [ERR_INVALID_HTTP_TOKEN]: Header name must be a valid HTTP token ["inva lid"]
      at processHeader (_http_outgoing.js:449:5)
      at ServerResponse._storeHeader (_http_outgoing.js:363:11)
      at ServerResponse.writeHead (_http_server.js:312:8)
      at RequestPipelineContext.sendResponseHeaders
      (D:\test\node_modules\testcafe-hammerhead\lib\request-pipeline\context.js:347:9)
      at Array.sendProxyResponse
      (D:\test\node_modules\testcafe-hammerhead\lib\request-pipeline\index.js:137:7)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at run (D:\test\node_modules\testcafe-hammerhead\lib\request-pipeline\index.js:161:5)

It happens because http.request allows spaces in responses and our destination request error handler is not invoked while ServerResponse.writeHeader is more strict and rejects spaces in header names.

Note that if you use a different invalid symbol:

http
    .createServer((req, res) => {
        res._headers={'inva\x01lid': 'x' };
        res.end();
    })
    .listen(1337);
```,
the destination request fails and we can capture the Node.js error and show the correct error message:

Failed to perform a request to the resource at "http://localhost:1337/" because of an error. The request contains a header that doesn't comply with the specification "https://tools.ietf.org/html/rfc7230#section-3.2.4". It causes an internal Node.js error on parsing this header.

  Invalid characters:
  Character with code "1" in header "invalid" name at index 4

AndreyBelym avatar Sep 01 '20 15:09 AndreyBelym

The same for me.

VusalIs avatar Aug 10 '21 00:08 VusalIs

Already fixed.

AndreyBelym avatar Sep 16 '22 10:09 AndreyBelym