Skip to content

Commit

Permalink
Removed non-standard (and not that useful) xhr emulation methods & re…
Browse files Browse the repository at this point in the history
…worked the headers test as a consequence.
  • Loading branch information
jaubourg committed Dec 10, 2010
1 parent 3178884 commit 9b9d270
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 37 deletions.
19 changes: 2 additions & 17 deletions src/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
}
}

Expand Down Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions test/data/headers.request.php
Original file line number Diff line number Diff line change
@@ -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";
}
52 changes: 32 additions & 20 deletions test/unit/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ){
Expand All @@ -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() {
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 9b9d270

Please sign in to comment.