Skip to content

Commit

Permalink
Merge pull request #38 from climba03003/climba03003/fix-user-agent-is…
Browse files Browse the repository at this point in the history
…sue-in-broswer

Set "User-Agent" in Node only
  • Loading branch information
claudiosanches authored Jan 30, 2020
2 parents 3397573 + 1d42bc3 commit 90b8bd5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,26 @@ export default class WooCommerceRestApi {
_request(method, endpoint, data, params = {}) {
const url = this._getUrl(endpoint, params);

const headers = {
Accept: "application/json"
};
// only set "User-Agent" in node environment
// the checking method is identical to upstream axios
if (
typeof process !== "undefined" &&
Object.prototype.toString.call(process) === "[object process]"
) {
headers["User-Agent"] =
"WooCommerce REST API - JS Client/" + this.classVersion;
}

let options = {
url: url,
method: method,
responseEncoding: this.encoding,
timeout: this.timeout,
responseType: "json",
headers: {
"User-Agent": "WooCommerce REST API - JS Client/" + this.classVersion,
Accept: "application/json"
}
headers
};

if (this.isHttps) {
Expand Down

0 comments on commit 90b8bd5

Please sign in to comment.