Skip to content
Permalink
Browse files

Removed non-standard (and not that useful) xhr emulation methods & re…

…worked the headers test as a consequence.
  • Loading branch information...
jaubourg
jaubourg committed Dec 10, 2010
1 parent 3178884 commit 9b9d270e3d697d8129147d03807c4e37b23120b7
Showing with 55 additions and 37 deletions.
  1. +2 −17 src/xhr.js
  2. +21 −0 test/data/headers.request.php
  3. +32 −20 test/unit/ajax.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;
@@ -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 );

0 comments on commit 9b9d270

Please sign in to comment.
You can’t perform that action at this time.