Skip to content

Get an "Error: Parse Error: Expected HTTP/" with cy.request on 204 status #27554

Open
@pitivie

Description

@pitivie

Current behavior

I'm trying to delete item with:

  cy.request({
    method: 'DELETE',
    url: `http://localhost:8000/api/items/${itemId}`,
    followRedirect: false,
    auth: {
      'bearer': 'long token'
    },
  }).then(
    (response) => {
      expect(response.status).to.eq(204);
    }
  )

My server returns a response with 204 status and an empty body (as defined here https://developer.mozilla.org/fr/docs/Web/HTTP/Status/204).
But I get an error from cypress:
cypress-error

When I change server return with a non-empty body (like "foo"), the test passed.

Desired behavior

Cypress should accept empty response on 204

Test code to reproduce

  cy.request({
    method: 'DELETE',
    url: `http://localhost:8000/api/items/${itemId}`,
    followRedirect: false,
    auth: {
      'bearer': 'long token'
    },
  }).then(
    (response) => {
      expect(response.status).to.eq(204);
    }
  )

Cypress Version

12.17.3

Node version

v20.5.0

Operating System

Archlinux

Debug Logs

cy.request() failed trying to load:

http://localhost:8000/api/items/582

We attempted to make an http request to this URL but the request failed without a response.

We received this error at the network level:

  > Error: Parse Error: Expected HTTP/

-----------------------------------------------------------

The request we sent was:

Method: DELETE

URL: http://localhost:8000/api/items/582

-----------------------------------------------------------

Common situations why this would fail:

  - you don't have internet access

  - you forgot to run / boot your web server

  - your web server isn't accessible

  - you have weird network configuration settings on your computerLearn more

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    E2EIssue related to end-to-end testingexisting workaroundtype: featureNew feature that does not currently exist

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions