yui / yui3

A library for building richly interactive web applications.
http://yuilibrary.com/
Other
4.12k stars 1.28k forks source link

io-form bypasses setHeaders #1783

Open mschipperheyn opened 10 years ago

mschipperheyn commented 10 years ago

When you use io-form to submit a form through Y.io, the setHeaders method is bypassed.

So, if you're trying to pass a custom header, it will not be passed. In this sense, it violates the io contract, which allows you to pass a header object.

triptych commented 10 years ago

Can you link to an example? Any idea if this is new behavior in 3.16.0 vs. earlier versions?

mschipperheyn commented 10 years ago

I don't think this is new behaviour but I can check. I just ran into another regression so I need to go back anyway. I'm using a global IO header mechanism. This mechanism is bypassed in an io-form scenario when upload = true.

YUI.add('msa-io', function(Y) { var origIo = Y.io, globalHeaders;

// Assign some global headers.
globalHeaders = function(url,config) {
    origIo.header.call(Y.io, 'X-MSA-Header', 'MSA');
};

// Do.before inserts the function given before the method referenced
// in this case, do globalHeaders before Y.io
Y.Do.before(globalHeaders, Y, 'io');

// Unfortunately, it blows away any properties assigned to the given
// function, so we have to reassign them. :|
Y.Object.each(origIo, function(v,k) {
    Y.io[k] = v;
});

}, '0.0.1', { requires: [ 'io-base', 'event-custom' ] });

mschipperheyn commented 10 years ago

So, I created a fiddle http://jsfiddle.net/LtvD3/3/ But you need to step through the code after the debugger statement in the global header method because at first glance it all seems to work.

But when you step through the code, you will see that the io-upload-iframe module diverges from the normal io process before the headers are set (http://yuilibrary.com/yui/docs/api/files/io_js_io-base.js.html#l531 line 666) and doesn't set them itself.