prototypejs / prototype

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

Allow Content-type header to be unchanged #314

Closed Gargaj closed 7 years ago

Gargaj commented 8 years ago

This is crucial to be able to do proper multipart/form-data requests, otherwise the boundary will never get filled correctly!

With this patch if the user sets contentType to null/false, the actual Content-Type header will be generated (correctly) by the browser.

izhovnir commented 8 years ago

It won't work as you expect. Ajax.Base.initialize() sets this.options.contentType to 'application/x-www-form-urlencoded'. The only way to remove it completely is delete headers['Content-type'] in case it was specified by programmer

See my issue about the same problem

Gargaj commented 8 years ago

It does work (and I'm using it) because the options object provided by the user extends (=overwrites) this.options here: https://github.com/sstephenson/prototype/blob/master/src/prototype/ajax/base.js#L13

Note that I didn't say that the user shouldn't supply contentType for this effect - they should explicitly set it to null or false!

izhovnir commented 8 years ago

OK, if it works. But you didn't take encoding parameter in consideration - it won't be set if contentType is not provided

Gargaj commented 8 years ago

...why wouldn't it (it does, the constructor loads the default if it's not set) and what does it matter? If contentType is false, the encoding parameter is never used.

adam-nielsen commented 8 years ago

Just came across this issue myself. Hopefully this patch can be merged, otherwise there is no way to do Ajax requests that involve files.

It is worth noting that jQuery supports this by setting the contentType to false, so it would be nice if Prototype could also support this feature (as implemented by this PR.)

adam-nielsen commented 7 years ago

@savetheclocktower Sorry for the bump but any chance this can be merged? It is pretty low risk as it only adds a new way of specifying new behaviour and so won't change the way the code works for existing users.

savetheclocktower commented 7 years ago

Yeah, sorry. A new release is on my to-do list, and I'll make sure this is part of it.

adam-nielsen commented 7 years ago

Fantastic, many thanks :-)

josemanuelsh commented 7 years ago

Excellent!! Thank You!!

savetheclocktower commented 7 years ago

Fixed this in f63d7f7bb59bfa11adb21a79c3322a0f4d7ed7d3. Thanks!