aws4
aws4 copied to clipboard
Inherited keys in headers ignored
Hey,
I noticed that the canonicalHeaders function uses Object.keys. Object.keys ignores inherited properties. The Fetch standard for one, or at least every implementation, takes inherited headers into account when creating the request. That discrepancy will mean some headers will not properly be signed by Aws4. You might want to switch to using the classic for (var key in headers) style.
Cheers
@moll can you give me an example of what you're talking about?
Fetch uses a completely different options API to Node.js – doesn't it rely on the Headers interface for providing headers?
To use aws4 with Fetch, I imagine you'd provide your headers as a standard object to aws4, then after signing use that to construct your Fetch Headers object.
I mean something like {__proto__: SHARED_HEADERS, Host: "foo"} or a prototyped obj created with Object.create.
I'm extracting the headers back out of the object Aws4 mutates as that's the interface I prefer, but both take an object of keys and values under the headers property. They're pretty similar. I don't remember if Node.js's implementation took inherited props, but the API docs don't explicitly say they don't, so I'd support all to be safe.
Sorry, I'm still confused – can you show me that actual Fetch code you're using?
Using for ... in ... definitely won't give you what you want:
var myHeaders = new Headers()
myHeaders.append('Content-Type', 'text/xml')
for (var i in myHeaders) { console.log(i) }
gives:
append
delete
get
getAll
has
set
keys
values
entries
forEach
You don't need to call Fetch with a Headers object. You can call it with a plain object, just like Node's HTTP requests.
Something like:
fetch("https://....amazonaws.com/bucket", {method: "PUT", headers: {"Content-Type": "xxx"}})
I just pass that headers above to Aws4.sign, let it do its magic, get the headers back out and pass them onwards.