File tree Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,10 @@ var github = new GitHubApi({
37
37
protocol: " https" ,
38
38
host: " github.my-GHE-enabled-company.com" ,
39
39
pathPrefix: " /api/v3" , // for some GHEs
40
- timeout: 5000
40
+ timeout: 5000 ,
41
+ headers: {
42
+ " user-agent" : " My-Cool-GitHub-App" , // GitHub is happy with a unique user agent
43
+ }
41
44
});
42
45
github .user .getFollowingFromUser ({
43
46
// optional:
Original file line number Diff line number Diff line change @@ -173,6 +173,7 @@ var Url = require("url");
173
173
* }
174
174
**/
175
175
var Client = module . exports = function ( config ) {
176
+ config . headers = config . headers || { } ;
176
177
this . config = config ;
177
178
this . debug = Util . isTrue ( config . debug ) ;
178
179
@@ -721,19 +722,21 @@ var Client = module.exports = function(config) {
721
722
}
722
723
}
723
724
724
- if ( ! msg . headers )
725
- msg . headers = { } ;
726
- Object . keys ( msg . headers ) . forEach ( function ( header ) {
727
- var headerLC = header . toLowerCase ( ) ;
728
- if ( self . requestHeaders . indexOf ( headerLC ) == - 1 )
729
- return ;
730
- headers [ headerLC ] = msg . headers [ header ] ;
731
- } ) ;
725
+ function addCustomHeaders ( customHeaders ) {
726
+ Object . keys ( customHeaders ) . forEach ( function ( header ) {
727
+ var headerLC = header . toLowerCase ( ) ;
728
+ if ( self . requestHeaders . indexOf ( headerLC ) == - 1 )
729
+ return ;
730
+ headers [ headerLC ] = customHeaders [ header ] ;
731
+ } ) ;
732
+ }
733
+ addCustomHeaders ( Util . extend ( msg . headers || { } , this . config . headers ) ) ;
734
+
732
735
if ( ! headers [ "user-agent" ] )
733
736
headers [ "user-agent" ] = "NodeJS HTTP Client" ;
734
737
735
- if ( ! headers [ "accept" ] )
736
- headers [ " accept" ] = this . config . requestMedia || this . constants . requestMedia ;
738
+ if ( ! ( "accept" in headers ) )
739
+ headers . accept = this . config . requestMedia || this . constants . requestMedia ;
737
740
738
741
var options = {
739
742
host : host ,
You can’t perform that action at this time.
0 commit comments