Removed non-standard (and not that useful) xhr emulation methods & reworked the headers test as a consequence.
This commit is contained in:
parent
317888464d
commit
9b9d270e3d
19
src/xhr.js
19
src/xhr.js
|
@ -147,8 +147,8 @@ jQuery.xhr = function( _native ) {
|
|||
accepts[ "*" ];
|
||||
|
||||
// Check for headers option
|
||||
if ( headers ) {
|
||||
xhr.setRequestHeaders( headers );
|
||||
for ( i in headers ) {
|
||||
requestHeaders[ i.toLowerCase() ] = headers[ i ];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -554,21 +554,6 @@ jQuery.xhr = function( _native ) {
|
|||
return xhr;
|
||||
},
|
||||
|
||||
// Ditto with an s
|
||||
setRequestHeaders: function(map) {
|
||||
checkState(1, !sendFlag);
|
||||
for ( var name in map ) {
|
||||
requestHeaders[ name.toLowerCase() ] = map[name];
|
||||
}
|
||||
return xhr;
|
||||
},
|
||||
|
||||
// Utility method to get headers set
|
||||
getRequestHeader: function(name) {
|
||||
checkState(1, !sendFlag);
|
||||
return requestHeaders[ name.toLowerCase() ];
|
||||
},
|
||||
|
||||
// Raw string
|
||||
getAllResponseHeaders: function() {
|
||||
return xhr.readyState <= 1 ? "" : responseHeadersString;
|
||||
|
|
21
test/data/headers.request.php
Normal file
21
test/data/headers.request.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
if (!function_exists('apache_request_headers')) {
|
||||
function apache_request_headers() {
|
||||
foreach($_SERVER as $key=>$value) {
|
||||
if (substr($key,0,5)=="HTTP_") {
|
||||
$key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
|
||||
$out[$key]=$value;
|
||||
}else{
|
||||
$out[$key]=$value;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
$headers = apache_request_headers();
|
||||
|
||||
foreach( explode( "_" , $_GET[ "keys" ] ) as $key ) {
|
||||
echo "$key: $headers[$key]\n";
|
||||
}
|
|
@ -281,10 +281,39 @@ test("jQuery.ajax() - error callbacks", function() {
|
|||
test(".ajax() - headers" , function() {
|
||||
|
||||
// No multiple line headers in IE
|
||||
expect( jQuery.browser.msie ? 2 : 4 );
|
||||
expect( jQuery.browser.msie ? 3 : 5 );
|
||||
|
||||
stop();
|
||||
|
||||
var requestHeaders = {
|
||||
Simple: "value",
|
||||
"Something-Else": "other value",
|
||||
Other: "something else"
|
||||
},
|
||||
list = [],
|
||||
i,
|
||||
sync = 2;
|
||||
|
||||
for( i in requestHeaders ) {
|
||||
list.push( i.toLowerCase() );
|
||||
}
|
||||
|
||||
list = list.join( "_" );
|
||||
|
||||
jQuery.ajax(url("data/headers.request.php?keys="+list), {
|
||||
headers: requestHeaders,
|
||||
success: function( data ) {
|
||||
var tmp = [];
|
||||
for ( i in requestHeaders ) {
|
||||
tmp.push( i.toLowerCase() , ": " , requestHeaders[ i ] , "\n" );
|
||||
}
|
||||
tmp = tmp.join( "" );
|
||||
|
||||
equals( data , tmp , "Headers were sent" );
|
||||
if ( ! --sync ) start();
|
||||
}
|
||||
});
|
||||
|
||||
jQuery.ajax({
|
||||
url: url("data/headers.php"),
|
||||
success: function( _1 , _2 , xhr ){
|
||||
|
@ -297,11 +326,11 @@ test(".ajax() - headers" , function() {
|
|||
ok( /^Hello\s+World$/.test( xhr.getResponseHeader( "Multiple-Line" ) ) , "Multiple line" );
|
||||
ok( /^Hello\s+Beautiful\s+World$/.test( xhr.getResponseHeader( "Multiple-Multiple-Line" ) ) , "Multiple multiple line" );
|
||||
}
|
||||
start();
|
||||
if ( ! --sync ) start();
|
||||
},
|
||||
error: function(){ ok(false, "error"); }
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
test(".ajax() - hash", function() {
|
||||
|
@ -1813,23 +1842,6 @@ test("jQuery.ajax - Etag support", function() {
|
|||
});
|
||||
});
|
||||
|
||||
test("jQuery ajax - headers", function() {
|
||||
|
||||
stop();
|
||||
|
||||
jQuery.ajax(url("data/css.php?wait=1&id=headers"), {
|
||||
headers: {
|
||||
testKey: "testValue"
|
||||
},
|
||||
beforeSend: function( xhr ) {
|
||||
equals( xhr.getRequestHeader("testKey") , "testValue" , "Headers properly set" );
|
||||
setTimeout( start , 13 );
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test("jQuery ajax - failing cross-domain", function() {
|
||||
|
||||
expect( 2 );
|
||||
|
|
Loading…
Reference in a new issue