File tree Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import fetch from 'node-fetch';
21
21
import FormData from 'form-data' ;
22
22
import qs from 'qs' ;
23
23
import fs from 'fs' ;
24
+ import packageJson from '../package.json' ;
24
25
25
26
/**
26
27
* The object returned for a basic request
@@ -223,6 +224,7 @@ export default class Agent {
223
224
actualUri = `${ actualUri } ${ hasParams ? '&' : '?' } ${ queryParams } ` ;
224
225
}
225
226
227
+ const userAgentHeader = { 'User-Agent' : `${ packageJson . name } /${ packageJson . version } (${ packageJson . repository . url } )` } ;
226
228
let body ;
227
229
let contentTypeHeader ;
228
230
if ( files ) {
@@ -236,6 +238,7 @@ export default class Agent {
236
238
body = JSON . stringify ( data ) ;
237
239
}
238
240
const finalHeaders = Object . assign ( { } ,
241
+ userAgentHeader ,
239
242
contentTypeHeader ,
240
243
this . _getAuthorizationHeader ( auth ) ,
241
244
this . _getContextHeaders ( context ) ,
Original file line number Diff line number Diff line change @@ -345,6 +345,11 @@ describe('Agent', () => {
345
345
expect ( extractFilename ( opts . body , 'file2' , 3 ) ) . to . eql ( 'dir/file2path.cpp' ) ;
346
346
} ) ;
347
347
348
+ it ( 'sets the user agent to particle-api-js' , ( ) => {
349
+ const [ , opts ] = agent . _buildRequest ( { uri : 'uri' , method : 'get' } ) ;
350
+ expect ( opts . headers ) . to . have . property ( 'User-Agent' ) . that . match ( / ^ p a r t i c l e - a p i - j s / ) ;
351
+ } ) ;
352
+
348
353
if ( ! inBrowser ( ) ) {
349
354
it ( 'should handle Windows nested dirs' , ( ) => {
350
355
const files = {
You can’t perform that action at this time.
0 commit comments