Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11011: accept_header_additions.diff

File accept_header_additions.diff, 3.1 kB (added by jdalton, 7 months ago)
  • C:/Inetpub/wwwroot/prototype/src/Copy

    old new  
    128128      this.respondToReadyState(this.transport.readyState); 
    129129  }, 
    130130   
    131   setRequestHeaders: function() { 
    132     var headers = { 
    133       'X-Requested-With': 'XMLHttpRequest', 
    134       'X-Prototype-Version': Prototype.Version, 
    135       'Accept': 'text/javascript, text/html, application/xml, text/xml, */*' 
    136     }; 
     131  setRequestHeaders: (function(){ 
     132   
     133    var acceptHeader = $w('text/javascript text/html '+ 
     134      (Prototype.Browser.IE? '' : 'application/xhtml+xml ')+ 
     135        'application/xml text/xml application/json */*').join(', '); 
     136       
     137    return function(){ 
     138      var headers = { 
     139        'X-Requested-With': 'XMLHttpRequest', 
     140        'X-Prototype-Version': Prototype.Version, 
     141        'Accept': acceptHeader 
     142      }; 
    137143 
    138     if (this.method == 'post') { 
    139       headers['Content-type'] = this.options.contentType + 
    140         (this.options.encoding ? '; charset=' + this.options.encoding : ''); 
     144      if (this.method == 'post') { 
     145        headers['Content-type'] = this.options.contentType + 
     146          (this.options.encoding ? '; charset=' + this.options.encoding : ''); 
    141147       
    142       /* Force "Connection: close" for older Mozilla browsers to work 
    143        * around a bug where XMLHttpRequest sends an incorrect 
    144        * Content-length header. See Mozilla Bugzilla #246651.  
    145        */ 
    146       if (this.transport.overrideMimeType && 
    147           (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005) 
    148             headers['Connection'] = 'close'; 
    149     } 
    150      
    151     // user-defined headers 
    152     if (typeof this.options.requestHeaders == 'object') { 
    153       var extras = this.options.requestHeaders; 
     148        /* Force "Connection: close" for older Mozilla browsers to work 
     149         * around a bug where XMLHttpRequest sends an incorrect 
     150         * Content-length header. See Mozilla Bugzilla #246651.  
     151         */ 
     152        if (this.transport.overrideMimeType && 
     153            (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005) 
     154              headers['Connection'] = 'close'; 
     155      } 
    154156 
    155       if (Object.isFunction(extras.push)) 
    156         for (var i = 0, length = extras.length; i < length; i += 2)  
    157           headers[extras[i]] = extras[i+1]; 
    158       else 
    159         $H(extras).each(function(pair) { headers[pair.key] = pair.value }); 
    160     } 
     157      // user-defined headers 
     158      if (typeof this.options.requestHeaders == 'object') { 
     159        var extras = this.options.requestHeaders; 
    161160 
    162     for (var name in headers)  
    163       this.transport.setRequestHeader(name, headers[name]); 
    164   }, 
     161        if (Object.isFunction(extras.push)) 
     162          for (var i = 0, length = extras.length; i < length; i += 2)  
     163            headers[extras[i]] = extras[i+1]; 
     164        else 
     165          $H(extras).each(function(pair) { headers[pair.key] = pair.value }); 
     166      } 
     167 
     168      for (var name in headers)  
     169        this.transport.setRequestHeader(name, headers[name]); 
     170    } 
     171  })(), 
    165172   
    166173  success: function() { 
    167174    var status = this.getStatus();