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

Traffic: [Status 304] - Response with null body status cannot have body #52

Open
JeanDamien opened this issue Jul 12, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@JeanDamien
Copy link

Description

If the user uses a .har file that contained a resource with a 304 status , this package will throw an exception:

Uncaught (in promise) TypeError: Failed to construct 'Response': Response with null body status cannot have body
    at toResponse (@mswjs_source_traffic.js)
    at fromTraffic (@mswjs_source_traffic.js)

https://github.com/mswjs/source/blob/main/src/traffic/utils/har-utils.ts#L40

Reproduction steps

  • Go to your favorite website, ie: https://source.mswjs.io/

  • Make sure Disable cache is not checked in the network tab

  • Clean the network log and refresh

  • The document and some resources should have a 304 status
    image

  • Export the logs as HAR file

  • Try to generate the request handlers following the instructions

HAR file

test/traffic/fixtures/archives/entry-with-status-304.har

Test template

  // Happen when the resource is already in cache
  it.todo(
    'does not throw an exception given an HAR file with a 304 status entry',
    () => {
      const traffic = readArchive(
        'test/traffic/fixtures/archives/entry-with-status-304.har',
      )
      expect(() => fromTraffic(traffic)).not.toThrow()
    },
  )

Expected behavior

It would be ideal if the library didn't throw an exception, or if we could add an entry in the documentation advising users to clear the cache before generating the HAR file to avoid this issue.

Initial assessment

Browsers, despite the specification stating that a 304 Not Modified response should not include a response body, might display a response body in the network tab for a few practical reasons related to implementation details, user experience, and debugging purposes. These responses do end up in the HAR file.

@JeanDamien JeanDamien added the bug Something isn't working label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant