prototypejs / prototype

Prototype JavaScript framework
http://prototypejs.org/
Other
3.53k stars 639 forks source link

It is impossible to set blank 'Content-Type' header #313

Closed izhovnir closed 7 years ago

izhovnir commented 8 years ago

This bug is actual mainly for using Ajax.Request along with FormData(). setRequestHeaders() method always sets 'Content-Type' header, even if contentType and encoding options are not defined. It causes incorrect header for Chrome (with comma before the string) that forces to define contentType and enconding. In this case boundary, which is required for multipart/form-data, is missing.

Probable solution:

Replace

if (this.method == 'post') {
      headers['Content-type'] = this.options.contentType + (this.options.encoding ? '; charset=' + this.options.encoding : '');
...
}

to

if (this.method == 'post') {
    if (this.options.contentType || this.options.encoding) { 
        headers['Content-type'] = this.options.contentType + (this.options.encoding ? '; charset=' + this.options.encoding : '');
     } else if (this.options.contentType == '' && this.options.encoding == '') {
         delete headers['Content-type'];
     }
...
}

It will resolve this problem