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

Cast string bodies to buffers to ensure correct encoding used #1303

Merged
merged 2 commits into from Jan 17, 2017

Conversation

jeskew
Copy link
Contributor

@jeskew jeskew commented Jan 17, 2017

This change ensures that bodies are always converted to byte buffers before being passed to an http.ClientRequest. It looks like the code that packs headers and short bodies into the same outgoing HTTP packet has a slightly different codepath for non-binary strings, which this change lets the SDK avoid.

Resolves #1297.

@coveralls
Copy link

coveralls commented Jan 17, 2017

Coverage Status

Coverage increased (+0.003%) to 91.901% when pulling 646a1e4 on jeskew:fix/s3-buffer-encoding into be97613 on aws:master.

Copy link
Contributor

@chrisradek chrisradek left a comment

Choose a reason for hiding this comment

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

Just one change requested to protect against the hard removal of using the Buffer constructor in later versions of node.js

@@ -100,6 +100,9 @@ AWS.NodeHttpClient = AWS.util.inherit({
total: totalBytes
});
});
if (typeof body === 'string') {
body = new Buffer(body);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the Buffer constructors are deprecated, we might want to add some feature detection to try Buffer.from first, then new Buffer.

@chrisradek
Copy link
Contributor

Also, can you add a changelog entry using the ./scrips/changelog/add-change.js script?

Copy link
Contributor

@chrisradek chrisradek left a comment

Choose a reason for hiding this comment

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

:shipit:

@coveralls
Copy link

coveralls commented Jan 17, 2017

Coverage Status

Coverage increased (+0.003%) to 91.901% when pulling 5bfd9fd on jeskew:fix/s3-buffer-encoding into be97613 on aws:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 91.901% when pulling 5bfd9fd on jeskew:fix/s3-buffer-encoding into be97613 on aws:master.

@jeskew jeskew merged commit 1afffc7 into aws:master Jan 17, 2017
@jeskew jeskew deleted the fix/s3-buffer-encoding branch January 17, 2017 23:29
@@ -100,6 +100,10 @@ AWS.NodeHttpClient = AWS.util.inherit({
total: totalBytes
});
});
if (typeof body === 'string') {
body = typeof Buffer.from === 'function' ?
Copy link

Choose a reason for hiding this comment

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

This unfortunately is broken on Node 4.4.5 :-( Buffer.from is a function but fails (because it is actually Uint8Array.from)

root@45d8cedbf66f:/app# node --version
v4.4.5
root@45d8cedbf66f:/app# node
> Buffer.from === Uint8Array.from
true
> typeof Buffer.from
'function'
> Buffer.from("foo")
TypeError: this is not a typed array.
    at Function.from (native)
...

@lock
Copy link

lock bot commented Sep 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

S3 putObject is generating incorrect signatures in some cases
4 participants