Skip to content

Commit d5965de

Browse files
derekrJames Halliday
authored andcommitted
Make withCredentials a param allowing caller to set
1 parent c07ffd6 commit d5965de

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/request.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ var Request = module.exports = function (xhr, params) {
1515
+ (params.path || '/')
1616
;
1717

18-
try { xhr.withCredentials = true }
18+
if (typeof params.withCredentials === 'undefined') {
19+
params.withCredentials = true;
20+
}
21+
22+
try { xhr.withCredentials = params.withCredentials }
1923
catch (e) {}
2024

2125
xhr.open(

test/request_url.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,19 @@ test('Test string as parameters', function(t) {
5656
t.equal( request.uri, 'http://localhost:8081/api/foo', 'Url should be correct');
5757
t.end();
5858

59-
})
59+
});
60+
61+
test('Test withCredentials param', function(t) {
62+
var url = '/api/foo';
63+
64+
var request = http.request({ url: url, withCredentials: false }, noop);
65+
t.equal( request.xhr.withCredentials, false, 'xhr.withCredentials should be false');
66+
67+
var request = http.request({ url: url, withCredentials: true }, noop);
68+
t.equal( request.xhr.withCredentials, true, 'xhr.withCredentials should be true');
69+
70+
var request = http.request({ url: url }, noop);
71+
t.equal( request.xhr.withCredentials, true, 'xhr.withCredentials should be true');
72+
73+
t.end();
74+
});

0 commit comments

Comments
 (0)