Fixes #8245. Ajax now ensures header names are capitalized so that non-compliant xhr implementations don't override them.
This commit is contained in:
parent
3a1d7a3c7c
commit
f2e0ae1a39
19
src/ajax.js
19
src/ajax.js
|
@ -15,6 +15,7 @@ var r20 = /%20/g,
|
||||||
rselectTextarea = /^(?:select|textarea)/i,
|
rselectTextarea = /^(?:select|textarea)/i,
|
||||||
rspacesAjax = /\s+/,
|
rspacesAjax = /\s+/,
|
||||||
rts = /([?&])_=[^&]*/,
|
rts = /([?&])_=[^&]*/,
|
||||||
|
rucWord = /(^|\-)([a-z])/g,
|
||||||
rurl = /^([\w\+\.\-]+:)\/\/([^\/?#:]*)(?::(\d+))?/,
|
rurl = /^([\w\+\.\-]+:)\/\/([^\/?#:]*)(?::(\d+))?/,
|
||||||
|
|
||||||
// Keep a copy of the old load method
|
// Keep a copy of the old load method
|
||||||
|
@ -400,8 +401,10 @@ jQuery.extend({
|
||||||
|
|
||||||
// Caches the header
|
// Caches the header
|
||||||
setRequestHeader: function( name, value ) {
|
setRequestHeader: function( name, value ) {
|
||||||
if ( state === 0 ) {
|
if ( !state ) {
|
||||||
requestHeaders[ name.toLowerCase() ] = value;
|
requestHeaders[ name.toLowerCase().replace( rucWord, function( _, $1, $2 ) {
|
||||||
|
return $1 + $2.toUpperCase();
|
||||||
|
} ) ] = value;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
@ -428,7 +431,7 @@ jQuery.extend({
|
||||||
|
|
||||||
// Overrides response content-type header
|
// Overrides response content-type header
|
||||||
overrideMimeType: function( type ) {
|
overrideMimeType: function( type ) {
|
||||||
if ( state === 0 ) {
|
if ( !state ) {
|
||||||
s.mimeType = type;
|
s.mimeType = type;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -649,28 +652,28 @@ jQuery.extend({
|
||||||
|
|
||||||
// Set the correct header, if data is being sent
|
// Set the correct header, if data is being sent
|
||||||
if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
|
if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
|
||||||
requestHeaders[ "content-type" ] = s.contentType;
|
requestHeaders[ "Content-Type" ] = s.contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
||||||
if ( s.ifModified ) {
|
if ( s.ifModified ) {
|
||||||
ifModifiedKey = ifModifiedKey || s.url;
|
ifModifiedKey = ifModifiedKey || s.url;
|
||||||
if ( jQuery.lastModified[ ifModifiedKey ] ) {
|
if ( jQuery.lastModified[ ifModifiedKey ] ) {
|
||||||
requestHeaders[ "if-modified-since" ] = jQuery.lastModified[ ifModifiedKey ];
|
requestHeaders[ "If-Modified-Since" ] = jQuery.lastModified[ ifModifiedKey ];
|
||||||
}
|
}
|
||||||
if ( jQuery.etag[ ifModifiedKey ] ) {
|
if ( jQuery.etag[ ifModifiedKey ] ) {
|
||||||
requestHeaders[ "if-none-match" ] = jQuery.etag[ ifModifiedKey ];
|
requestHeaders[ "If-None-Match" ] = jQuery.etag[ ifModifiedKey ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the Accepts header for the server, depending on the dataType
|
// Set the Accepts header for the server, depending on the dataType
|
||||||
requestHeaders.accept = s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
|
requestHeaders.Accept = s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
|
||||||
s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", */*; q=0.01" : "" ) :
|
s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", */*; q=0.01" : "" ) :
|
||||||
s.accepts[ "*" ];
|
s.accepts[ "*" ];
|
||||||
|
|
||||||
// Check for headers option
|
// Check for headers option
|
||||||
for ( i in s.headers ) {
|
for ( i in s.headers ) {
|
||||||
requestHeaders[ i.toLowerCase() ] = s.headers[ i ];
|
jqXHR.setRequestHeader( i, s.headers[ i ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow custom headers/mimetypes and early abort
|
// Allow custom headers/mimetypes and early abort
|
||||||
|
|
|
@ -96,8 +96,8 @@ if ( jQuery.support.ajax ) {
|
||||||
// Not set for crossDomain requests with no content
|
// Not set for crossDomain requests with no content
|
||||||
// (see why at http://trac.dojotoolkit.org/ticket/9486)
|
// (see why at http://trac.dojotoolkit.org/ticket/9486)
|
||||||
// Won't change header if already provided
|
// Won't change header if already provided
|
||||||
if ( !( s.crossDomain && !s.hasContent ) && !headers["x-requested-with"] ) {
|
if ( !( s.crossDomain && !s.hasContent ) && !headers["X-Requested-With"] ) {
|
||||||
headers[ "x-requested-with" ] = "XMLHttpRequest";
|
headers[ "X-Requested-With" ] = "XMLHttpRequest";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need an extra try/catch for cross domain requests in Firefox 3
|
// Need an extra try/catch for cross domain requests in Firefox 3
|
||||||
|
|
Loading…
Reference in a new issue