PDA

View Full Version : Problems with ConnectionManager w/ new YUI2.2.0 and EXT0.33



nfarahani
22 Feb 2007, 2:16 PM
I noticed that there is a problem with the connection manager when using the new YUI 2.2.0 release (out 2/20/07) and the YUI-EXT available on the main site (0.33); maybe someone can further clarify, but what I've noticed is that the "setHeader" method in connection.js of the YUI library has been updated. This method is overridden in the yui-ext.js file; which I believe to be the root of the problem. Commenting the override in yui-ext.js fixes the problem -- and data gets posted properly. Can anyone advise on this issue? I appreciate the help... the code differences are pasted below:




======================================
| YUI-EXT 0.33
======================================
if(YAHOO.util.Connect){
YAHOO.util.Connect.setHeader = function(o){
for(var prop in this._http_header){

if(typeof this._http_header[prop] != 'function'){
o.conn.setRequestHeader(prop, this._http_header[prop]);
}
}
delete this._http_header;
this._http_header = {};
this._has_http_headers = false;
};
}

======================================
| YUI 0.12.2
======================================
/**
* @description Accessor that sets the HTTP headers for each transaction.
* @method setHeader
* @private
* @static
* @param {object} o The connection object for the transaction.
* @return {void}
*/
setHeader:function(o)
{
for(var prop in this._http_header){
if(this._http_header.hasOwnProperty(prop)){
o.conn.setRequestHeader(prop, this._http_header[prop]);
}
}
delete this._http_header;

this._http_header = {};
this._has_http_headers = false;
}

======================================
| YUI 2.2.0
======================================
/**
* @description Accessor that sets the HTTP headers for each transaction.
* @method setHeader
* @private
* @static
* @param {object} o The connection object for the transaction.
* @return {void}
*/
setHeader:function(o)
{
if(this._has_default_headers){
for(var prop in this._default_headers){
if(YAHOO.lang.hasOwnProperty(this._default_headers,prop)){
o.conn.setRequestHeader(prop, this._default_headers[prop]);
YAHOO.log('Default HTTP header ' + prop + ' set with value of ' + this._default_headers[prop], 'info', 'Connection');
}
}
}

if(this._has_http_headers){
for(var prop in this._http_headers){
if(YAHOO.lang.hasOwnProperty(this._http_headers,prop)){
o.conn.setRequestHeader(prop, this._http_headers[prop]);
YAHOO.log('HTTP header ' + prop + ' set with value of ' + this._http_headers[prop], 'info', 'Connection');
}
}
delete this._http_headers;

this._http_headers = {};
this._has_http_headers = false;
}
},

My resolution so far is to comment out Jack's override of the setHeader method (not sure the necessity of it) -- perhaps a new override is needed if the changes that were made are important.

tryanDLS
22 Feb 2007, 3:04 PM
It looks like YUI eliminated the need for that Safari hack.

I think the best solution is to just comment that block in your version of yui-ext.js or yui-ext-core (or the debug versions if you're using them).

It doesn't appear that YUI has a Version property in their code that would let yui-ext determine whether you have 12.2 or 2.2.0. Given all the work going into the current 1.0 alpha effort, I'm not sure that Jack would be comfortable trying to hack/test something into the .33 code, unless somebody determines that there's a YAHOO global var that is new to 2.2.0 that can be checked.

nfarahani
22 Feb 2007, 3:13 PM
I actually came up with this soon afterwards:


if(YAHOO.util.Connect){
YAHOO.util.Connect.setHeader = function(o)
{
if(this._has_default_headers){
for(var prop in this._default_headers){
if(YAHOO.lang.hasOwnProperty(this._default_headers,prop) && (typeof this._http_headers[prop] != 'function')){
o.conn.setRequestHeader(prop, this._default_headers[prop]);
YAHOO.log('Default HTTP header ' + prop + ' set with value of ' + this._default_headers[prop], 'info', 'Connection');
}
}
}

if(this._has_http_headers){
for(var prop in this._http_headers){
if(YAHOO.lang.hasOwnProperty(this._http_headers,prop) && (typeof this._http_headers[prop] != 'function')){
o.conn.setRequestHeader(prop, this._http_headers[prop]);
YAHOO.log('HTTP header ' + prop + ' set with value of ' + this._http_headers[prop], 'info', 'Connection');
}
}
delete this._http_headers;

this._http_headers = {};
this._has_http_headers = false;
}
}
}

which can keep his "safari" hack in place also... but don't know how redundant both checks will be. So what exactly is the typeof there for instead of hasOwnProperty?

tryanDLS
22 Feb 2007, 3:37 PM
Your version of the code is missing the second half of the if statement. What's the timestamp on your yui-ext files?



// workaround for Safari 1.3 not supporting hasOwnProperty
if(YAHOO.util.Connect && YAHOO.ext.util.Browser.isSafari){


The check was needed because older versions of Sarfari don't have the function.

nfarahani
23 Feb 2007, 10:53 AM
Not sure of the timestamp -- but I will now compare my files against the latest one available.

Thanks for the info!

I don't have a copy of Safari (or a Mac) to test with -- but I assume the function replacement needs to still be updated in order for the code to be compatible with the new YUI2.2.0 release.

nfarahani
23 Feb 2007, 10:58 AM
Correction -- I just ran WinMerge (diff utility) on my copy versus a clean downlaod from the main site (http://www.jackslocum.com/blog/index.php -> clicked download). All files are identical -- and the yui-ext.js files (core) do not have the second half mentioned above. I will add that in, but am I missing something? Or is that in an upcoming release...

tryanDLS
23 Feb 2007, 11:08 AM
Ok, the PC I was looking at had the original .33 zip files. The current .33 version has a hotfix for a bug and removes that 2nd half of the 'IF'. yui-ext.js and yui-ext-core.js are dated 12/24. However, be aware that that change didn't make it into the debug versions which are still dated 12/14.

nfarahani
23 Feb 2007, 4:40 PM
Thanks for the update -- I assume the 2nd half was not a bug though -- and can be placed back in... correct? The function replacement will still need to be update in a future release to work properly on Safari I assume also.

tryanDLS
23 Feb 2007, 4:50 PM
I think if you're using the 2.2 code, you can just remove that function from the yui-ext files - it's not needed. If you're staying on the .12.2 code, I'd add the isSafari check back in. I'm not sure why it got removed, but my impression was that function was only needed to deal with a Safari bug.

I would imagine that 1.0 release will include the 2.2 YUI code, so that hack will get removed, or maybe moved to an optional include for people that want to remain on the YUI .12.2 code.

Hopefully, Jack will see this and confirm.