Skip to content

cy.intercept does not return the response body when the status is a 304 #24605

Closed as not planned
@mjhenkes

Description

@mjhenkes

Current behavior

If an intercepted request receives a 304 the body is returned as an empty string.

Desired behavior

The intercepted request should return as the cached response.

There is currently a work around documented here: #14277 (comment)

  1. We could fix this in two ways. Internalize the work around. If a response that matched an intercept rule is cacheable, break caching on the response by deleting headers.
  2. We could simulate caching by caching server responses on the server and returning the body of the previously successful (200) response when we get a (304) status code

It seems the easier route would be to break caching.

Test code to reproduce

This can be reproduced by removing the work around from this test: https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/logging-in__single-sign-on/cypress/e2e/logging-in-single-sign-on-spec.cy.js#L239

and by running the test at least twice, you need the request to first be cached.

(note, this test currently uses route but will be updated to use intercept with this PR: cypress-io/cypress-example-recipes#800)

Cypress Version

10.11.0

Node version

16.16.0

Operating System

macOS

Debug Logs

No response

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions