polymer-xhr.html and polymer-ajax.html drop the body of PUT requests

200 views
Skip to first unread message

Nicholaus Shupe

unread,
Mar 30, 2014, 3:20:10 AM3/30/14
to polym...@googlegroups.com
Supporting PUT correctly is important because PUT requests are supposed to be idempotent (http://stackoverflow.com/questions/630453/put-vs-post-in-rest).

However, Polymer seems to have a few bugs for PUT requests. In particular, the body is completely being dropped when the method is set to PUT. Here are my suggested fixes:

polymer-ajax.html, line 235 should be:

        if (this.method === 'POST' || this.method === 'PUT') {
          args.body = this.body || args.body;
        }

polymer-xhr.html, line 88 should be:

        xhr.send((method == 'POST' || method == 'PUT') ? (options.body || params) : null);

My additions in bold.

Please take address this issue!

Thanks,

-- Nic


Nicholaus Shupe

unread,
Mar 30, 2014, 3:20:30 AM3/30/14
to polym...@googlegroups.com
Please take some time to address this issue rather.

mar...@maklesoft.com

unread,
Mar 30, 2014, 8:50:28 AM3/30/14
to polym...@googlegroups.com
I don't see why you should drop the request body at all, regardless of the method. Afaik, the http spec does not explicitly preclude including a request body for any request type. Whether or not the server will/should interpret or even parse that body is another question, but I don't see why this kind of restriction should be enforced on the client side.

Jos Gerrits

unread,
May 13, 2014, 3:22:59 AM5/13/14
to polym...@googlegroups.com
Another issue i've encountered is that there's no way to see the status of the request without having the XHR object.

i've made the following changes:

isSuccess: function(xhr) {
        xhr = xhr || this.xhr;
        var status = xhr.status || 0;
        return !status || (status >= 200 && status < 300);
      } 

This way i can alway check the readystate of the xhr object.

I don't know if this should be in the defaults of polymer but the ajax and xhr objects definitly need some work..
Reply all
Reply to author
Forward
0 new messages