Skip to content

Commit 90b8bd5

Browse files
Merge pull request #38 from climba03003/climba03003/fix-user-agent-issue-in-broswer
Set "User-Agent" in Node only
2 parents 3397573 + 1d42bc3 commit 90b8bd5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Diff for: index.mjs

+14-4
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,26 @@ export default class WooCommerceRestApi {
187187
_request(method, endpoint, data, params = {}) {
188188
const url = this._getUrl(endpoint, params);
189189

190+
const headers = {
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+
typeof process !== "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
let options = {
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)