Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty header value not sent in HTTP Request when using Cypress cy.intercept #30588

Open
NicholasMantovani opened this issue Nov 8, 2024 · 0 comments
Labels
E2E Issue related to end-to-end testing stage: needs investigating Someone from Cypress needs to look at this

Comments

@NicholasMantovani
Copy link

NicholasMantovani commented Nov 8, 2024

Current behavior

I'm working on an end-to-end (E2E) test using Cypress to intercept an HTTP call with the following command:

cy.intercept('GET', 'https://url:port/').as('intercept');

In my Angular application, there’s a requirement to send a specific HTTP header with an empty value. For example:

curl 'http://url:port/' \
  -H 'Currencycode;'

Note: The header (Currencycode) has a semicolon (;) after its name, indicating an empty value.

Issue:
When I use Cypress to intercept the request, the header isn't sent. However, if I don't use cy.intercept, the header is sent as expected.

In the dev-tool the header is shown but it's actually not sent.

Desired behavior

The headers should be sent correctly, this seems to be working when using cypress 6.0 that is the first version where intercept is introduced. We also tested the version 12.11 and the issue is present.

Test code to reproduce

Server

const express = require('express');
const fs = require('fs');
const cors = require('cors');
const app = express();
const port = 3000;
 
app.use(cors());
app.use(express.json());
 
app.post('/api/test', (req, res) => {
  // Log headers in a file
  fs.appendFileSync('headers.log', JSON.stringify(req.headers, null, 2) + '\n');
 
  // Response
  res.status(200).json({ message: 'Success' });
});
 
app.listen(port, () => {
  console.log(`Server listening at http://localhost:${port}`);
});

Html page

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Title</title>
</head>
<body>
  <script>
    const myHeaders = new Headers();
    myHeaders.append("emptyHeader", "");
 
    const requestOptions = {
        method: "POST",
        headers: myHeaders,
        redirect: "follow"
    };
    fetch('http://localhost:3000/api/test', requestOptions)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));
 
  </script>
</body>
</html>

Cypress test

it('test', () => {
    cy.intercept('POST', 'http://localhost:3000/api/test')
 
    cy.visit('../page.html');
  })

Cypress Version

13.15.0

Node version

v22.9.2

Operating System

Windows 11 Pro 23H2 build: 22631.4317

Debug Logs

No response

Other

No response

@jennifer-shehane jennifer-shehane added stage: needs investigating Someone from Cypress needs to look at this E2E Issue related to end-to-end testing labels Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing stage: needs investigating Someone from Cypress needs to look at this
Projects
None yet
Development

No branches or pull requests

2 participants