Closed jordanhendricks closed 7 years ago
CR at: https://cr.joyent.us/#/c/2079/.
After some discussion on the CR, I've decided it's best to fix this issue without changing the arguments to the createUpload
method on the Manta client, which would constitute a major version bump. Instead, I changed the way the headers
options is interpreted by the method to prevent them from being interpreted as headers on the request itself.
I added a test for this bug that creates an upload with headers on the target object that are also headers added to requests via the "opts.headers" argument for most methods on the client.
First, let's make sure the example from the man page works correctly now:
➜ node-manta git:(master) ✗ bin/mmpu create ~~/stor/foo.txt -c 3 -H 'content-type:text/plain' \
-H 'access-control-allow-origin:*'
ca9d7c6f-a1be-6d2f-943f-e860b00c616b
Additionally, I ran the node-manta test suite, including the additional test, against my Manta standup, and all tests passed.
This change is make prepush
clean.
While working on the
mmpu
man page (#joyent/node-manta#302), I wrote up a couple examples ofmmpu create
, including one that added acontent-type
andaccess-control-allow-origin
header to the object:As a part of my review of the man page, I tested out my examples to ensure they worked. To my surprise, the following example failed with a confusing error:
The error message itself was not very helpful, but seemed to be related to the fact that I specified a
content-type
header for the object. I ran the command again with-v
and saw something interesting:Here we see an "UnsupportedMediaTypeError" from the server-side for the media type "text/plain". This indicates that the content type of the request was sent as "text/plain" instead of the actual content type (which is JSON here). This is a clear flag that user-specified header for the target object was being sent as an actual header on the object instead of as data in the JSON request.
The culprit here is that
createUpload
uses a client helper calledcreateOptions
to create the headers for the request, which in turn uses theheaders
key on options object passed from the CLI script. Theheaders
key here unintentionally has a dual meaning -- both the headers to store on the target MPU object, and the headers for the request.I think the cleanest fix is to rename the
headers
key on the options blob that is passed to the Manta client, so that there is a clear separation because request headers and headers that are actually just data on the MPU create request.