testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Implement HTTP/2 support

Open Jeffhabs opened this issue 5 years ago • 1 comments

  • [x] DevExpress/testcafe-hammerhead#2706 (DONE)
  • [ ] DevExpress/testcafe#7174

What is your Test Scenario?

According to this discussion thread, HTTP/2 should be supported. I've found this to not be the case. I've tested this by simply opening the network tab while running TestCafeStudio and noticing all of my requests being sent via HTTP/1

Here is a screenshot of my network using TestCafe image

Here is a screenshot not using TestCafe image

Seems the hammerhead url proxy translates my http/2 requests to http/1?

What are you suggesting?

I suggest either adding HTTP/2 support, or clearly specify that HTTP/2 is not supported. Can someone at TestCafe confirm this?

What alternatives have you considered?

N/A

Additional context

The web application I am testing is live and not running in localhost.

Jeffhabs avatar Mar 07 '19 21:03 Jeffhabs

Thank you for your inquiry. Currently, TestCafe doesn't support HTTP/2-only servers, it can work only if your web server can switch to the HTTPS compatibility mode. I think we should note this in our FAQ: #3550.

I've attached the code of an example server. HTTP/1 support can be enabled/disabled via the CAN_FALLBACK_TO_HTTP1 environment variable.

const http2 = require('http2');
const opensslcert = require('openssl-self-signed-certificate');


const { CAN_FALLBACK_TO_HTTP1 } = process.env;

const server = http2.createSecureServer({
    allowHTTP1: !!CAN_FALLBACK_TO_HTTP1,
    key: opensslcert.key,
    cert: opensslcert.cert
});
server.on('error', (err) => console.error(err));

server.on('request', (req, res) => {
    // Detects if it is a HTTPS request or HTTP/2
    const { socket: { alpnProtocol } } = req.httpVersion === '2.0' ?
        req.stream.session : req;

    res.writeHead(200, { 'content-type': 'text/html' });

    res.end(`
        <div>
            ${
                JSON.stringify({
                    alpnProtocol,
                    httpVersion: req.httpVersion
                })
            }
        </div>
        `
    );
});

server.listen(9000);

AndreyBelym avatar Mar 11 '19 13:03 AndreyBelym

Implemented in https://github.com/DevExpress/testcafe-hammerhead/issues/2706

miherlosev avatar Jun 21 '23 06:06 miherlosev