Skip to content

Client.writeFileUsingPut() does not use 'PUT' #38

Closed
asnowfix opened this Issue Jan 28, 2013 · 6 comments

2 participants

@asnowfix

Is this intentional?

In my Node.js-based client, using POST causes the XMLHttpRequest wrapper to reset the body to null, because it is not a known Form format. Changing POST to PUT fixes the issue.

@pwnall
pwnall commented Jan 28, 2013

@snowfix Thank you for reporting this issue!

The writeFileUsingPut name is misleading, but there is a good reason for using POST -- it avoids a CORS preflight in browsers. Also, I wanted to keep the node.js behavior as close as possible to the browser behavior.

What object are you passing to writeFile?

I hope that Client.writeFile in the unit tests always delegates to Client.writeFileUsingPut on node.js, so writeFieUsingPut should be able to write String instances to text files.

@asnowfix
  1. I am passing Buffer objects to writeFile(), (which needed a small fix in the XHR wrapper for Node.js, BTW).
  2. When not changing POST to PUT, calls to the REST API fail. I can provide some traces if you want.
  3. And indeed, it seems that writeFile() always calls writeFieUsingPut() on Node.js
@pwnall
pwnall commented Jan 28, 2013

@snowfix I'm afraid the problem lies in the node-xmlhttprequest wrapper. The XHR specification doesn't distinguish between POST and PUT, and the code works as intended on the browser.

I'm working on a replacement XHR wrapper for node.js that will support binary files via Buffer and ArrayBuffer.
https://github.com/pwnall/node-xhr2

In the short run, it probably makes the most sense to keep using your patched version of node.js. I hope to get this library done soon, and I'll make a dropbox.js release that uses it instead of node-xmlhttprequest.

@asnowfix

This is good news. I just forked my own copy of node-xmlhttprequest because I wanted to not only make the stuff work, but also to enhance it to make it work behind proxies (probably by using node-tunnel just like request is doing). Would you have interest in this type of contribution?

BTW, I am using a patched version of node-XMLHttpRequest, not of the entire Node.js.

@pwnall
pwnall commented Jan 28, 2013

@snowfix I think it's better to wait until I make a first stable release, because I'll probably be changing the code like crazy until I get all the features working.

After that, definitely go for it!

@pwnall pwnall was assigned Jan 28, 2013
@pwnall
pwnall commented Jan 29, 2013

@snowfix I have released 0.9.1-beta1, which is a node.js-only update that supports node.js Buffers and ArrayBuffers. Please give it a try!

node-xhr2 still needs more work, I haven't added tests for events and network error handling. I think the code for send() is pretty stable though, and you can start looking at figuring out proxy support.

I'm closing this bug. Let's discuss proxy support in the node-xhr2 issue tracker.

@pwnall pwnall closed this Jan 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.