Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: capricorn86/happy-dom
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v13.7.5
Choose a base ref
...
head repository: capricorn86/happy-dom
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 54d1ae080f4e91ae09bb586ad01f82050cf5db15
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 11, 2024

  1. fix: [#1294] Fixes problem related to cloning a cloned Response in Re…

    …sponse.clone()
    capricorn86 committed Mar 11, 2024
    Copy the full SHA
    6e87ead View commit details
  2. Merge pull request #1296 from capricorn86/1294-cloning-a-response-twi…

    …ce-locks-the-readablestream
    
    fix: [#1294] Fixes problem related to cloning a cloned Response in Re…
    capricorn86 authored Mar 11, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    54d1ae0 View commit details
Showing with 24 additions and 2 deletions.
  1. +3 −1 packages/happy-dom/src/fetch/Response.ts
  2. +21 −1 packages/happy-dom/test/fetch/Response.test.ts
4 changes: 3 additions & 1 deletion packages/happy-dom/src/fetch/Response.ts
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ export default class Response implements IResponse {
public readonly ok: boolean;
public readonly headers: IHeaders;
public [PropertySymbol.cachedResponse]: ICachedResponse | null = null;
public readonly [PropertySymbol.buffer]: Buffer | null = null;
public [PropertySymbol.buffer]: Buffer | null = null;
readonly #window: IBrowserWindow;
readonly #browserFrame: IBrowserFrame;

@@ -275,6 +275,8 @@ export default class Response implements IResponse {
headers: this.headers
});

response[PropertySymbol.cachedResponse] = this[PropertySymbol.cachedResponse];
response[PropertySymbol.buffer] = this[PropertySymbol.buffer];
(<boolean>response.ok) = this.ok;
(<boolean>response.redirected) = this.redirected;
(<string>response.type) = this.type;
22 changes: 21 additions & 1 deletion packages/happy-dom/test/fetch/Response.test.ts
Original file line number Diff line number Diff line change
@@ -488,7 +488,24 @@ describe('Response', () => {
expect(bodyText).toBe('Hello World');
});

it('Can use the body of the cloned Response independently (cached).', async () => {
it('Can use the body of the cloned Response with a buffer independently.', async () => {
const originalResponse = new window.Response('Hello World', {
status: 200,
statusText: 'OK',
headers: { 'Content-Type': 'text/plain' }
});
const clonedResponse = originalResponse.clone();
const clonedResponse2 = clonedResponse.clone();

const originalResponseText = await originalResponse.text();
const clonedResponseText = await clonedResponse.text();
const clonedResponseText2 = await clonedResponse2.text();
expect(originalResponseText).toBe('Hello World');
expect(clonedResponseText).toBe('Hello World');
expect(clonedResponseText2).toBe('Hello World');
});

it('Can use the body of the cloned Response with a buffer independently when cloned multiple times.', async () => {
const originalResponse = new window.Response('Hello World', {
status: 200,
statusText: 'OK',
@@ -536,11 +553,14 @@ describe('Response', () => {
headers: { 'Content-Type': 'text/plain' }
});
const clonedResponse = originalResponse.clone();
const clonedResponse2 = clonedResponse.clone();

const originalResponseText = await originalResponse.text();
const clonedResponseText = await clonedResponse.text();
const clonedResponseText2 = await clonedResponse2.text();
expect(originalResponseText).toBe('chunk1chunk2chunk3');
expect(clonedResponseText).toBe('chunk1chunk2chunk3');
expect(clonedResponseText2).toBe('chunk1chunk2chunk3');
});

it('Fails if the body of the original Response is already used.', async () => {