Skip to content

Commit fd847f9

Browse files
author
Joe Goggins
committed
.getEventStream() computes http headers via _getDefaultHttpHeadersForContext()
1 parent 988ab8f commit fd847f9

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Particle.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,25 @@ class Particle {
892892
}
893893

894894
auth = this._getActiveAuthToken(auth);
895-
return new EventStream(`${this.baseUrl}${uri}`, auth).connect();
895+
const headers = this._getDefaultHttpHeadersForContext();
896+
return new EventStream(`${this.baseUrl}${uri}`, auth, { headers }).connect();
897+
}
898+
899+
/**
900+
* A reimplementation of Agent's _addToolContext() and _addProjectContext() methods
901+
* that can be used by getEventStream() which doesn't use Agent for http interactions
902+
* @private
903+
* @returns {Object} key/value http headers
904+
*/
905+
_getDefaultHttpHeadersForContext() {
906+
const returnThis = {};
907+
if (this.context && this.context.tool) {
908+
returnThis['X-Particle-Tool'] = `${this.context.tool.name}@${this.context.tool.version}`;
909+
}
910+
if (this.context && this.context.project) {
911+
returnThis['X-Particle-Project'] = `${this.context.project.name}@${this.context.project.version}`;
912+
}
913+
return returnThis;
896914
}
897915

898916
/**

0 commit comments

Comments
 (0)