Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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