Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(clientgen): fix setting user agent in js client
Browse files Browse the repository at this point in the history
Setting the User-Agent
rewop committed Feb 13, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ray-kast june
1 parent 0f6f384 commit 7588ddc
Showing 4 changed files with 28 additions and 4 deletions.
8 changes: 7 additions & 1 deletion internal/clientgen/javascript.go
Original file line number Diff line number Diff line change
@@ -477,8 +477,14 @@ class BaseClient {`)
this.baseURL = baseURL
this.headers = {
"Content-Type": "application/json",
"User-Agent": "` + userAgent + `",
}
// Add User-Agent header if the script is running in the server
// because browsers do not allow setting User-Agent headers to requests
if (typeof window === "undefined") {
this.headers["User-Agent"] = "` + userAgent + `";
}
this.requestInit = options.requestInit ?? {}
// Setup what fetch function we'll be using in the base client
8 changes: 7 additions & 1 deletion internal/clientgen/testdata/expected_baseauth_javascript.js
Original file line number Diff line number Diff line change
@@ -104,8 +104,14 @@ class BaseClient {
this.baseURL = baseURL
this.headers = {
"Content-Type": "application/json",
"User-Agent": "app-Generated-JS-Client (Encore/devel)",
}

// Add User-Agent header if the script is running in the server
// because browsers do not allow setting User-Agent headers to requests
if (typeof window === "undefined") {
this.headers["User-Agent"] = "app-Generated-JS-Client (Encore/devel)";
}

this.requestInit = options.requestInit ?? {}

// Setup what fetch function we'll be using in the base client
8 changes: 7 additions & 1 deletion internal/clientgen/testdata/expected_javascript.js
Original file line number Diff line number Diff line change
@@ -272,8 +272,14 @@ class BaseClient {
this.baseURL = baseURL
this.headers = {
"Content-Type": "application/json",
"User-Agent": "app-Generated-JS-Client (Encore/devel)",
}

// Add User-Agent header if the script is running in the server
// because browsers do not allow setting User-Agent headers to requests
if (typeof window === "undefined") {
this.headers["User-Agent"] = "app-Generated-JS-Client (Encore/devel)";
}

this.requestInit = options.requestInit ?? {}

// Setup what fetch function we'll be using in the base client
8 changes: 7 additions & 1 deletion internal/clientgen/testdata/expected_noauth_javascript.js
Original file line number Diff line number Diff line change
@@ -88,8 +88,14 @@ class BaseClient {
this.baseURL = baseURL
this.headers = {
"Content-Type": "application/json",
"User-Agent": "app-Generated-JS-Client (Encore/devel)",
}

// Add User-Agent header if the script is running in the server
// because browsers do not allow setting User-Agent headers to requests
if (typeof window === "undefined") {
this.headers["User-Agent"] = "app-Generated-JS-Client (Encore/devel)";
}

this.requestInit = options.requestInit ?? {}

// Setup what fetch function we'll be using in the base client

0 comments on commit 7588ddc

Please sign in to comment.