Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Fixes #7881. Setting contentType to false will prevent the Content-Ty…
…pe header from being sent. Unit test added.
- Loading branch information
Showing
with
40 additions
and
8 deletions.
-
+1
−1
src/ajax.js
-
+3
−7
test/data/headers.php
-
+36
−0
test/unit/ajax.js
|
@@ -559,7 +559,7 @@ jQuery.extend({ |
|
|
} |
|
|
|
|
|
// Set the correct header, if data is being sent |
|
|
if ( ( s.data && s.hasContent ) || options.contentType ) { |
|
|
if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) { |
|
|
requestHeaders[ "content-type" ] = s.contentType; |
|
|
} |
|
|
|
|
|
|
@@ -6,15 +6,11 @@ |
|
|
|
|
|
foreach( $_SERVER as $key => $value ) { |
|
|
|
|
|
if ( substr( $key , 0 , 5 ) == "HTTP_" ) { |
|
|
|
|
|
$key = str_replace( "_" , "-" , substr( $key , 5) ); |
|
|
$headers[ $key ] = $value; |
|
|
|
|
|
} |
|
|
$key = str_replace( "_" , "-" , substr( $key , 0 , 5 ) == "HTTP_" ? substr( $key , 5 ) : $key ); |
|
|
$headers[ $key ] = $value; |
|
|
|
|
|
} |
|
|
|
|
|
foreach( explode( "_" , $_GET[ "keys" ] ) as $key ) { |
|
|
echo "$key: " . $headers[ strtoupper( $key ) ] . "\n"; |
|
|
echo "$key: " . @$headers[ strtoupper( $key ) ] . "\n"; |
|
|
} |
|
@@ -276,6 +276,42 @@ test(".ajax() - headers" , function() { |
|
|
|
|
|
}); |
|
|
|
|
|
test(".ajax() - contentType" , function() { |
|
|
|
|
|
expect( 2 ); |
|
|
|
|
|
stop(); |
|
|
|
|
|
var count = 2; |
|
|
|
|
|
function restart() { |
|
|
if ( ! --count ) { |
|
|
start(); |
|
|
} |
|
|
} |
|
|
|
|
|
jQuery.ajax(url("data/headers.php?keys=content-type" ), { |
|
|
contentType: "test", |
|
|
success: function( data ) { |
|
|
strictEqual( data , "content-type: test\n" , "Test content-type is sent when options.contentType is set" ); |
|
|
}, |
|
|
complete: function() { |
|
|
restart(); |
|
|
} |
|
|
}); |
|
|
|
|
|
jQuery.ajax(url("data/headers.php?keys=content-type" ), { |
|
|
contentType: false, |
|
|
success: function( data ) { |
|
|
strictEqual( data , "content-type: \n" , "Test content-type is not sent when options.contentType===false" ); |
|
|
}, |
|
|
complete: function() { |
|
|
restart(); |
|
|
} |
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
test(".ajax() - hash", function() { |
|
|
expect(3); |
|
|
|
|
|