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

fix disturbed ReadableStream error #65

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions dist/aws4fetch.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,9 @@ class AwsClient {
input = url;
}
const signer = new AwsV4Signer(Object.assign({ url: input }, init, this, init && init.aws));
const signed = Object.assign({}, init, await signer.sign());
const signed = Object.assign(signer.body instanceof ReadableStream ? { duplex: 'half' } : {}, init, await signer.sign());
delete signed.aws;
try {
return new Request(signed.url.toString(), signed)
} catch (e) {
if (e instanceof TypeError) {
return new Request(signed.url.toString(), Object.assign({ duplex: 'half' }, signed))
}
throw e
}
return new Request(signed.url.toString(), signed)
}
async fetch(input, init) {
for (let i = 0; i <= this.retries; i++) {
Expand Down
11 changes: 2 additions & 9 deletions dist/aws4fetch.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,9 @@ class AwsClient {
input = url;
}
const signer = new AwsV4Signer(Object.assign({ url: input }, init, this, init && init.aws));
const signed = Object.assign({}, init, await signer.sign());
const signed = Object.assign(signer.body instanceof ReadableStream ? { duplex: 'half' } : {}, init, await signer.sign());
delete signed.aws;
try {
return new Request(signed.url.toString(), signed)
} catch (e) {
if (e instanceof TypeError) {
return new Request(signed.url.toString(), Object.assign({ duplex: 'half' }, signed))
}
throw e
}
return new Request(signed.url.toString(), signed)
}
async fetch(input, init) {
for (let i = 0; i <= this.retries; i++) {
Expand Down
11 changes: 2 additions & 9 deletions dist/aws4fetch.esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,9 @@ class AwsClient {
input = url;
}
const signer = new AwsV4Signer(Object.assign({ url: input }, init, this, init && init.aws));
const signed = Object.assign({}, init, await signer.sign());
const signed = Object.assign(signer.body instanceof ReadableStream ? { duplex: 'half' } : {}, init, await signer.sign());
delete signed.aws;
try {
return new Request(signed.url.toString(), signed)
} catch (e) {
if (e instanceof TypeError) {
return new Request(signed.url.toString(), Object.assign({ duplex: 'half' }, signed))
}
throw e
}
return new Request(signed.url.toString(), signed)
}
async fetch(input, init) {
for (let i = 0; i <= this.retries; i++) {
Expand Down
11 changes: 2 additions & 9 deletions dist/aws4fetch.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,9 @@
input = url;
}
const signer = new AwsV4Signer(Object.assign({ url: input }, init, this, init && init.aws));
const signed = Object.assign({}, init, await signer.sign());
const signed = Object.assign(signer.body instanceof ReadableStream ? { duplex: 'half' } : {}, init, await signer.sign());
delete signed.aws;
try {
return new Request(signed.url.toString(), signed)
} catch (e) {
if (e instanceof TypeError) {
return new Request(signed.url.toString(), Object.assign({ duplex: 'half' }, signed))
}
throw e
}
return new Request(signed.url.toString(), signed)
}
async fetch(input, init) {
for (let i = 0; i <= this.retries; i++) {
Expand Down
12 changes: 2 additions & 10 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,9 @@ export class AwsClient {
input = url
}
const signer = new AwsV4Signer(Object.assign({ url: input }, init, this, init && init.aws))
const signed = Object.assign({}, init, await signer.sign())
const signed = Object.assign(signer.body instanceof ReadableStream ? { duplex: 'half' } : {}, init, await signer.sign())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potentially we could always include { duplex: 'half' }, I'm not sure how necessary it is to actually run the signer.body instanceof ReadableStream check.

delete signed.aws
try {
return new Request(signed.url.toString(), signed)
} catch (e) {
if (e instanceof TypeError) {
// https://bugs.chromium.org/p/chromium/issues/detail?id=1360943
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see from here – it's a Chrome workaround specifically.

You'd need to check that { duplex: 'half' } works on all platforms (and that it's appropriate)

return new Request(signed.url.toString(), Object.assign({ duplex: 'half' }, signed))
}
throw e
}
return new Request(signed.url.toString(), signed)
}

/**
Expand Down