Skip to content

Commit e528978

Browse files
committed
Headers added to _request function
Old headers function simplified and now part of _request function Previously wasn't sending headers and so not able to authenticate Tested with basic & oAuth and works fine
1 parent 17017af commit e528978

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

github.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@
1313
// Util
1414
// =======
1515

16-
function headers() {
17-
var headers = {}
18-
if (options.auth === 'oauth' && !options.token) return { Accept: 'application/vnd.github.raw' };
19-
if (options.auth === 'basic' && (!options.username || !options.password)) return { Accept: 'application/vnd.github.raw' };
20-
return options.auth == 'oauth'
21-
? { Authorization: 'token '+ options.token, Accept: 'application/vnd.github.raw' }
22-
: { Authorization : 'Basic ' + Base64.encode(options.username + ':' + options.password), Accept: 'application/vnd.github.raw' }
23-
}
24-
2516
function _request(method, path, data, cb, raw) {
2617
var xhr = new XMLHttpRequest();
2718
if (!raw) {xhr.dataType = "json"}
@@ -31,6 +22,16 @@
3122
this.status == 200 ? cb(null, JSON.parse(this.responseText)) : cb(this.status);
3223
}
3324
}
25+
xhr.setRequestHeader('Accept','application/vnd.github.raw');
26+
if (
27+
(options.auth == 'oauth' && options.token) ||
28+
(options.auth == 'basic' && options.username && options.password)
29+
) {
30+
xhr.setRequestHeader('Authorization',options.auth == 'oauth'
31+
? 'token '+ options.token
32+
: 'Basic ' + Base64.encode(options.username + ':' + options.password)
33+
);
34+
}
3435
data ? xhr.send(JSON.stringify(data)) : xhr.send();
3536
}
3637

0 commit comments

Comments
 (0)