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.10.0
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: a6debf50e909766e0e5442b9e4c5ebe8dadb1cd1
Choose a head ref
  • 4 commits
  • 3 files changed
  • 1 contributor

Commits on Mar 18, 2024

  1. fix: [#1325] Fixes problem related to cloning a response without a body

    capricorn86 committed Mar 18, 2024
    Copy the full SHA
    d924104 View commit details
  2. Merge pull request #1327 from capricorn86/1325-symbolnodestream-error…

    …-message-with-msw
    
    fix: [#1325] Fixes problem related to cloning a response without a body
    capricorn86 authored Mar 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    bedb752 View commit details
  3. chore: [#1328] Fixes wrong license year in README.md

    capricorn86 committed Mar 18, 2024
    Copy the full SHA
    c60d9f1 View commit details
  4. Merge pull request #1329 from capricorn86/1328-fix-wrong-year-in-license

    chore: [#1328] Fixes wrong license year in README.md
    capricorn86 authored Mar 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a6debf5 View commit details
Showing with 40 additions and 2 deletions.
  1. +1 −1 README.md
  2. +5 −1 packages/happy-dom/src/fetch/utilities/FetchBodyUtility.ts
  3. +34 −0 packages/happy-dom/test/fetch/Response.test.ts
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -62,4 +62,4 @@ See [Contributing Guide](https://github.com/capricorn86/happy-dom/blob/master/do

## License

MIT License © 2020-Present [David Ortner](https://github.com/capricorn86)
MIT License © 2019-Present [David Ortner](https://github.com/capricorn86)
6 changes: 5 additions & 1 deletion packages/happy-dom/src/fetch/utilities/FetchBodyUtility.ts
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ export default class FetchBodyUtility {
* @returns New stream.
*/
public static cloneBodyStream(requestOrResponse: {
body: ReadableStream;
body: ReadableStream | null;
bodyUsed: boolean;
}): ReadableStream {
if (requestOrResponse.bodyUsed) {
@@ -113,6 +113,10 @@ export default class FetchBodyUtility {
);
}

if (requestOrResponse.body === null || requestOrResponse.body === undefined) {
return null;
}

// If a buffer is set, use it to create a new stream.
if (requestOrResponse[PropertySymbol.buffer]) {
return this.toReadableStream(requestOrResponse[PropertySymbol.buffer]);
34 changes: 34 additions & 0 deletions packages/happy-dom/test/fetch/Response.test.ts
Original file line number Diff line number Diff line change
@@ -488,6 +488,40 @@ describe('Response', () => {
expect(bodyText).toBe('Hello World');
});

it('Can clone Response without body.', async () => {
const response = new window.Response(null, {
status: 404,
statusText: 'Not Found',
headers: { 'Content-Type': 'text/plain' }
});

const clone = response.clone();

expect(clone).not.toBe(response);
expect(clone.status).toBe(404);
expect(clone.statusText).toBe('Not Found');
expect(clone.headers.get('Content-Type')).toBe('text/plain');
});

it('Can clone Response with empty string as body.', async () => {
const response = new window.Response('', {
status: 404,
statusText: 'Not Found',
headers: { 'Content-Type': 'text/plain' }
});

const clone = response.clone();

expect(clone).not.toBe(response);
expect(clone.status).toBe(404);
expect(clone.statusText).toBe('Not Found');
expect(clone.headers.get('Content-Type')).toBe('text/plain');

const bodyText = await clone.text();

expect(bodyText).toBe('');
});

it('Can use the body of the cloned Response with a buffer independently.', async () => {
const originalResponse = new window.Response('Hello World', {
status: 200,