File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -236,8 +236,12 @@ Ajax.Request = Class.create(Ajax.Base, {
236
236
} ;
237
237
238
238
if ( this . method == 'post' ) {
239
- headers [ 'Content-type' ] = this . options . contentType +
240
- ( this . options . encoding ? '; charset=' + this . options . encoding : '' ) ;
239
+ // Don't set the `Content-Type` header if the user has explicitly set
240
+ // `contentType` to anything falsy.
241
+ if ( this . options . contentType ) {
242
+ headers [ 'Content-type' ] = this . options . contentType +
243
+ ( this . options . encoding ? '; charset=' + this . options . encoding : '' ) ;
244
+ }
241
245
242
246
/* Force "Connection: close" for older Mozilla browsers to work
243
247
* around a bug where XMLHttpRequest sends an incorrect
Original file line number Diff line number Diff line change @@ -495,5 +495,17 @@ suite("Ajax", function () {
495
495
Ajax . Request . prototype . isSameOrigin = isSameOrigin ;
496
496
} ) ;
497
497
498
+ test ( 'can omit content-type' , function ( ) {
499
+ new Ajax . Request ( '/inspect' , extendDefault ( {
500
+ method : 'post' ,
501
+ contentType : false ,
502
+ onSuccess : function ( response ) {
503
+ // If we omit Content-Type, the browser will provide its own.
504
+ var contentType = response . responseJSON . headers [ 'content-type' ] ;
505
+ assert ( contentType . indexOf ( 'text/plain' ) > - 1 ) ;
506
+ }
507
+ } ) ) ;
508
+ } ) ;
509
+
498
510
} ) ;
499
511
You can’t perform that action at this time.
0 commit comments