Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
net: Adding X-Requested-With: XmlHttpRequest [#158 state:review]
  • Loading branch information
jakearchibald committed Oct 26, 2009
1 parent 03e90d6 commit 588b420
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
31 changes: 17 additions & 14 deletions src/net/net.js
Expand Up @@ -66,20 +66,23 @@
* @returns Object
*/
function populateOptions(opts) {
return glow.lang.apply(
{
onLoad: emptyFunc,
onError: emptyFunc,
onAbort: emptyFunc,
headers: {},
async: true,
useCache: false,
data: null,
defer: false,
forceXml: false
},
opts || {}
);
var newOpts = glow.lang.apply({
onLoad: emptyFunc,
onError: emptyFunc,
onAbort: emptyFunc,
headers: {},
async: true,
useCache: false,
data: null,
defer: false,
forceXml: false
}, opts || {} );

// add requested with header if one hasn't been added
if ( !('X-Requested-With' in newOpts.headers) ) {
newOpts.headers['X-Requested-With'] = 'XMLHttpRequest';
}
return newOpts;
}

/*
Expand Down
3 changes: 2 additions & 1 deletion test/glow/net/net.js
Expand Up @@ -58,7 +58,7 @@ t.test("glow.net.get sync", function() {
});

t.test("glow.net.get async header setting", function() {
t.expect(4);
t.expect(5);
t.stop();
var request = glow.net.get("testdata/xhr/requestheaderdump.php", {
headers: {
Expand All @@ -74,6 +74,7 @@ t.test("glow.net.get async header setting", function() {
t.ok(true, "correct callback used");
t.ok(/^REQUEST_METHOD: GET/m.test(response.text()), "Using get method");
t.ok(/^HTTP_CUSTOM_HEADER: thisisatest/m.test(response.text()), "Custom Header Sent");
t.ok(/^HTTP_X_REQUESTED_WITH: XMLHttpRequest/m.test(response.text()), "X-Requested-With default set");
t.ok(/^CONTENT_TYPE: image\/png/m.test(response.text()), "Content-type Changed");
t.start();
},
Expand Down

0 comments on commit 588b420

Please sign in to comment.