Skip to content

Commit 7bb7f21

Browse files
committed
Set "User-Agent" in Node only
1 parent 3397573 commit 7bb7f21

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

‎index.mjs‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,26 @@ export default class WooCommerceRestApi{
187187
_request(method,endpoint,data,params={}){
188188
consturl=this._getUrl(endpoint,params);
189189

190+
constheaders={
191+
Accept: "application/json"
192+
};
193+
// only set "User-Agent" in node environment
194+
// the checking method is identical to upstream axios
195+
if(
196+
typeofprocess!=="undefined"&&
197+
Object.prototype.toString.call(process)==="[object process]"
198+
){
199+
headers["User-Agent"]=
200+
"WooCommerce REST API - JS Client/"+this.classVersion;
201+
}
202+
190203
letoptions={
191204
url: url,
192205
method: method,
193206
responseEncoding: this.encoding,
194207
timeout: this.timeout,
195208
responseType: "json",
196-
headers: {
197-
"User-Agent": "WooCommerce REST API - JS Client/"+this.classVersion,
198-
Accept: "application/json"
199-
}
209+
headers
200210
};
201211

202212
if(this.isHttps){

0 commit comments

Comments
(0)