@@ -17,7 +17,9 @@ function TourCMS(options) {
17
17
apiKey : '' ,
18
18
marketplaceId : 0 ,
19
19
channelId : 0 ,
20
- channels : [ ]
20
+ channels : [ ] ,
21
+ userAgent : '' ,
22
+ prependCallerToUserAgent : true
21
23
} ;
22
24
23
25
if ( typeof options !== 'undefined' ) {
@@ -30,6 +32,9 @@ function TourCMS(options) {
30
32
31
33
if ( typeof options . channelId !== 'undefined' )
32
34
this . options . channelId = options . channelId ;
35
+
36
+ if ( typeof options . userAgent !== 'undefined' )
37
+ this . options . userAgent = options . userAgent ;
33
38
}
34
39
35
40
}
@@ -60,16 +65,20 @@ TourCMS.prototype.makeRequest = function(a) {
60
65
// Generate the signature
61
66
var signature = this . generateSignature ( a . path , a . channelId , a . verb , outboundTime , this . options . apiKey ) ;
62
67
68
+ var headers = {
69
+ 'x-tourcms-date' : outboundTime ,
70
+ 'Authorization' : 'TourCMS ' + a . channelId + ':' + this . options . marketplaceId + ':' + signature ,
71
+ 'Content-type' : 'text/xml;charset="utf-8"' ,
72
+ 'Content-length' : Buffer . byteLength ( apiParams , 'utf8' )
73
+ } ;
74
+
75
+ headers = this . addUserAgent ( headers , a ) ;
76
+
63
77
var options = {
64
78
method : a . verb ,
65
79
hostname : this . options . hostname ,
66
80
path : a . path ,
67
- headers : {
68
- 'x-tourcms-date' : outboundTime ,
69
- 'Authorization' : 'TourCMS ' + a . channelId + ':' + this . options . marketplaceId + ':' + signature ,
70
- 'Content-type' : 'text/xml;charset="utf-8"' ,
71
- 'Content-length' : Buffer . byteLength ( apiParams , 'utf8' )
72
- }
81
+ headers : headers
73
82
} ;
74
83
75
84
var req = https . request ( options , function ( response ) {
@@ -1296,6 +1305,22 @@ TourCMS.prototype.generateSignature = function(path, channelId, verb, outboundTi
1296
1305
return signature ;
1297
1306
} ;
1298
1307
1308
+ TourCMS . prototype . addUserAgent = function ( headers , a ) {
1309
+
1310
+ let userAgent = this . options . userAgent ;
1311
+
1312
+ if ( userAgent == '' )
1313
+ return headers ;
1314
+
1315
+ if ( this . options . prependCallerToUserAgent )
1316
+ userAgent = userAgent + ' (' + this . options . marketplaceId + "_" + a . channelId + ')' ;
1317
+
1318
+ headers [ 'User-Agent' ] = userAgent ;
1319
+
1320
+ return headers ;
1321
+
1322
+ }
1323
+
1299
1324
// Generate the current Unix Timestamp (PHP style)
1300
1325
TourCMS . prototype . generateTime = function ( ) {
1301
1326
return Math . floor ( new Date ( ) . getTime ( ) / 1000 ) ;
0 commit comments